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