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