1 /**
2   ******************************************************************************
3   * @file    stm32wbxx_hal_ipcc.c
4   * @author  MCD Application Team
5   * @brief   IPCC HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the Inter-Processor communication controller
8   *          peripherals (IPCC).
9   *           + Initialization and de-initialization functions
10   *           + Configuration, notification and interrupts handling
11   *           + Peripheral State and Error functions
12   ******************************************************************************
13   * @attention
14   *
15   * Copyright (c) 2019 STMicroelectronics.
16   * All rights reserved.
17   *
18   * This software is licensed under terms that can be found in the LICENSE file
19   * in the root directory of this software component.
20   * If no LICENSE file comes with this software, it is provided AS-IS.
21   *
22   ******************************************************************************
23   @verbatim
24   ==============================================================================
25                         ##### How to use this driver #####
26   ==============================================================================
27     [..]
28       The IPCC HAL driver can be used as follows:
29 
30       (#) Declare a IPCC_HandleTypeDef handle structure, for example: IPCC_HandleTypeDef hipcc;
31       (#) Initialize the IPCC low level resources by implementing the HAL_IPCC_MspInit() API:
32         (##) Enable the IPCC interface clock
33         (##) NVIC configuration if you need to use interrupt process
34             (+++) Configure the IPCC interrupt priority
35             (+++) Enable the NVIC IPCC IRQ
36 
37       (#) Initialize the IPCC registers by calling the HAL_IPCC_Init() API which trig
38           HAL_IPCC_MspInit().
39 
40       (#) Implement the interrupt callbacks for transmission and reception to use the driver in interrupt mode
41 
42       (#) Associate those callback to the corresponding channel and direction using HAL_IPCC_ConfigChannel().
43           This is the interrupt mode.
44           If no callback are configured for a given channel and direction, it is up to the user to poll the
45           status of the communication (polling mode).
46 
47       (#) Notify the other MCU when a message is available in a chosen channel
48           or when a message has been retrieved from a chosen channel by calling
49           the HAL_IPCC_NotifyCPU() API.
50 
51 @endverbatim
52   ******************************************************************************
53   */
54 
55 /* Includes ------------------------------------------------------------------*/
56 #include "stm32wbxx_hal.h"
57 
58 #if defined(IPCC)
59 /** @addtogroup STM32WBxx_HAL_Driver
60   * @{
61   */
62 
63 /** @addtogroup IPCC
64   * @{
65   */
66 
67 #ifdef HAL_IPCC_MODULE_ENABLED
68 
69 /* Private typedef -----------------------------------------------------------*/
70 /* Private define ------------------------------------------------------------*/
71 /** @defgroup IPCC_Private_Constants IPCC Private Constants
72   * @{
73   */
74 #define IPCC_ALL_RX_BUF 0x0000003FU /*!< Mask for all RX buffers. */
75 #define IPCC_ALL_TX_BUF 0x003F0000U /*!< Mask for all TX buffers. */
76 #define CHANNEL_INDEX_MASK 0x0000000FU /*!< Mask the channel index to avoid overflow */
77 /**
78   * @}
79   */
80 
81 /* Private macros ------------------------------------------------------------*/
82 /* Private variables ---------------------------------------------------------*/
83 /* Private function prototypes -----------------------------------------------*/
84 /** @defgroup IPCC_Private_Functions IPCC Private Functions
85   * @{
86   */
87 void IPCC_MaskInterrupt(uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir);
88 void IPCC_UnmaskInterrupt(uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir);
89 void IPCC_SetDefaultCallbacks(IPCC_HandleTypeDef *hipcc);
90 void IPCC_Reset_Register(IPCC_CommonTypeDef *Instance);
91 /**
92   * @}
93   */
94 
95 /** @addtogroup IPCC_Exported_Functions
96   * @{
97   */
98 
99 /** @addtogroup IPCC_Exported_Functions_Group1
100   *  @brief    Initialization and de-initialization functions
101   *
102 @verbatim
103  ===============================================================================
104              ##### Initialization and de-initialization functions  #####
105  ===============================================================================
106     [..]  This subsection provides a set of functions allowing to initialize and
107           deinitialize the IPCC peripheral:
108 
109       (+) User must Implement HAL_IPCC_MspInit() function in which he configures
110           all related peripherals resources (CLOCK and NVIC ).
111 
112       (+) Call the function HAL_IPCC_Init() to configure the IPCC register.
113 
114       (+) Call the function HAL_PKA_DeInit() to restore the default configuration
115           of the selected IPCC peripheral.
116 
117 @endverbatim
118   * @{
119   */
120 
121 /**
122   * @brief  Initialize the IPCC peripheral.
123   * @param  hipcc IPCC handle
124   * @retval HAL status
125   */
HAL_IPCC_Init(IPCC_HandleTypeDef * hipcc)126 HAL_StatusTypeDef HAL_IPCC_Init(IPCC_HandleTypeDef *hipcc)
127 {
128   HAL_StatusTypeDef err = HAL_OK;
129 
130   /* Check the IPCC handle allocation */
131   if (hipcc != NULL)
132   {
133     /* Check the parameters */
134     assert_param(IS_IPCC_ALL_INSTANCE(hipcc->Instance));
135 
136     IPCC_CommonTypeDef *currentInstance = IPCC_C1;
137 
138     if (hipcc->State == HAL_IPCC_STATE_RESET)
139     {
140       /* Init the low level hardware : CLOCK, NVIC */
141       HAL_IPCC_MspInit(hipcc);
142     }
143 
144     /* Reset all registers of the current cpu to default state */
145     IPCC_Reset_Register(currentInstance);
146 
147     /* Activate the interrupts */
148     currentInstance->CR |= (IPCC_CR_RXOIE | IPCC_CR_TXFIE);
149 
150     /* Clear callback pointers */
151     IPCC_SetDefaultCallbacks(hipcc);
152 
153     /* Reset all callback notification request */
154     hipcc->callbackRequest = 0;
155 
156     hipcc->State = HAL_IPCC_STATE_READY;
157   }
158   else
159   {
160     err = HAL_ERROR;
161   }
162 
163   return err;
164 }
165 
166 /**
167   * @brief  DeInitialize the IPCC peripheral.
168   * @param  hipcc IPCC handle
169   * @retval HAL status
170   */
HAL_IPCC_DeInit(IPCC_HandleTypeDef * hipcc)171 HAL_StatusTypeDef HAL_IPCC_DeInit(IPCC_HandleTypeDef *hipcc)
172 {
173   HAL_StatusTypeDef err = HAL_OK;
174 
175   /* Check the IPCC handle allocation */
176   if (hipcc != NULL)
177   {
178     assert_param(IS_IPCC_ALL_INSTANCE(hipcc->Instance));
179     IPCC_CommonTypeDef *currentInstance = IPCC_C1;
180 
181     /* Set the state to busy */
182     hipcc->State = HAL_IPCC_STATE_BUSY;
183 
184     /* Reset all registers of the current cpu to default state */
185     IPCC_Reset_Register(currentInstance);
186 
187     /* Clear callback pointers */
188     IPCC_SetDefaultCallbacks(hipcc);
189 
190     /* Reset all callback notification request */
191     hipcc->callbackRequest = 0;
192 
193     /* DeInit the low level hardware : CLOCK, NVIC */
194     HAL_IPCC_MspDeInit(hipcc);
195 
196     hipcc->State = HAL_IPCC_STATE_RESET;
197   }
198   else
199   {
200     err = HAL_ERROR;
201   }
202 
203   return err;
204 }
205 
206 /**
207   * @brief Initialize the IPCC MSP.
208   * @param  hipcc IPCC handle
209   * @retval None
210   */
HAL_IPCC_MspInit(IPCC_HandleTypeDef * hipcc)211 __weak void HAL_IPCC_MspInit(IPCC_HandleTypeDef *hipcc)
212 {
213   /* Prevent unused argument(s) compilation warning */
214   UNUSED(hipcc);
215 
216   /* NOTE : This function should not be modified. When the callback is needed
217             the HAL_IPCC_MspInit should be implemented in the user file
218    */
219 }
220 
221 /**
222   * @brief IPCC MSP DeInit
223   * @param  hipcc IPCC handle
224   * @retval None
225   */
HAL_IPCC_MspDeInit(IPCC_HandleTypeDef * hipcc)226 __weak void HAL_IPCC_MspDeInit(IPCC_HandleTypeDef *hipcc)
227 {
228   /* Prevent unused argument(s) compilation warning */
229   UNUSED(hipcc);
230 
231   /* NOTE : This function should not be modified. When the callback is needed
232             the HAL_IPCC_MspDeInit should be implemented in the user file
233    */
234 }
235 
236 /**
237   * @}
238   */
239 
240 
241 /** @addtogroup IPCC_Exported_Functions_Group2
242   *  @brief    Configuration, notification and Irq handling functions.
243   *
244 @verbatim
245  ===============================================================================
246               ##### IO operation functions #####
247  ===============================================================================
248     [..]  This section provides functions to allow two MCU to communicate.
249 
250     (#) For a given channel (from 0 to IPCC_CHANNEL_NUMBER), for a given direction
251         IPCC_CHANNEL_DIR_TX or IPCC_CHANNEL_DIR_RX, you can choose to communicate
252         in polling mode or in interrupt mode using IPCC.
253         By default, the IPCC HAL driver handle the communication in polling mode.
254         By setting a callback for a channel/direction, this communication use
255         the interrupt mode.
256 
257     (#) Polling mode:
258        (++) To transmit information, use HAL_IPCC_NotifyCPU() with
259             IPCC_CHANNEL_DIR_TX. To know when the other processor has handled
260             the notification, poll the communication using HAL_IPCC_NotifyCPU
261             with IPCC_CHANNEL_DIR_TX.
262 
263        (++) To receive information, poll the status of the communication with
264             HAL_IPCC_GetChannelStatus with IPCC_CHANNEL_DIR_RX. To notify the other
265             processor that the information has been received, use HAL_IPCC_NotifyCPU
266             with IPCC_CHANNEL_DIR_RX.
267 
268     (#) Interrupt mode:
269        (++) Configure a callback for the channel and the direction using HAL_IPCC_ConfigChannel().
270             This callback will be triggered under interrupt.
271 
272        (++) To transmit information, use HAL_IPCC_NotifyCPU() with
273             IPCC_CHANNEL_DIR_TX. The callback configured with HAL_IPCC_ConfigChannel() and
274             IPCC_CHANNEL_DIR_TX will be triggered once the communication has been handled by the
275             other processor.
276 
277        (++) To receive information, the callback configured with HAL_IPCC_ConfigChannel() and
278             IPCC_CHANNEL_DIR_RX will be triggered on reception of a communication.To notify the other
279             processor that the information has been received, use HAL_IPCC_NotifyCPU
280             with IPCC_CHANNEL_DIR_RX.
281 
282        (++) HAL_IPCC_TX_IRQHandler must be added to the IPCC TX IRQHandler
283 
284        (++) HAL_IPCC_RX_IRQHandler must be added to the IPCC RX IRQHandler
285 @endverbatim
286   * @{
287   */
288 
289 /**
290   * @brief  Activate the callback notification on receive/transmit interrupt
291   * @param  hipcc IPCC handle
292   * @param  ChannelIndex Channel number
293   *          This parameter can be one of the following values:
294   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
295   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
296   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
297   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
298   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
299   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
300   * @param  ChannelDir Channel direction
301   * @param  cb Interrupt callback
302   * @retval HAL status
303   */
HAL_IPCC_ActivateNotification(IPCC_HandleTypeDef * hipcc,uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir,ChannelCb cb)304 HAL_StatusTypeDef HAL_IPCC_ActivateNotification(IPCC_HandleTypeDef *hipcc,
305                                                 uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir,
306                                                 ChannelCb cb)
307 {
308   HAL_StatusTypeDef err = HAL_OK;
309 
310   /* Check the IPCC handle allocation */
311   if (hipcc != NULL)
312   {
313     /* Check the parameters */
314     assert_param(IS_IPCC_ALL_INSTANCE(hipcc->Instance));
315 
316     /* Check IPCC state */
317     if (hipcc->State == HAL_IPCC_STATE_READY)
318     {
319       /* Set callback and register masking information */
320       if (ChannelDir == IPCC_CHANNEL_DIR_TX)
321       {
322         hipcc->ChannelCallbackTx[ChannelIndex] = cb;
323         hipcc->callbackRequest |= (IPCC_MR_CH1FM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
324       }
325       else
326       {
327         hipcc->ChannelCallbackRx[ChannelIndex] = cb;
328         hipcc->callbackRequest |= (IPCC_MR_CH1OM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
329       }
330 
331       /* Unmask only the channels in reception (Transmission channel mask/unmask is done in HAL_IPCC_NotifyCPU) */
332       if (ChannelDir == IPCC_CHANNEL_DIR_RX)
333       {
334         IPCC_UnmaskInterrupt(ChannelIndex, ChannelDir);
335       }
336     }
337     else
338     {
339       err = HAL_ERROR;
340     }
341   }
342   else
343   {
344     err = HAL_ERROR;
345   }
346   return err;
347 }
348 
349 /**
350   * @brief  Remove the callback notification on receive/transmit interrupt
351   * @param  hipcc IPCC handle
352   * @param  ChannelIndex Channel number
353   *          This parameter can be one of the following values:
354   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
355   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
356   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
357   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
358   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
359   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
360   * @param  ChannelDir Channel direction
361   * @retval HAL status
362   */
HAL_IPCC_DeActivateNotification(IPCC_HandleTypeDef * hipcc,uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)363 HAL_StatusTypeDef HAL_IPCC_DeActivateNotification(IPCC_HandleTypeDef *hipcc,
364                                                   uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
365 {
366   HAL_StatusTypeDef err = HAL_OK;
367 
368   /* Check the IPCC handle allocation */
369   if (hipcc != NULL)
370   {
371     /* Check the parameters */
372     assert_param(IS_IPCC_ALL_INSTANCE(hipcc->Instance));
373 
374     /* Check IPCC state */
375     if (hipcc->State == HAL_IPCC_STATE_READY)
376     {
377       /* Set default callback and register masking information */
378       if (ChannelDir == IPCC_CHANNEL_DIR_TX)
379       {
380         hipcc->ChannelCallbackTx[ChannelIndex] = HAL_IPCC_TxCallback;
381         hipcc->callbackRequest &= ~(IPCC_MR_CH1FM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
382       }
383       else
384       {
385         hipcc->ChannelCallbackRx[ChannelIndex] = HAL_IPCC_RxCallback;
386         hipcc->callbackRequest &= ~(IPCC_MR_CH1OM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
387       }
388 
389       /* Mask the interrupt */
390       IPCC_MaskInterrupt(ChannelIndex, ChannelDir);
391     }
392     else
393     {
394       err = HAL_ERROR;
395     }
396   }
397   else
398   {
399     err = HAL_ERROR;
400   }
401   return err;
402 }
403 
404 /**
405   * @brief  Get state of IPCC channel
406   * @param  hipcc IPCC handle
407   * @param  ChannelIndex Channel number
408   *          This parameter can be one of the following values:
409   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
410   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
411   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
412   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
413   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
414   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
415   * @param  ChannelDir Channel direction
416   * @retval Channel status
417   */
HAL_IPCC_GetChannelStatus(IPCC_HandleTypeDef const * const hipcc,uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)418 IPCC_CHANNELStatusTypeDef HAL_IPCC_GetChannelStatus(IPCC_HandleTypeDef const *const hipcc,
419                                                     uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
420 {
421   uint32_t channel_state;
422   IPCC_CommonTypeDef *currentInstance = IPCC_C1;
423   IPCC_CommonTypeDef *otherInstance = IPCC_C2;
424 
425   /* Check the parameters */
426   assert_param(IS_IPCC_ALL_INSTANCE(hipcc->Instance));
427 
428   /* Read corresponding channel depending of the MCU and the direction */
429   if (ChannelDir == IPCC_CHANNEL_DIR_TX)
430   {
431     channel_state = (currentInstance->SR) & (IPCC_SR_CH1F_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
432   }
433   else
434   {
435     channel_state = (otherInstance->SR) & (IPCC_SR_CH1F_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
436   }
437 
438   return (channel_state == 0UL) ? IPCC_CHANNEL_STATUS_FREE : IPCC_CHANNEL_STATUS_OCCUPIED ;
439 }
440 
441 /**
442   * @brief  Notify remote processor
443   * @param  hipcc IPCC handle
444   * @param  ChannelIndex Channel number
445   *          This parameter can be one of the following values:
446   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
447   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
448   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
449   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
450   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
451   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
452   * @param  ChannelDir Channel direction
453   * @retval HAL status
454   */
HAL_IPCC_NotifyCPU(IPCC_HandleTypeDef const * const hipcc,uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)455 HAL_StatusTypeDef HAL_IPCC_NotifyCPU(IPCC_HandleTypeDef const *const hipcc,
456                                      uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
457 {
458   HAL_StatusTypeDef err = HAL_OK;
459   uint32_t mask;
460   IPCC_CommonTypeDef *currentInstance = IPCC_C1;
461 
462   /* Check the parameters */
463   assert_param(IS_IPCC_ALL_INSTANCE(hipcc->Instance));
464 
465   /* Check if IPCC is initialized */
466   if (hipcc->State == HAL_IPCC_STATE_READY)
467   {
468     /* For IPCC_CHANNEL_DIR_TX, set the status. For IPCC_CHANNEL_DIR_RX, clear the status */
469     currentInstance->SCR |= ((ChannelDir == IPCC_CHANNEL_DIR_TX) ? IPCC_SCR_CH1S :
470                              IPCC_SCR_CH1C)
471                             << (ChannelIndex & CHANNEL_INDEX_MASK);
472 
473     /* Unmask interrupt if the callback is requested */
474     mask = ((ChannelDir == IPCC_CHANNEL_DIR_TX) ? IPCC_MR_CH1FM_Msk :
475             IPCC_MR_CH1OM_Msk) << (ChannelIndex & CHANNEL_INDEX_MASK);
476     if ((hipcc->callbackRequest & mask) == mask)
477     {
478       IPCC_UnmaskInterrupt(ChannelIndex, ChannelDir);
479     }
480   }
481   else
482   {
483     err = HAL_ERROR;
484   }
485 
486   return err;
487 }
488 
489 /**
490   * @}
491   */
492 
493 /** @addtogroup IPCC_IRQ_Handler_and_Callbacks
494   * @{
495   */
496 
497 /**
498   * @brief  This function handles IPCC Tx Free interrupt request.
499   * @param  hipcc IPCC handle
500   * @retval None
501   */
HAL_IPCC_TX_IRQHandler(IPCC_HandleTypeDef * const hipcc)502 void HAL_IPCC_TX_IRQHandler(IPCC_HandleTypeDef *const hipcc)
503 {
504   uint32_t irqmask;
505   uint32_t bit_pos;
506   uint32_t ch_count = 0U;
507   IPCC_CommonTypeDef *currentInstance = IPCC_C1;
508 
509   /* check the Tx free channels which are not masked */
510   irqmask = ~(currentInstance->MR) & IPCC_ALL_TX_BUF;
511   irqmask = irqmask & ~(currentInstance->SR << IPCC_MR_CH1FM_Pos);
512 
513   while (irqmask != 0UL)  /* if several bits are set, it loops to serve all of them */
514   {
515     bit_pos = 1UL << (IPCC_MR_CH1FM_Pos + (ch_count & CHANNEL_INDEX_MASK));
516 
517     if ((irqmask & bit_pos) != 0U)
518     {
519       /* mask the channel Free interrupt  */
520       currentInstance->MR |= bit_pos;
521       if (hipcc->ChannelCallbackTx[ch_count] != NULL)
522       {
523         hipcc->ChannelCallbackTx[ch_count](hipcc, ch_count, IPCC_CHANNEL_DIR_TX);
524       }
525       irqmask =  irqmask & ~(bit_pos);
526     }
527     ch_count++;
528   }
529 }
530 
531 /**
532   * @brief  This function handles IPCC Rx Occupied interrupt request.
533   * @param  hipcc : IPCC handle
534   * @retval None
535   */
HAL_IPCC_RX_IRQHandler(IPCC_HandleTypeDef * const hipcc)536 void HAL_IPCC_RX_IRQHandler(IPCC_HandleTypeDef *const hipcc)
537 {
538   uint32_t irqmask;
539   uint32_t bit_pos;
540   uint32_t ch_count = 0U;
541   IPCC_CommonTypeDef *currentInstance = IPCC_C1;
542   IPCC_CommonTypeDef *otherInstance = IPCC_C2;
543 
544   /* check the Rx occupied channels which are not masked */
545   irqmask = ~(currentInstance->MR) & IPCC_ALL_RX_BUF;
546   irqmask = irqmask & otherInstance->SR;
547 
548   while (irqmask != 0UL)  /* if several bits are set, it loops to serve all of them */
549   {
550     bit_pos = 1UL << (ch_count & CHANNEL_INDEX_MASK);
551 
552     if ((irqmask & bit_pos) != 0U)
553     {
554       /* mask the channel occupied interrupt */
555       currentInstance->MR |= bit_pos;
556       if (hipcc->ChannelCallbackRx[ch_count] != NULL)
557       {
558         hipcc->ChannelCallbackRx[ch_count](hipcc, ch_count, IPCC_CHANNEL_DIR_RX);
559       }
560       irqmask = irqmask & ~(bit_pos);
561     }
562     ch_count++;
563   }
564 }
565 
566 /**
567   * @brief Rx occupied callback
568   * @param hipcc IPCC handle
569   * @param ChannelIndex Channel number
570   *          This parameter can be one of the following values:
571   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
572   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
573   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
574   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
575   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
576   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
577   * @param ChannelDir Channel direction
578   */
HAL_IPCC_RxCallback(IPCC_HandleTypeDef * hipcc,uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)579 __weak void HAL_IPCC_RxCallback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
580 {
581   /* Prevent unused argument(s) compilation warning */
582   UNUSED(hipcc);
583   UNUSED(ChannelIndex);
584   UNUSED(ChannelDir);
585 
586   /* NOTE : This function should not be modified, when the callback is needed,
587             the HAL_IPCC_RxCallback can be implemented in the user file
588    */
589 }
590 
591 /**
592   * @brief Tx free callback
593   * @param hipcc IPCC handle
594   * @param ChannelIndex Channel number
595   *          This parameter can be one of the following values:
596   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
597   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
598   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
599   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
600   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
601   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
602   * @param ChannelDir Channel direction
603   */
HAL_IPCC_TxCallback(IPCC_HandleTypeDef * hipcc,uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)604 __weak void HAL_IPCC_TxCallback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
605 {
606   /* Prevent unused argument(s) compilation warning */
607   UNUSED(hipcc);
608   UNUSED(ChannelIndex);
609   UNUSED(ChannelDir);
610 
611   /* NOTE : This function should not be modified, when the callback is needed,
612             the HAL_IPCC_TxCallback can be implemented in the user file
613    */
614 }
615 
616 /**
617   * @}
618   */
619 
620 /** @addtogroup IPCC_Exported_Functions_Group3
621   *  @brief   IPCC Peripheral State and Error functions
622   *
623 @verbatim
624   ==============================================================================
625             ##### Peripheral State and Error functions #####
626   ==============================================================================
627     [..]
628     This subsection permit to get in run-time the status of the peripheral
629     and the data flow.
630 
631 @endverbatim
632   * @{
633   */
634 
635 /**
636   * @brief Return the IPCC handle state.
637   * @param  hipcc IPCC handle
638   * @retval IPCC handle state
639   */
HAL_IPCC_GetState(IPCC_HandleTypeDef const * const hipcc)640 HAL_IPCC_StateTypeDef HAL_IPCC_GetState(IPCC_HandleTypeDef const *const hipcc)
641 {
642   return hipcc->State;
643 }
644 
645 /**
646   * @}
647   */
648 
649 /**
650   * @}
651   */
652 
653 /** @addtogroup IPCC_Private_Functions
654   * @{
655   */
656 
657 /**
658   * @brief  Mask IPCC interrupts.
659   * @param  ChannelIndex Channel number
660   *          This parameter can be one of the following values:
661   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
662   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
663   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
664   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
665   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
666   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
667   * @param  ChannelDir Channel direction
668   */
IPCC_MaskInterrupt(uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)669 void IPCC_MaskInterrupt(uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
670 {
671   IPCC_CommonTypeDef *currentInstance = IPCC_C1;
672   if (ChannelDir == IPCC_CHANNEL_DIR_TX)
673   {
674     /* Mask interrupt */
675     currentInstance->MR |= (IPCC_MR_CH1FM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
676   }
677   else
678   {
679     /* Mask interrupt */
680     currentInstance->MR |= (IPCC_MR_CH1OM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
681   }
682 }
683 /**
684   * @brief  Unmask IPCC interrupts.
685   * @param  ChannelIndex Channel number
686   *          This parameter can be one of the following values:
687   *            @arg IPCC_CHANNEL_1: IPCC Channel 1
688   *            @arg IPCC_CHANNEL_2: IPCC Channel 2
689   *            @arg IPCC_CHANNEL_3: IPCC Channel 3
690   *            @arg IPCC_CHANNEL_4: IPCC Channel 4
691   *            @arg IPCC_CHANNEL_5: IPCC Channel 5
692   *            @arg IPCC_CHANNEL_6: IPCC Channel 6
693   * @param  ChannelDir Channel direction
694   */
IPCC_UnmaskInterrupt(uint32_t ChannelIndex,IPCC_CHANNELDirTypeDef ChannelDir)695 void IPCC_UnmaskInterrupt(uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir)
696 {
697   IPCC_CommonTypeDef *currentInstance = IPCC_C1;
698   if (ChannelDir == IPCC_CHANNEL_DIR_TX)
699   {
700     /* Unmask interrupt */
701     currentInstance->MR &= ~(IPCC_MR_CH1FM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
702   }
703   else
704   {
705     /* Unmask interrupt */
706     currentInstance->MR &= ~(IPCC_MR_CH1OM_Msk << (ChannelIndex & CHANNEL_INDEX_MASK));
707   }
708 }
709 
710 /**
711   * @brief Reset all callbacks of the handle to NULL.
712   * @param  hipcc IPCC handle
713   */
IPCC_SetDefaultCallbacks(IPCC_HandleTypeDef * hipcc)714 void IPCC_SetDefaultCallbacks(IPCC_HandleTypeDef *hipcc)
715 {
716   uint32_t i;
717   /* Set all callbacks to default */
718   for (i = 0; i < IPCC_CHANNEL_NUMBER; i++)
719   {
720     hipcc->ChannelCallbackRx[i] = HAL_IPCC_RxCallback;
721     hipcc->ChannelCallbackTx[i] = HAL_IPCC_TxCallback;
722   }
723 }
724 
725 /**
726   * @brief Reset IPCC register to default value for the concerned instance.
727   * @param  Instance pointer to register
728   */
IPCC_Reset_Register(IPCC_CommonTypeDef * Instance)729 void IPCC_Reset_Register(IPCC_CommonTypeDef *Instance)
730 {
731   /* Disable RX and TX interrupts */
732   Instance->CR  = 0x00000000U;
733 
734   /* Mask RX and TX interrupts */
735   Instance->MR  = (IPCC_ALL_TX_BUF | IPCC_ALL_RX_BUF);
736 
737   /* Clear RX status */
738   Instance->SCR = IPCC_ALL_RX_BUF;
739 }
740 
741 /**
742   * @}
743   */
744 
745 #endif /* HAL_IPCC_MODULE_ENABLED */
746 
747 /**
748   * @}
749   */
750 
751 /**
752   * @}
753   */
754 #endif /* IPCC */
755