Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32f1xx_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 function |
||
| 10 | * + IO operation function |
||
| 11 | * + Peripheral Control function |
||
| 12 | * |
||
| 13 | * |
||
| 14 | @verbatim |
||
| 15 | =============================================================================== |
||
| 16 | ##### How to use this driver ##### |
||
| 17 | =============================================================================== |
||
| 18 | [..] |
||
| 19 | The CEC HAL driver can be used as follow: |
||
| 20 | |||
| 21 | (#) Declare a CEC_HandleTypeDef handle structure. |
||
| 22 | (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API: |
||
| 23 | (##) Enable the CEC interface clock. |
||
| 24 | (##) CEC pins configuration: |
||
| 25 | (+++) Enable the clock for the CEC GPIOs. |
||
| 26 | (+++) Configure these CEC pins as alternate function pull-up. |
||
| 27 | (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT() |
||
| 28 | and HAL_CEC_Receive_IT() APIs): |
||
| 29 | (+++) Configure the CEC interrupt priority. |
||
| 30 | (+++) Enable the NVIC CEC IRQ handle. |
||
| 31 | (+++) The specific CEC interrupts (Transmission complete interrupt, |
||
| 32 | RXNE interrupt and Error Interrupts) will be managed using the macros |
||
| 33 | __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit |
||
| 34 | and receive process. |
||
| 35 | |||
| 36 | (#) Program the Bit Timing Error Mode and the Bit Period Error Mode in the hcec Init structure. |
||
| 37 | |||
| 38 | (#) Initialize the CEC registers by calling the HAL_CEC_Init() API. |
||
| 39 | |||
| 40 | [..] |
||
| 41 | (@) This API (HAL_CEC_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc) |
||
| 42 | by calling the customed HAL_CEC_MspInit() API. |
||
| 43 | |||
| 44 | @endverbatim |
||
| 45 | ****************************************************************************** |
||
| 46 | * @attention |
||
| 47 | * |
||
| 48 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
||
| 49 | * |
||
| 50 | * Redistribution and use in source and binary forms, with or without modification, |
||
| 51 | * are permitted provided that the following conditions are met: |
||
| 52 | * 1. Redistributions of source code must retain the above copyright notice, |
||
| 53 | * this list of conditions and the following disclaimer. |
||
| 54 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
| 55 | * this list of conditions and the following disclaimer in the documentation |
||
| 56 | * and/or other materials provided with the distribution. |
||
| 57 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
||
| 58 | * may be used to endorse or promote products derived from this software |
||
| 59 | * without specific prior written permission. |
||
| 60 | * |
||
| 61 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
| 62 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
| 63 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
| 64 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||
| 65 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
| 66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||
| 67 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
| 68 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||
| 69 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
| 70 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 71 | * |
||
| 72 | ****************************************************************************** |
||
| 73 | */ |
||
| 74 | |||
| 75 | /* Includes ------------------------------------------------------------------*/ |
||
| 76 | #include "stm32f1xx_hal.h" |
||
| 77 | |||
| 78 | #ifdef HAL_CEC_MODULE_ENABLED |
||
| 79 | |||
| 80 | #if defined(STM32F100xB) || defined(STM32F100xE) |
||
| 81 | |||
| 82 | /** @addtogroup STM32F1xx_HAL_Driver |
||
| 83 | * @{ |
||
| 84 | */ |
||
| 85 | |||
| 86 | /** @defgroup CEC CEC |
||
| 87 | * @brief HAL CEC module driver |
||
| 88 | * @{ |
||
| 89 | */ |
||
| 90 | |||
| 91 | /* Private typedef -----------------------------------------------------------*/ |
||
| 92 | /* Private define ------------------------------------------------------------*/ |
||
| 93 | /** @defgroup CEC_Private_Constants CEC Private Constants |
||
| 94 | * @{ |
||
| 95 | */ |
||
| 96 | #define CEC_CFGR_FIELDS (CEC_CFGR_BTEM | CEC_CFGR_BPEM ) |
||
| 97 | #define CEC_FLAG_TRANSMIT_MASK (CEC_FLAG_TSOM|CEC_FLAG_TEOM|CEC_FLAG_TBTRF) |
||
| 98 | #define CEC_FLAG_RECEIVE_MASK (CEC_FLAG_RSOM|CEC_FLAG_REOM|CEC_FLAG_RBTF) |
||
| 99 | #define CEC_ESR_ALL_ERROR (CEC_ESR_BTE|CEC_ESR_BPE|CEC_ESR_RBTFE|CEC_ESR_SBE|CEC_ESR_ACKE|CEC_ESR_LINE|CEC_ESR_TBTFE) |
||
| 100 | #define CEC_RXXFERSIZE_INITIALIZE 0xFFFF /*!< Value used to initialise the RxXferSize of the handle */ |
||
| 101 | /** |
||
| 102 | * @} |
||
| 103 | */ |
||
| 104 | |||
| 105 | /* Private macro -------------------------------------------------------------*/ |
||
| 106 | /* Private variables ---------------------------------------------------------*/ |
||
| 107 | /* Private function prototypes -----------------------------------------------*/ |
||
| 108 | /** @defgroup CEC_Private_Functions CEC Private Functions |
||
| 109 | * @{ |
||
| 110 | */ |
||
| 111 | static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec); |
||
| 112 | static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec); |
||
| 113 | /** |
||
| 114 | * @} |
||
| 115 | */ |
||
| 116 | |||
| 117 | /* Exported functions ---------------------------------------------------------*/ |
||
| 118 | |||
| 119 | /** @defgroup CEC_Exported_Functions CEC Exported Functions |
||
| 120 | * @{ |
||
| 121 | */ |
||
| 122 | |||
| 123 | /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions |
||
| 124 | * @brief Initialization and Configuration functions |
||
| 125 | * |
||
| 126 | @verbatim |
||
| 127 | =============================================================================== |
||
| 128 | ##### Initialization and Configuration functions ##### |
||
| 129 | =============================================================================== |
||
| 130 | [..] |
||
| 131 | This subsection provides a set of functions allowing to initialize the CEC |
||
| 132 | (+) The following parameters need to be configured: |
||
| 133 | (++) TimingErrorFree |
||
| 134 | (++) PeriodErrorFree |
||
| 135 | (++) InitiatorAddress |
||
| 136 | |||
| 137 | @endverbatim |
||
| 138 | * @{ |
||
| 139 | */ |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @brief Initializes the CEC mode according to the specified |
||
| 143 | * parameters in the CEC_InitTypeDef and creates the associated handle . |
||
| 144 | * @param hcec: CEC handle |
||
| 145 | * @retval HAL status |
||
| 146 | */ |
||
| 147 | HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec) |
||
| 148 | { |
||
| 149 | /* Check the CEC handle allocation */ |
||
| 150 | if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL)) |
||
| 151 | { |
||
| 152 | return HAL_ERROR; |
||
| 153 | } |
||
| 154 | |||
| 155 | /* Check the parameters */ |
||
| 156 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
||
| 157 | assert_param(IS_CEC_BIT_TIMING_ERROR_MODE(hcec->Init.TimingErrorFree)); |
||
| 158 | assert_param(IS_CEC_BIT_PERIOD_ERROR_MODE(hcec->Init.PeriodErrorFree)); |
||
| 159 | assert_param(IS_CEC_ADDRESS(hcec->Init.OwnAddress)); |
||
| 160 | |||
| 161 | if(hcec->gState == HAL_CEC_STATE_RESET) |
||
| 162 | { |
||
| 163 | /* Allocate lock resource and initialize it */ |
||
| 164 | hcec->Lock = HAL_UNLOCKED; |
||
| 165 | /* Init the low level hardware : GPIO, CLOCK */ |
||
| 166 | HAL_CEC_MspInit(hcec); |
||
| 167 | } |
||
| 168 | hcec->gState = HAL_CEC_STATE_BUSY; |
||
| 169 | |||
| 170 | /* Disable the Peripheral */ |
||
| 171 | __HAL_CEC_DISABLE(hcec); |
||
| 172 | |||
| 173 | /* Write to CEC Control Register */ |
||
| 174 | MODIFY_REG(hcec->Instance->CFGR, CEC_CFGR_FIELDS, hcec->Init.TimingErrorFree | hcec->Init.PeriodErrorFree); |
||
| 175 | |||
| 176 | /* Write to CEC Own Address Register */ |
||
| 177 | MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.OwnAddress); |
||
| 178 | |||
| 179 | /* Configure the prescaler to generate the required 50 microseconds time base.*/ |
||
| 180 | MODIFY_REG(hcec->Instance->PRES, CEC_PRES_PRES, 50U * (HAL_RCC_GetPCLK1Freq()/1000000U) - 1U); |
||
| 181 | |||
| 182 | /* Enable the following CEC Interrupt */ |
||
| 183 | __HAL_CEC_ENABLE_IT(hcec, CEC_IT_IE); |
||
| 184 | |||
| 185 | /* Enable the CEC Peripheral */ |
||
| 186 | __HAL_CEC_ENABLE(hcec); |
||
| 187 | |||
| 188 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
||
| 189 | hcec->gState = HAL_CEC_STATE_READY; |
||
| 190 | hcec->RxState = HAL_CEC_STATE_READY; |
||
| 191 | |||
| 192 | return HAL_OK; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @brief DeInitializes the CEC peripheral |
||
| 197 | * @param hcec: CEC handle |
||
| 198 | * @retval HAL status |
||
| 199 | */ |
||
| 200 | HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec) |
||
| 201 | { |
||
| 202 | /* Check the CEC handle allocation */ |
||
| 203 | if(hcec == NULL) |
||
| 204 | { |
||
| 205 | return HAL_ERROR; |
||
| 206 | } |
||
| 207 | |||
| 208 | /* Check the parameters */ |
||
| 209 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
||
| 210 | |||
| 211 | hcec->gState = HAL_CEC_STATE_BUSY; |
||
| 212 | |||
| 213 | /* DeInit the low level hardware */ |
||
| 214 | HAL_CEC_MspDeInit(hcec); |
||
| 215 | |||
| 216 | __HAL_RCC_CEC_FORCE_RESET(); |
||
| 217 | __HAL_RCC_CEC_RELEASE_RESET(); |
||
| 218 | |||
| 219 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
||
| 220 | hcec->gState = HAL_CEC_STATE_RESET; |
||
| 221 | hcec->RxState = HAL_CEC_STATE_RESET; |
||
| 222 | |||
| 223 | /* Process Unlock */ |
||
| 224 | __HAL_UNLOCK(hcec); |
||
| 225 | |||
| 226 | return HAL_OK; |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @brief Initializes the Own Address of the CEC device |
||
| 231 | * @param hcec: CEC handle |
||
| 232 | * @param CEC_OwnAddress: The CEC own address. |
||
| 233 | * @retval HAL status |
||
| 234 | */ |
||
| 235 | HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress) |
||
| 236 | { |
||
| 237 | /* Check the parameters */ |
||
| 238 | assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress)); |
||
| 239 | |||
| 240 | if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY)) |
||
| 241 | { |
||
| 242 | /* Process Locked */ |
||
| 243 | __HAL_LOCK(hcec); |
||
| 244 | |||
| 245 | hcec->gState = HAL_CEC_STATE_BUSY; |
||
| 246 | |||
| 247 | /* Disable the Peripheral */ |
||
| 248 | __HAL_CEC_DISABLE(hcec); |
||
| 249 | |||
| 250 | if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE) |
||
| 251 | { |
||
| 252 | MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.OwnAddress); |
||
| 253 | } |
||
| 254 | else |
||
| 255 | { |
||
| 256 | CLEAR_BIT(hcec->Instance->OAR, CEC_OAR_OA); |
||
| 257 | } |
||
| 258 | |||
| 259 | hcec->gState = HAL_CEC_STATE_READY; |
||
| 260 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
||
| 261 | |||
| 262 | /* Process Unlocked */ |
||
| 263 | __HAL_UNLOCK(hcec); |
||
| 264 | |||
| 265 | /* Enable the Peripheral */ |
||
| 266 | __HAL_CEC_ENABLE(hcec); |
||
| 267 | |||
| 268 | return HAL_OK; |
||
| 269 | } |
||
| 270 | else |
||
| 271 | { |
||
| 272 | return HAL_BUSY; |
||
| 273 | } |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @brief CEC MSP Init |
||
| 278 | * @param hcec: CEC handle |
||
| 279 | * @retval None |
||
| 280 | */ |
||
| 281 | __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec) |
||
| 282 | { |
||
| 283 | /* Prevent unused argument(s) compilation warning */ |
||
| 284 | UNUSED(hcec); |
||
| 285 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 286 | the HAL_CEC_MspInit can be implemented in the user file |
||
| 287 | */ |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @brief CEC MSP DeInit |
||
| 292 | * @param hcec: CEC handle |
||
| 293 | * @retval None |
||
| 294 | */ |
||
| 295 | __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec) |
||
| 296 | { |
||
| 297 | /* Prevent unused argument(s) compilation warning */ |
||
| 298 | UNUSED(hcec); |
||
| 299 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 300 | the HAL_CEC_MspDeInit can be implemented in the user file |
||
| 301 | */ |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @} |
||
| 306 | */ |
||
| 307 | |||
| 308 | /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions |
||
| 309 | * @brief CEC Transmit/Receive functions |
||
| 310 | * |
||
| 311 | @verbatim |
||
| 312 | =============================================================================== |
||
| 313 | ##### IO operation functions ##### |
||
| 314 | =============================================================================== |
||
| 315 | [..] |
||
| 316 | This subsection provides a set of functions allowing to manage the CEC data transfers. |
||
| 317 | |||
| 318 | (#) The CEC handle must contain the initiator (TX side) and the destination (RX side) |
||
| 319 | logical addresses (4-bit long addresses, 0xF for broadcast messages destination) |
||
| 320 | |||
| 321 | (#) The communication is performed using Interrupts. |
||
| 322 | These API's return the HAL status. |
||
| 323 | The end of the data processing will be indicated through the |
||
| 324 | dedicated CEC IRQ when using Interrupt mode. |
||
| 325 | The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks |
||
| 326 | will be executed respectively at the end of the transmit or Receive process |
||
| 327 | The HAL_CEC_ErrorCallback() user callback will be executed when a communication |
||
| 328 | error is detected |
||
| 329 | |||
| 330 | (#) API's with Interrupt are : |
||
| 331 | (+) HAL_CEC_Transmit_IT() |
||
| 332 | (+) HAL_CEC_IRQHandler() |
||
| 333 | |||
| 334 | (#) A set of User Callbacks are provided: |
||
| 335 | (+) HAL_CEC_TxCpltCallback() |
||
| 336 | (+) HAL_CEC_RxCpltCallback() |
||
| 337 | (+) HAL_CEC_ErrorCallback() |
||
| 338 | |||
| 339 | @endverbatim |
||
| 340 | * @{ |
||
| 341 | */ |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @brief Send data in interrupt mode |
||
| 345 | * @param hcec: CEC handle |
||
| 346 | * @param InitiatorAddress: Initiator address |
||
| 347 | * @param DestinationAddress: destination logical address |
||
| 348 | * @param pData: pointer to input byte data buffer |
||
| 349 | * @param Size: amount of data to be sent in bytes (without counting the header). |
||
| 350 | * 0 means only the header is sent (ping operation). |
||
| 351 | * Maximum TX size is 15 bytes (1 opcode and up to 14 operands). |
||
| 352 | * @retval HAL status |
||
| 353 | */ |
||
| 354 | HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress,uint8_t DestinationAddress, uint8_t *pData, uint32_t Size) |
||
| 355 | { |
||
| 356 | /* if the IP isn't already busy and if there is no previous transmission |
||
| 357 | already pending due to arbitration lost */ |
||
| 358 | if(hcec->gState == HAL_CEC_STATE_READY) |
||
| 359 | { |
||
| 360 | if((pData == NULL ) && (Size > 0U)) |
||
| 361 | { |
||
| 362 | return HAL_ERROR; |
||
| 363 | } |
||
| 364 | |||
| 365 | assert_param(IS_CEC_ADDRESS(DestinationAddress)); |
||
| 366 | assert_param(IS_CEC_ADDRESS(InitiatorAddress)); |
||
| 367 | assert_param(IS_CEC_MSGSIZE(Size)); |
||
| 368 | |||
| 369 | /* Process Locked */ |
||
| 370 | __HAL_LOCK(hcec); |
||
| 371 | hcec->pTxBuffPtr = pData; |
||
| 372 | hcec->gState = HAL_CEC_STATE_BUSY_TX; |
||
| 373 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
||
| 374 | |||
| 375 | /* initialize the number of bytes to send, |
||
| 376 | * 0 means only one header is sent (ping operation) */ |
||
| 377 | hcec->TxXferCount = Size; |
||
| 378 | |||
| 379 | /* send header block */ |
||
| 380 | hcec->Instance->TXD = (uint8_t)((uint32_t)InitiatorAddress << CEC_INITIATOR_LSB_POS) | DestinationAddress; |
||
| 381 | |||
| 382 | /* Process Unlocked */ |
||
| 383 | __HAL_UNLOCK(hcec); |
||
| 384 | |||
| 385 | /* case no data to be sent, sender is only pinging the system */ |
||
| 386 | if (Size != 0) |
||
| 387 | { |
||
| 388 | /* Set TX Start of Message (TXSOM) bit */ |
||
| 389 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TSOM); |
||
| 390 | } |
||
| 391 | else |
||
| 392 | { |
||
| 393 | /* Send a ping command */ |
||
| 394 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM|CEC_FLAG_TSOM); |
||
| 395 | } |
||
| 396 | return HAL_OK; |
||
| 397 | |||
| 398 | } |
||
| 399 | else |
||
| 400 | { |
||
| 401 | return HAL_BUSY; |
||
| 402 | } |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @brief Get size of the received frame. |
||
| 407 | * @param hcec: CEC handle |
||
| 408 | * @retval Frame size |
||
| 409 | */ |
||
| 410 | uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec) |
||
| 411 | { |
||
| 412 | return hcec->RxXferSize; |
||
| 413 | } |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @brief Change Rx Buffer. |
||
| 417 | * @param hcec: CEC handle |
||
| 418 | * @param Rxbuffer: Rx Buffer |
||
| 419 | * @note This function can be called only inside the HAL_CEC_RxCpltCallback() |
||
| 420 | * @retval Frame size |
||
| 421 | */ |
||
| 422 | void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer) |
||
| 423 | { |
||
| 424 | hcec->Init.RxBuffer = Rxbuffer; |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @brief This function handles CEC interrupt requests. |
||
| 429 | * @param hcec: CEC handle |
||
| 430 | * @retval None |
||
| 431 | */ |
||
| 432 | void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec) |
||
| 433 | { |
||
| 434 | /* Save error status register for further error handling purposes */ |
||
| 435 | hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR); |
||
| 436 | |||
| 437 | /* Transmit error */ |
||
| 438 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TERR) != RESET) |
||
| 439 | { |
||
| 440 | /* Acknowledgement of the error */ |
||
| 441 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR); |
||
| 442 | |||
| 443 | hcec->gState = HAL_CEC_STATE_READY; |
||
| 444 | } |
||
| 445 | |||
| 446 | /* Receive error */ |
||
| 447 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RERR) != RESET) |
||
| 448 | { |
||
| 449 | /* Acknowledgement of the error */ |
||
| 450 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR); |
||
| 451 | hcec->Init.RxBuffer-=hcec->RxXferSize; |
||
| 452 | hcec->RxXferSize = 0U; |
||
| 453 | hcec->RxState = HAL_CEC_STATE_READY; |
||
| 454 | } |
||
| 455 | |||
| 456 | if((hcec->ErrorCode & CEC_ESR_ALL_ERROR) != 0U) |
||
| 457 | { |
||
| 458 | /* Error Call Back */ |
||
| 459 | HAL_CEC_ErrorCallback(hcec); |
||
| 460 | } |
||
| 461 | |||
| 462 | /* Transmit byte request or block transfer finished */ |
||
| 463 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TBTRF) != RESET) |
||
| 464 | { |
||
| 465 | CEC_Transmit_IT(hcec); |
||
| 466 | } |
||
| 467 | |||
| 468 | /* Receive byte or block transfer finished */ |
||
| 469 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RBTF) != RESET) |
||
| 470 | { |
||
| 471 | if(hcec->RxXferSize == 0U) |
||
| 472 | { |
||
| 473 | /* reception is starting */ |
||
| 474 | hcec->RxState = HAL_CEC_STATE_BUSY_RX; |
||
| 475 | } |
||
| 476 | CEC_Receive_IT(hcec); |
||
| 477 | } |
||
| 478 | } |
||
| 479 | |||
| 480 | |||
| 481 | /** |
||
| 482 | * @brief Tx Transfer completed callback |
||
| 483 | * @param hcec: CEC handle |
||
| 484 | * @retval None |
||
| 485 | */ |
||
| 486 | __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec) |
||
| 487 | { |
||
| 488 | /* Prevent unused argument(s) compilation warning */ |
||
| 489 | UNUSED(hcec); |
||
| 490 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 491 | the HAL_CEC_TxCpltCallback can be implemented in the user file |
||
| 492 | */ |
||
| 493 | } |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @brief Rx Transfer completed callback |
||
| 497 | * @param hcec: CEC handle |
||
| 498 | * @param RxFrameSize: Size of frame |
||
| 499 | * @retval None |
||
| 500 | */ |
||
| 501 | __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize) |
||
| 502 | { |
||
| 503 | /* Prevent unused argument(s) compilation warning */ |
||
| 504 | UNUSED(hcec); |
||
| 505 | UNUSED(RxFrameSize); |
||
| 506 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 507 | the HAL_CEC_RxCpltCallback can be implemented in the user file |
||
| 508 | */ |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @brief CEC error callbacks |
||
| 513 | * @param hcec: CEC handle |
||
| 514 | * @retval None |
||
| 515 | */ |
||
| 516 | __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec) |
||
| 517 | { |
||
| 518 | /* Prevent unused argument(s) compilation warning */ |
||
| 519 | UNUSED(hcec); |
||
| 520 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 521 | the HAL_CEC_ErrorCallback can be implemented in the user file |
||
| 522 | */ |
||
| 523 | } |
||
| 524 | /** |
||
| 525 | * @} |
||
| 526 | */ |
||
| 527 | |||
| 528 | /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control functions |
||
| 529 | * @brief CEC control functions |
||
| 530 | * |
||
| 531 | @verbatim |
||
| 532 | =============================================================================== |
||
| 533 | ##### Peripheral Control function ##### |
||
| 534 | =============================================================================== |
||
| 535 | [..] |
||
| 536 | This subsection provides a set of functions allowing to control the CEC. |
||
| 537 | (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral. |
||
| 538 | (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral. |
||
| 539 | @endverbatim |
||
| 540 | * @{ |
||
| 541 | */ |
||
| 542 | /** |
||
| 543 | * @brief return the CEC state |
||
| 544 | * @param hcec: pointer to a CEC_HandleTypeDef structure that contains |
||
| 545 | * the configuration information for the specified CEC module. |
||
| 546 | * @retval HAL state |
||
| 547 | */ |
||
| 548 | HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec) |
||
| 549 | { |
||
| 550 | uint32_t temp1= 0x00U, temp2 = 0x00U; |
||
| 551 | temp1 = hcec->gState; |
||
| 552 | temp2 = hcec->RxState; |
||
| 553 | |||
| 554 | return (HAL_CEC_StateTypeDef)(temp1 | temp2); |
||
| 555 | } |
||
| 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 | * @} |
||
| 574 | */ |
||
| 575 | |||
| 576 | /** @addtogroup CEC_Private_Functions |
||
| 577 | * @{ |
||
| 578 | */ |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @brief Send data in interrupt mode |
||
| 582 | * @param hcec: CEC handle. |
||
| 583 | * Function called under interruption only, once |
||
| 584 | * interruptions have been enabled by HAL_CEC_Transmit_IT() |
||
| 585 | * @retval HAL status |
||
| 586 | */ |
||
| 587 | static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec) |
||
| 588 | { |
||
| 589 | /* if the IP is already busy or if there is a previous transmission |
||
| 590 | already pending due to arbitration loss */ |
||
| 591 | if((hcec->gState == HAL_CEC_STATE_BUSY_TX) || (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) != RESET)) |
||
| 592 | { |
||
| 593 | /* if all data have been sent */ |
||
| 594 | if(hcec->TxXferCount == 0U) |
||
| 595 | { |
||
| 596 | /* Acknowledge successful completion by writing 0x00 */ |
||
| 597 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00U); |
||
| 598 | |||
| 599 | hcec->gState = HAL_CEC_STATE_READY; |
||
| 600 | |||
| 601 | HAL_CEC_TxCpltCallback(hcec); |
||
| 602 | |||
| 603 | return HAL_OK; |
||
| 604 | } |
||
| 605 | else |
||
| 606 | { |
||
| 607 | /* Reduce the number of bytes to transfer by one */ |
||
| 608 | hcec->TxXferCount--; |
||
| 609 | |||
| 610 | /* Write data to TX buffer*/ |
||
| 611 | hcec->Instance->TXD = *hcec->pTxBuffPtr++; |
||
| 612 | |||
| 613 | /* If this is the last byte of the ongoing transmission */ |
||
| 614 | if(hcec->TxXferCount == 0U) |
||
| 615 | { |
||
| 616 | /* Acknowledge byte request and signal end of message */ |
||
| 617 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM); |
||
| 618 | } |
||
| 619 | else |
||
| 620 | { |
||
| 621 | /* Acknowledge byte request by writing 0x00 */ |
||
| 622 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00U); |
||
| 623 | } |
||
| 624 | |||
| 625 | return HAL_OK; |
||
| 626 | } |
||
| 627 | } |
||
| 628 | else |
||
| 629 | { |
||
| 630 | return HAL_BUSY; |
||
| 631 | } |
||
| 632 | } |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @brief Receive data in interrupt mode. |
||
| 636 | * @param hcec: CEC handle. |
||
| 637 | * Function called under interruption only, once |
||
| 638 | * interruptions have been enabled by HAL_CEC_Receive_IT() |
||
| 639 | * @retval HAL status |
||
| 640 | */ |
||
| 641 | static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec) |
||
| 642 | { |
||
| 643 | static uint32_t temp; |
||
| 644 | |||
| 645 | if(hcec->RxState == HAL_CEC_STATE_BUSY_RX) |
||
| 646 | { |
||
| 647 | temp = hcec->Instance->CSR; |
||
| 648 | |||
| 649 | /* Store received data */ |
||
| 650 | hcec->RxXferSize++; |
||
| 651 | *hcec->Init.RxBuffer++ = hcec->Instance->RXD; |
||
| 652 | |||
| 653 | /* Acknowledge received byte by writing 0x00 */ |
||
| 654 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_RECEIVE_MASK, 0x00U); |
||
| 655 | |||
| 656 | /* If the End Of Message is reached */ |
||
| 657 | if(HAL_IS_BIT_SET(temp, CEC_FLAG_REOM)) |
||
| 658 | { |
||
| 659 | /* Interrupts are not disabled due to transmission still ongoing */ |
||
| 660 | hcec->RxState = HAL_CEC_STATE_READY; |
||
| 661 | |||
| 662 | HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize); |
||
| 663 | |||
| 664 | return HAL_OK; |
||
| 665 | } |
||
| 666 | else |
||
| 667 | { |
||
| 668 | return HAL_BUSY; |
||
| 669 | } |
||
| 670 | } |
||
| 671 | else |
||
| 672 | { |
||
| 673 | return HAL_BUSY; |
||
| 674 | } |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * @} |
||
| 679 | */ |
||
| 680 | |||
| 681 | /** |
||
| 682 | * @} |
||
| 683 | */ |
||
| 684 | |||
| 685 | #endif /* defined(STM32F100xB) || defined(STM32F100xE) */ |
||
| 686 | |||
| 687 | #endif /* HAL_CEC_MODULE_ENABLED */ |
||
| 688 | /** |
||
| 689 | * @} |
||
| 690 | */ |
||
| 691 | |||
| 692 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |