You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

748 lines
23 KiB

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