stm32f3xx_hal_cec.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_cec.c
  4. * @author MCD Application Team
  5. * @brief CEC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the High Definition Multimedia Interface
  8. * Consumer Electronics Control Peripheral (CEC).
  9. * + Initialization and de-initialization functions
  10. * + IO operation functions
  11. * + Peripheral Control functions
  12. *
  13. *
  14. @verbatim
  15. ===============================================================================
  16. ##### How to use this driver #####
  17. ===============================================================================
  18. [..]
  19. The CEC HAL driver can be used as follow:
  20. (#) Declare a CEC_HandleTypeDef handle structure.
  21. (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API:
  22. (##) Enable the CEC interface clock.
  23. (##) CEC pins configuration:
  24. (+) Enable the clock for the CEC GPIOs.
  25. (+) Configure these CEC pins as alternate function pull-up.
  26. (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT()
  27. and HAL_CEC_Receive_IT() APIs):
  28. (+) Configure the CEC interrupt priority.
  29. (+) Enable the NVIC CEC IRQ handle.
  30. (@) The specific CEC interrupts (Transmission complete interrupt,
  31. RXNE interrupt and Error Interrupts) will be managed using the macros
  32. __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit
  33. and receive process.
  34. (#) Program the Signal Free Time (SFT) and SFT option, Tolerance, reception stop in
  35. in case of Bit Rising Error, Error-Bit generation conditions, device logical
  36. address and Listen mode in the hcec Init structure.
  37. (#) Initialize the CEC registers by calling the HAL_CEC_Init() API.
  38. (@) This API (HAL_CEC_Init()) configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
  39. by calling the customed HAL_CEC_MspInit() API.
  40. @endverbatim
  41. ******************************************************************************
  42. * @attention
  43. *
  44. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  45. *
  46. * Redistribution and use in source and binary forms, with or without modification,
  47. * are permitted provided that the following conditions are met:
  48. * 1. Redistributions of source code must retain the above copyright notice,
  49. * this list of conditions and the following disclaimer.
  50. * 2. Redistributions in binary form must reproduce the above copyright notice,
  51. * this list of conditions and the following disclaimer in the documentation
  52. * and/or other materials provided with the distribution.
  53. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  54. * may be used to endorse or promote products derived from this software
  55. * without specific prior written permission.
  56. *
  57. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  58. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  59. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  60. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  61. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  62. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  65. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  66. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67. *
  68. ******************************************************************************
  69. */
  70. /* Includes ------------------------------------------------------------------*/
  71. #include "stm32f3xx_hal.h"
  72. /** @addtogroup STM32F3xx_HAL_Driver
  73. * @{
  74. */
  75. #ifdef HAL_CEC_MODULE_ENABLED
  76. #if defined(STM32F373xC) || defined(STM32F378xx)
  77. /** @defgroup CEC CEC
  78. * @brief HAL CEC module driver
  79. * @{
  80. */
  81. /* Private typedef -----------------------------------------------------------*/
  82. /* Private define ------------------------------------------------------------*/
  83. /** @defgroup CEC_Private_Constants CEC Private Constants
  84. * @{
  85. */
  86. /**
  87. * @}
  88. */
  89. /* Private macro -------------------------------------------------------------*/
  90. /* Private variables ---------------------------------------------------------*/
  91. /* Private function prototypes -----------------------------------------------*/
  92. /** @defgroup CEC_Private_Functions CEC Private Functions
  93. * @{
  94. */
  95. /**
  96. * @}
  97. */
  98. /* Exported functions ---------------------------------------------------------*/
  99. /** @defgroup CEC_Exported_Functions CEC Exported Functions
  100. * @{
  101. */
  102. /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions
  103. * @brief Initialization and Configuration functions
  104. *
  105. @verbatim
  106. ===============================================================================
  107. ##### Initialization and Configuration functions #####
  108. ===============================================================================
  109. [..]
  110. This subsection provides a set of functions allowing to initialize the CEC
  111. (+) The following parameters need to be configured:
  112. (++) SignalFreeTime
  113. (++) Tolerance
  114. (++) BRERxStop (RX stopped or not upon Bit Rising Error)
  115. (++) BREErrorBitGen (Error-Bit generation in case of Bit Rising Error)
  116. (++) LBPEErrorBitGen (Error-Bit generation in case of Long Bit Period Error)
  117. (++) BroadcastMsgNoErrorBitGen (Error-bit generation in case of broadcast message error)
  118. (++) SignalFreeTimeOption (SFT Timer start definition)
  119. (++) OwnAddress (CEC device address)
  120. (++) ListenMode
  121. @endverbatim
  122. * @{
  123. */
  124. /**
  125. * @brief Initializes the CEC mode according to the specified
  126. * parameters in the CEC_InitTypeDef and creates the associated handle .
  127. * @param hcec CEC handle
  128. * @retval HAL status
  129. */
  130. HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec)
  131. {
  132. /* Check the CEC handle allocation */
  133. if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL))
  134. {
  135. return HAL_ERROR;
  136. }
  137. /* Check the parameters */
  138. assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
  139. assert_param(IS_CEC_SIGNALFREETIME(hcec->Init.SignalFreeTime));
  140. assert_param(IS_CEC_TOLERANCE(hcec->Init.Tolerance));
  141. assert_param(IS_CEC_BRERXSTOP(hcec->Init.BRERxStop));
  142. assert_param(IS_CEC_BREERRORBITGEN(hcec->Init.BREErrorBitGen));
  143. assert_param(IS_CEC_LBPEERRORBITGEN(hcec->Init.LBPEErrorBitGen));
  144. assert_param(IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(hcec->Init.BroadcastMsgNoErrorBitGen));
  145. assert_param(IS_CEC_SFTOP(hcec->Init.SignalFreeTimeOption));
  146. assert_param(IS_CEC_LISTENING_MODE(hcec->Init.ListenMode));
  147. assert_param(IS_CEC_OWN_ADDRESS(hcec->Init.OwnAddress));
  148. if(hcec->gState == HAL_CEC_STATE_RESET)
  149. {
  150. /* Allocate lock resource and initialize it */
  151. hcec->Lock = HAL_UNLOCKED;
  152. /* Init the low level hardware : GPIO, CLOCK */
  153. HAL_CEC_MspInit(hcec);
  154. }
  155. hcec->gState = HAL_CEC_STATE_BUSY;
  156. /* Disable the Peripheral */
  157. __HAL_CEC_DISABLE(hcec);
  158. /* Write to CEC Control Register */
  159. hcec->Instance->CFGR = hcec->Init.SignalFreeTime | hcec->Init.Tolerance | hcec->Init.BRERxStop|\
  160. hcec->Init.BREErrorBitGen | hcec->Init.LBPEErrorBitGen | hcec->Init.BroadcastMsgNoErrorBitGen |\
  161. hcec->Init.SignalFreeTimeOption |((uint32_t)(hcec->Init.OwnAddress)<<16U) |\
  162. hcec->Init.ListenMode;
  163. /* Enable the following CEC Transmission/Reception interrupts as
  164. * well as the following CEC Transmission/Reception Errors interrupts
  165. * Rx Byte Received IT
  166. * End of Reception IT
  167. * Rx overrun
  168. * Rx bit rising error
  169. * Rx short bit period error
  170. * Rx long bit period error
  171. * Rx missing acknowledge
  172. * Tx Byte Request IT
  173. * End of Transmission IT
  174. * Tx Missing Acknowledge IT
  175. * Tx-Error IT
  176. * Tx-Buffer Underrun IT
  177. * Tx arbitration lost */
  178. __HAL_CEC_ENABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
  179. /* Enable the CEC Peripheral */
  180. __HAL_CEC_ENABLE(hcec);
  181. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  182. hcec->gState = HAL_CEC_STATE_READY;
  183. hcec->RxState = HAL_CEC_STATE_READY;
  184. return HAL_OK;
  185. }
  186. /**
  187. * @brief DeInitializes the CEC peripheral
  188. * @param hcec CEC handle
  189. * @retval HAL status
  190. */
  191. HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec)
  192. {
  193. /* Check the CEC handle allocation */
  194. if(hcec == NULL)
  195. {
  196. return HAL_ERROR;
  197. }
  198. /* Check the parameters */
  199. assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
  200. hcec->gState = HAL_CEC_STATE_BUSY;
  201. /* DeInit the low level hardware */
  202. HAL_CEC_MspDeInit(hcec);
  203. /* Disable the Peripheral */
  204. __HAL_CEC_DISABLE(hcec);
  205. /* Clear Flags */
  206. __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXEND|CEC_FLAG_TXBR|CEC_FLAG_RXBR|CEC_FLAG_RXEND|CEC_ISR_ALL_ERROR);
  207. /* Disable the following CEC Transmission/Reception interrupts as
  208. * well as the following CEC Transmission/Reception Errors interrupts
  209. * Rx Byte Received IT
  210. * End of Reception IT
  211. * Rx overrun
  212. * Rx bit rising error
  213. * Rx short bit period error
  214. * Rx long bit period error
  215. * Rx missing acknowledge
  216. * Tx Byte Request IT
  217. * End of Transmission IT
  218. * Tx Missing Acknowledge IT
  219. * Tx-Error IT
  220. * Tx-Buffer Underrun IT
  221. * Tx arbitration lost */
  222. __HAL_CEC_DISABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
  223. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  224. hcec->gState = HAL_CEC_STATE_RESET;
  225. hcec->RxState = HAL_CEC_STATE_RESET;
  226. /* Process Unlock */
  227. __HAL_UNLOCK(hcec);
  228. return HAL_OK;
  229. }
  230. /**
  231. * @brief Initializes the Own Address of the CEC device
  232. * @param hcec CEC handle
  233. * @param CEC_OwnAddress The CEC own address.
  234. * @retval HAL status
  235. */
  236. HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress)
  237. {
  238. /* Check the parameters */
  239. assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress));
  240. if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY))
  241. {
  242. /* Process Locked */
  243. __HAL_LOCK(hcec);
  244. hcec->gState = HAL_CEC_STATE_BUSY;
  245. /* Disable the Peripheral */
  246. __HAL_CEC_DISABLE(hcec);
  247. if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE)
  248. {
  249. hcec->Instance->CFGR |= ((uint32_t)CEC_OwnAddress<<16U);
  250. }
  251. else
  252. {
  253. hcec->Instance->CFGR &= ~(CEC_CFGR_OAR);
  254. }
  255. hcec->gState = HAL_CEC_STATE_READY;
  256. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  257. /* Process Unlocked */
  258. __HAL_UNLOCK(hcec);
  259. /* Enable the Peripheral */
  260. __HAL_CEC_ENABLE(hcec);
  261. return HAL_OK;
  262. }
  263. else
  264. {
  265. return HAL_BUSY;
  266. }
  267. }
  268. /**
  269. * @brief CEC MSP Init
  270. * @param hcec CEC handle
  271. * @retval None
  272. */
  273. __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec)
  274. {
  275. /* Prevent unused argument(s) compilation warning */
  276. UNUSED(hcec);
  277. /* NOTE : This function should not be modified, when the callback is needed,
  278. the HAL_CEC_MspInit can be implemented in the user file
  279. */
  280. }
  281. /**
  282. * @brief CEC MSP DeInit
  283. * @param hcec CEC handle
  284. * @retval None
  285. */
  286. __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec)
  287. {
  288. /* Prevent unused argument(s) compilation warning */
  289. UNUSED(hcec);
  290. /* NOTE : This function should not be modified, when the callback is needed,
  291. the HAL_CEC_MspDeInit can be implemented in the user file
  292. */
  293. }
  294. /**
  295. * @}
  296. */
  297. /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions
  298. * @brief CEC Transmit/Receive functions
  299. *
  300. @verbatim
  301. ===============================================================================
  302. ##### IO operation functions #####
  303. ===============================================================================
  304. This subsection provides a set of functions allowing to manage the CEC data transfers.
  305. (#) The CEC handle must contain the initiator (TX side) and the destination (RX side)
  306. logical addresses (4-bit long addresses, 0x0F for broadcast messages destination)
  307. (#) The communication is performed using Interrupts.
  308. These API's return the HAL status.
  309. The end of the data processing will be indicated through the
  310. dedicated CEC IRQ when using Interrupt mode.
  311. The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks
  312. will be executed respectivelly at the end of the transmit or Receive process
  313. The HAL_CEC_ErrorCallback()user callback will be executed when a communication
  314. error is detected
  315. (#) API's with Interrupt are :
  316. (+) HAL_CEC_Transmit_IT()
  317. (+) HAL_CEC_IRQHandler()
  318. (#) A set of User Callbacks are provided:
  319. (+) HAL_CEC_TxCpltCallback()
  320. (+) HAL_CEC_RxCpltCallback()
  321. (+) HAL_CEC_ErrorCallback()
  322. @endverbatim
  323. * @{
  324. */
  325. /**
  326. * @brief Send data in interrupt mode
  327. * @param hcec CEC handle
  328. * @param InitiatorAddress Initiator address
  329. * @param DestinationAddress destination logical address
  330. * @param pData pointer to input byte data buffer
  331. * @param Size amount of data to be sent in bytes (without counting the header).
  332. * 0 means only the header is sent (ping operation).
  333. * Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
  334. * @retval HAL status
  335. */
  336. HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size)
  337. {
  338. /* if the IP isn't already busy and if there is no previous transmission
  339. already pending due to arbitration lost */
  340. if (hcec->gState == HAL_CEC_STATE_READY)
  341. {
  342. if((pData == NULL ) && (Size > 0U))
  343. {
  344. return HAL_ERROR;
  345. }
  346. assert_param(IS_CEC_ADDRESS(DestinationAddress));
  347. assert_param(IS_CEC_ADDRESS(InitiatorAddress));
  348. assert_param(IS_CEC_MSGSIZE(Size));
  349. /* Process Locked */
  350. __HAL_LOCK(hcec);
  351. hcec->pTxBuffPtr = pData;
  352. hcec->gState = HAL_CEC_STATE_BUSY_TX;
  353. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  354. /* initialize the number of bytes to send,
  355. * 0 means only one header is sent (ping operation) */
  356. hcec->TxXferCount = Size;
  357. /* in case of no payload (Size = 0U), sender is only pinging the system;
  358. Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */
  359. if (Size == 0U)
  360. {
  361. __HAL_CEC_LAST_BYTE_TX_SET(hcec);
  362. }
  363. /* send header block */
  364. hcec->Instance->TXDR = ((uint8_t)(InitiatorAddress << CEC_INITIATOR_LSB_POS) |(uint8_t) DestinationAddress);
  365. /* Set TX Start of Message (TXSOM) bit */
  366. __HAL_CEC_FIRST_BYTE_TX_SET(hcec);
  367. /* Process Unlocked */
  368. __HAL_UNLOCK(hcec);
  369. return HAL_OK;
  370. }
  371. else
  372. {
  373. return HAL_BUSY;
  374. }
  375. }
  376. /**
  377. * @brief Get size of the received frame.
  378. * @param hcec CEC handle
  379. * @retval Frame size
  380. */
  381. uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec)
  382. {
  383. return hcec->RxXferSize;
  384. }
  385. /**
  386. * @brief Change Rx Buffer.
  387. * @param hcec CEC handle
  388. * @param Rxbuffer Rx Buffer
  389. * @note This function can be called only inside the HAL_CEC_RxCpltCallback()
  390. * @retval Frame size
  391. */
  392. void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer)
  393. {
  394. hcec->Init.RxBuffer = Rxbuffer;
  395. }
  396. /**
  397. * @brief This function handles CEC interrupt requests.
  398. * @param hcec CEC handle
  399. * @retval None
  400. */
  401. void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec)
  402. {
  403. /* save interrupts register for further error or interrupts handling purposes */
  404. uint32_t reg = 0U;
  405. reg = hcec->Instance->ISR;
  406. /* ----------------------------Arbitration Lost Management----------------------------------*/
  407. /* CEC TX arbitration error interrupt occurred --------------------------------------*/
  408. if((reg & CEC_FLAG_ARBLST) != RESET)
  409. {
  410. hcec->ErrorCode = HAL_CEC_ERROR_ARBLST;
  411. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST);
  412. }
  413. /* ----------------------------Rx Management----------------------------------*/
  414. /* CEC RX byte received interrupt ---------------------------------------------------*/
  415. if((reg & CEC_FLAG_RXBR) != RESET)
  416. {
  417. /* reception is starting */
  418. hcec->RxState = HAL_CEC_STATE_BUSY_RX;
  419. hcec->RxXferSize++;
  420. /* read received byte */
  421. *hcec->Init.RxBuffer++ = hcec->Instance->RXDR;
  422. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR);
  423. }
  424. /* CEC RX end received interrupt ---------------------------------------------------*/
  425. if((reg & CEC_FLAG_RXEND) != RESET)
  426. {
  427. /* clear IT */
  428. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXEND);
  429. /* Rx process is completed, restore hcec->RxState to Ready */
  430. hcec->RxState = HAL_CEC_STATE_READY;
  431. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  432. hcec->Init.RxBuffer -= hcec->RxXferSize;
  433. HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize);
  434. hcec->RxXferSize = 0U;
  435. }
  436. /* ----------------------------Tx Management----------------------------------*/
  437. /* CEC TX byte request interrupt ------------------------------------------------*/
  438. if((reg & CEC_FLAG_TXBR) != RESET)
  439. {
  440. if (hcec->TxXferCount == 0U)
  441. {
  442. /* if this is the last byte transmission, set TX End of Message (TXEOM) bit */
  443. __HAL_CEC_LAST_BYTE_TX_SET(hcec);
  444. hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
  445. }
  446. else
  447. {
  448. hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
  449. hcec->TxXferCount--;
  450. }
  451. /* clear Tx-Byte request flag */
  452. __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR);
  453. }
  454. /* CEC TX end interrupt ------------------------------------------------*/
  455. if((reg & CEC_FLAG_TXEND) != RESET)
  456. {
  457. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXEND);
  458. /* Tx process is ended, restore hcec->gState to Ready */
  459. hcec->gState = HAL_CEC_STATE_READY;
  460. /* Call the Process Unlocked before calling the Tx call back API to give the possibility to
  461. start again the Transmission under the Tx call back API */
  462. __HAL_UNLOCK(hcec);
  463. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  464. HAL_CEC_TxCpltCallback(hcec);
  465. }
  466. /* ----------------------------Rx/Tx Error Management----------------------------------*/
  467. if ((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE|CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != 0U)
  468. {
  469. hcec->ErrorCode = reg;
  470. __HAL_CEC_CLEAR_FLAG(hcec, HAL_CEC_ERROR_RXOVR|HAL_CEC_ERROR_BRE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|HAL_CEC_ERROR_RXACKE|HAL_CEC_ERROR_TXUDR|HAL_CEC_ERROR_TXERR|HAL_CEC_ERROR_TXACKE);
  471. if((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE)) != RESET)
  472. {
  473. hcec->Init.RxBuffer-=hcec->RxXferSize;
  474. hcec->RxXferSize = 0U;
  475. hcec->RxState = HAL_CEC_STATE_READY;
  476. }
  477. else if (((reg & (CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != RESET) && ((reg & CEC_ISR_ARBLST) == RESET))
  478. {
  479. /* Set the CEC state ready to be able to start again the process */
  480. hcec->gState = HAL_CEC_STATE_READY;
  481. }
  482. /* Error Call Back */
  483. HAL_CEC_ErrorCallback(hcec);
  484. }
  485. }
  486. /**
  487. * @brief Tx Transfer completed callback
  488. * @param hcec CEC handle
  489. * @retval None
  490. */
  491. __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec)
  492. {
  493. /* Prevent unused argument(s) compilation warning */
  494. UNUSED(hcec);
  495. /* NOTE : This function should not be modified, when the callback is needed,
  496. the HAL_CEC_TxCpltCallback can be implemented in the user file
  497. */
  498. }
  499. /**
  500. * @brief Rx Transfer completed callback
  501. * @param hcec CEC handle
  502. * @param RxFrameSize Size of frame
  503. * @retval None
  504. */
  505. __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize)
  506. {
  507. /* Prevent unused argument(s) compilation warning */
  508. UNUSED(hcec);
  509. UNUSED(RxFrameSize);
  510. /* NOTE : This function should not be modified, when the callback is needed,
  511. the HAL_CEC_RxCpltCallback can be implemented in the user file
  512. */
  513. }
  514. /**
  515. * @brief CEC error callbacks
  516. * @param hcec CEC handle
  517. * @retval None
  518. */
  519. __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec)
  520. {
  521. /* Prevent unused argument(s) compilation warning */
  522. UNUSED(hcec);
  523. /* NOTE : This function should not be modified, when the callback is needed,
  524. the HAL_CEC_ErrorCallback can be implemented in the user file
  525. */
  526. }
  527. /**
  528. * @}
  529. */
  530. /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control function
  531. * @brief CEC control functions
  532. *
  533. @verbatim
  534. ===============================================================================
  535. ##### Peripheral Control function #####
  536. ===============================================================================
  537. [..]
  538. This subsection provides a set of functions allowing to control the CEC.
  539. (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral.
  540. (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral.
  541. @endverbatim
  542. * @{
  543. */
  544. /**
  545. * @brief return the CEC state
  546. * @param hcec pointer to a CEC_HandleTypeDef structure that contains
  547. * the configuration information for the specified CEC module.
  548. * @retval HAL state
  549. */
  550. HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec)
  551. {
  552. uint32_t temp1 = 0x00U, temp2 = 0x00U;
  553. temp1 = hcec->gState;
  554. temp2 = hcec->RxState;
  555. return (HAL_CEC_StateTypeDef)(temp1 | temp2);
  556. }
  557. /**
  558. * @brief Return the CEC error code
  559. * @param hcec pointer to a CEC_HandleTypeDef structure that contains
  560. * the configuration information for the specified CEC.
  561. * @retval CEC Error Code
  562. */
  563. uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec)
  564. {
  565. return hcec->ErrorCode;
  566. }
  567. /**
  568. * @}
  569. */
  570. /**
  571. * @}
  572. */
  573. #endif /* defined(STM32F373xC) || defined(STM32F378xx) */
  574. #endif /* HAL_CEC_MODULE_ENABLED */
  575. /**
  576. * @}
  577. */
  578. /**
  579. * @}
  580. */
  581. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/