mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
489:119543c9f674
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 489:119543c9f674 1 /**
mbed_official 489:119543c9f674 2 ******************************************************************************
mbed_official 489:119543c9f674 3 * @file stm32f1xx_hal_cec.c
mbed_official 489:119543c9f674 4 * @author MCD Application Team
mbed_official 489:119543c9f674 5 * @version V1.0.0
mbed_official 489:119543c9f674 6 * @date 15-December-2014
mbed_official 489:119543c9f674 7 * @brief CEC HAL module driver.
mbed_official 489:119543c9f674 8 * This file provides firmware functions to manage the following
mbed_official 489:119543c9f674 9 * functionalities of the High Definition Multimedia Interface
mbed_official 489:119543c9f674 10 * Consumer Electronics Control Peripheral (CEC).
mbed_official 489:119543c9f674 11 * + Initialization and de-initialization functions
mbed_official 489:119543c9f674 12 * + IO operation functions
mbed_official 489:119543c9f674 13 * + Peripheral Control functions
mbed_official 489:119543c9f674 14 *
mbed_official 489:119543c9f674 15 * @verbatim
mbed_official 489:119543c9f674 16 ==============================================================================
mbed_official 489:119543c9f674 17 ##### How to use this driver #####
mbed_official 489:119543c9f674 18 ==============================================================================
mbed_official 489:119543c9f674 19 [..]
mbed_official 489:119543c9f674 20 The CEC HAL driver can be used as follows:
mbed_official 489:119543c9f674 21 (#) Declare a CEC_HandleTypeDef handle structure.
mbed_official 489:119543c9f674 22 (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API:
mbed_official 489:119543c9f674 23 (##) Enable the CEC interface clock.
mbed_official 489:119543c9f674 24 (##) Enable the clock for the CEC GPIOs.
mbed_official 489:119543c9f674 25 (##) Configure these CEC pins as alternate function pull-up.
mbed_official 489:119543c9f674 26 (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT()
mbed_official 489:119543c9f674 27 and HAL_CEC_Receive_IT() APIs):
mbed_official 489:119543c9f674 28 (##) Configure the CEC interrupt priority.
mbed_official 489:119543c9f674 29 (##) Enable the NVIC CEC IRQ handle.
mbed_official 489:119543c9f674 30 (##) The CEC interrupt is activated/deactivated by the HAL driver
mbed_official 489:119543c9f674 31
mbed_official 489:119543c9f674 32 (#) Program the Bit Timing Error Mode and the Bit Period Error Mode in the hcec Init structure.
mbed_official 489:119543c9f674 33
mbed_official 489:119543c9f674 34 (#) Initialize the CEC registers by calling the HAL_CEC_Init() API.
mbed_official 489:119543c9f674 35
mbed_official 489:119543c9f674 36 (#) This API (HAL_CEC_Init()) configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
mbed_official 489:119543c9f674 37 by calling the customized HAL_CEC_MspInit() API.
mbed_official 489:119543c9f674 38
mbed_official 489:119543c9f674 39 @endverbatim
mbed_official 489:119543c9f674 40 ******************************************************************************
mbed_official 489:119543c9f674 41 * @attention
mbed_official 489:119543c9f674 42 *
mbed_official 489:119543c9f674 43 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 489:119543c9f674 44 *
mbed_official 489:119543c9f674 45 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 489:119543c9f674 46 * are permitted provided that the following conditions are met:
mbed_official 489:119543c9f674 47 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 489:119543c9f674 48 * this list of conditions and the following disclaimer.
mbed_official 489:119543c9f674 49 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 489:119543c9f674 50 * this list of conditions and the following disclaimer in the documentation
mbed_official 489:119543c9f674 51 * and/or other materials provided with the distribution.
mbed_official 489:119543c9f674 52 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 489:119543c9f674 53 * may be used to endorse or promote products derived from this software
mbed_official 489:119543c9f674 54 * without specific prior written permission.
mbed_official 489:119543c9f674 55 *
mbed_official 489:119543c9f674 56 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 489:119543c9f674 57 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 489:119543c9f674 58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 489:119543c9f674 59 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 489:119543c9f674 60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 489:119543c9f674 61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 489:119543c9f674 62 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 489:119543c9f674 63 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 489:119543c9f674 64 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 489:119543c9f674 65 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 489:119543c9f674 66 *
mbed_official 489:119543c9f674 67 ******************************************************************************
mbed_official 489:119543c9f674 68 */
mbed_official 489:119543c9f674 69
mbed_official 489:119543c9f674 70 /* Includes ------------------------------------------------------------------*/
mbed_official 489:119543c9f674 71 #include "stm32f1xx_hal.h"
mbed_official 489:119543c9f674 72
mbed_official 489:119543c9f674 73 #ifdef HAL_CEC_MODULE_ENABLED
mbed_official 489:119543c9f674 74
mbed_official 489:119543c9f674 75 #if defined(STM32F100xB) || defined(STM32F100xE)
mbed_official 489:119543c9f674 76
mbed_official 489:119543c9f674 77 /** @addtogroup STM32F1xx_HAL_Driver
mbed_official 489:119543c9f674 78 * @{
mbed_official 489:119543c9f674 79 */
mbed_official 489:119543c9f674 80
mbed_official 489:119543c9f674 81 /** @defgroup CEC CEC
mbed_official 489:119543c9f674 82 * @brief HAL CEC module driver
mbed_official 489:119543c9f674 83 * @{
mbed_official 489:119543c9f674 84 */
mbed_official 489:119543c9f674 85
mbed_official 489:119543c9f674 86 /* Private typedef -----------------------------------------------------------*/
mbed_official 489:119543c9f674 87 /* Private define ------------------------------------------------------------*/
mbed_official 489:119543c9f674 88 /** @defgroup CEC_Private_Constants CEC Private Constants
mbed_official 489:119543c9f674 89 * @{
mbed_official 489:119543c9f674 90 */
mbed_official 489:119543c9f674 91 #define CEC_CFGR_FIELDS (CEC_CFGR_BTEM | CEC_CFGR_BPEM )
mbed_official 489:119543c9f674 92 #define CEC_FLAG_TRANSMIT_MASK (CEC_FLAG_TSOM|CEC_FLAG_TEOM|CEC_FLAG_TBTRF)
mbed_official 489:119543c9f674 93 #define CEC_FLAG_RECEIVE_MASK (CEC_FLAG_RSOM|CEC_FLAG_REOM|CEC_FLAG_RBTF)
mbed_official 489:119543c9f674 94 #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)
mbed_official 489:119543c9f674 95 #define CEC_RXXFERSIZE_INITIALIZE 0xFFFF /*!< Value used to initialise the RxXferSize of the handle */
mbed_official 489:119543c9f674 96 /**
mbed_official 489:119543c9f674 97 * @}
mbed_official 489:119543c9f674 98 */
mbed_official 489:119543c9f674 99
mbed_official 489:119543c9f674 100 /* Private macro -------------------------------------------------------------*/
mbed_official 489:119543c9f674 101 /* Private variables ---------------------------------------------------------*/
mbed_official 489:119543c9f674 102 /* Private function prototypes -----------------------------------------------*/
mbed_official 489:119543c9f674 103 /** @defgroup CEC_Private_Functions CEC Private Functions
mbed_official 489:119543c9f674 104 * @{
mbed_official 489:119543c9f674 105 */
mbed_official 489:119543c9f674 106 static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec);
mbed_official 489:119543c9f674 107 static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec);
mbed_official 489:119543c9f674 108 /**
mbed_official 489:119543c9f674 109 * @}
mbed_official 489:119543c9f674 110 */
mbed_official 489:119543c9f674 111
mbed_official 489:119543c9f674 112 /* Exported functions ---------------------------------------------------------*/
mbed_official 489:119543c9f674 113
mbed_official 489:119543c9f674 114 /** @defgroup CEC_Exported_Functions CEC Exported Functions
mbed_official 489:119543c9f674 115 * @{
mbed_official 489:119543c9f674 116 */
mbed_official 489:119543c9f674 117
mbed_official 489:119543c9f674 118 /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 489:119543c9f674 119 * @brief Initialization and Configuration functions
mbed_official 489:119543c9f674 120 *
mbed_official 489:119543c9f674 121 @verbatim
mbed_official 489:119543c9f674 122 ===============================================================================
mbed_official 489:119543c9f674 123 ##### Initialization and Configuration functions #####
mbed_official 489:119543c9f674 124 ===============================================================================
mbed_official 489:119543c9f674 125 [..]
mbed_official 489:119543c9f674 126 This subsection provides a set of functions allowing to initialize the CEC
mbed_official 489:119543c9f674 127 (+) The following parameters need to be configured:
mbed_official 489:119543c9f674 128 (++) TimingErrorFree
mbed_official 489:119543c9f674 129 (++) PeriodErrorFree
mbed_official 489:119543c9f674 130 (++) InitiatorAddress
mbed_official 489:119543c9f674 131
mbed_official 489:119543c9f674 132 @endverbatim
mbed_official 489:119543c9f674 133 * @{
mbed_official 489:119543c9f674 134 */
mbed_official 489:119543c9f674 135
mbed_official 489:119543c9f674 136 /**
mbed_official 489:119543c9f674 137 * @brief Initializes the CEC mode according to the specified
mbed_official 489:119543c9f674 138 * parameters in the CEC_InitTypeDef and creates the associated handle .
mbed_official 489:119543c9f674 139 * @param hcec: CEC handle
mbed_official 489:119543c9f674 140 * @retval HAL status
mbed_official 489:119543c9f674 141 */
mbed_official 489:119543c9f674 142 HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 143 {
mbed_official 489:119543c9f674 144 /* Check the CEC handle allocation */
mbed_official 489:119543c9f674 145 if(hcec == NULL)
mbed_official 489:119543c9f674 146 {
mbed_official 489:119543c9f674 147 return HAL_ERROR;
mbed_official 489:119543c9f674 148 }
mbed_official 489:119543c9f674 149
mbed_official 489:119543c9f674 150 /* Check the parameters */
mbed_official 489:119543c9f674 151 assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
mbed_official 489:119543c9f674 152 assert_param(IS_CEC_BIT_TIMING_ERROR_MODE(hcec->Init.TimingErrorFree));
mbed_official 489:119543c9f674 153 assert_param(IS_CEC_BIT_PERIOD_ERROR_MODE(hcec->Init.PeriodErrorFree));
mbed_official 489:119543c9f674 154 assert_param(IS_CEC_ADDRESS(hcec->Init.InitiatorAddress));
mbed_official 489:119543c9f674 155
mbed_official 489:119543c9f674 156 if(hcec->State == HAL_CEC_STATE_RESET)
mbed_official 489:119543c9f674 157 {
mbed_official 489:119543c9f674 158 /* Allocate lock resource and initialize it */
mbed_official 489:119543c9f674 159 hcec-> Lock = HAL_UNLOCKED;
mbed_official 489:119543c9f674 160 /* Init the low level hardware : GPIO, CLOCK */
mbed_official 489:119543c9f674 161 HAL_CEC_MspInit(hcec);
mbed_official 489:119543c9f674 162 }
mbed_official 489:119543c9f674 163
mbed_official 489:119543c9f674 164 hcec->State = HAL_CEC_STATE_BUSY;
mbed_official 489:119543c9f674 165
mbed_official 489:119543c9f674 166 /* Disable the Peripheral */
mbed_official 489:119543c9f674 167 __HAL_CEC_DISABLE(hcec);
mbed_official 489:119543c9f674 168
mbed_official 489:119543c9f674 169 /* Write to CEC Control Register */
mbed_official 489:119543c9f674 170 MODIFY_REG(hcec->Instance->CFGR, CEC_CFGR_FIELDS, hcec->Init.TimingErrorFree|hcec->Init.PeriodErrorFree);
mbed_official 489:119543c9f674 171
mbed_official 489:119543c9f674 172 /* Write to CEC Own Address Register */
mbed_official 489:119543c9f674 173 MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.InitiatorAddress);
mbed_official 489:119543c9f674 174
mbed_official 489:119543c9f674 175 /* Configure the prescaler to generate the required 50 microseconds time base.*/
mbed_official 489:119543c9f674 176 MODIFY_REG(hcec->Instance->PRES, CEC_PRES_PRES, 50*(HAL_RCC_GetPCLK1Freq()/1000000)-1);
mbed_official 489:119543c9f674 177
mbed_official 489:119543c9f674 178 /* Enable the Peripheral */
mbed_official 489:119543c9f674 179 __HAL_CEC_ENABLE(hcec);
mbed_official 489:119543c9f674 180
mbed_official 489:119543c9f674 181 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 182
mbed_official 489:119543c9f674 183 return HAL_OK;
mbed_official 489:119543c9f674 184 }
mbed_official 489:119543c9f674 185
mbed_official 489:119543c9f674 186
mbed_official 489:119543c9f674 187
mbed_official 489:119543c9f674 188 /**
mbed_official 489:119543c9f674 189 * @brief DeInitializes the CEC peripheral
mbed_official 489:119543c9f674 190 * @param hcec: CEC handle
mbed_official 489:119543c9f674 191 * @retval HAL status
mbed_official 489:119543c9f674 192 */
mbed_official 489:119543c9f674 193 HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 194 {
mbed_official 489:119543c9f674 195 /* Check the CEC handle allocation */
mbed_official 489:119543c9f674 196 if(hcec == NULL)
mbed_official 489:119543c9f674 197 {
mbed_official 489:119543c9f674 198 return HAL_ERROR;
mbed_official 489:119543c9f674 199 }
mbed_official 489:119543c9f674 200
mbed_official 489:119543c9f674 201 /* Check the parameters */
mbed_official 489:119543c9f674 202 assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
mbed_official 489:119543c9f674 203
mbed_official 489:119543c9f674 204 hcec->State = HAL_CEC_STATE_BUSY;
mbed_official 489:119543c9f674 205
mbed_official 489:119543c9f674 206 /* Set peripheral to reset state */
mbed_official 489:119543c9f674 207 hcec->Instance->CFGR = 0x0;
mbed_official 489:119543c9f674 208 hcec->Instance->OAR = 0x0;
mbed_official 489:119543c9f674 209 hcec->Instance->PRES = 0x0;
mbed_official 489:119543c9f674 210 hcec->Instance->CFGR = 0x0;
mbed_official 489:119543c9f674 211 hcec->Instance->ESR = 0x0;
mbed_official 489:119543c9f674 212 hcec->Instance->CSR = 0x0;
mbed_official 489:119543c9f674 213 hcec->Instance->TXD = 0x0;
mbed_official 489:119543c9f674 214 hcec->Instance->RXD = 0x0;
mbed_official 489:119543c9f674 215
mbed_official 489:119543c9f674 216 /* Disable the Peripheral */
mbed_official 489:119543c9f674 217 __HAL_CEC_DISABLE(hcec);
mbed_official 489:119543c9f674 218
mbed_official 489:119543c9f674 219 /* DeInit the low level hardware */
mbed_official 489:119543c9f674 220 HAL_CEC_MspDeInit(hcec);
mbed_official 489:119543c9f674 221
mbed_official 489:119543c9f674 222 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 489:119543c9f674 223 hcec->State = HAL_CEC_STATE_RESET;
mbed_official 489:119543c9f674 224
mbed_official 489:119543c9f674 225 /* Process Unlock */
mbed_official 489:119543c9f674 226 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 227
mbed_official 489:119543c9f674 228 return HAL_OK;
mbed_official 489:119543c9f674 229 }
mbed_official 489:119543c9f674 230
mbed_official 489:119543c9f674 231 /**
mbed_official 489:119543c9f674 232 * @brief CEC MSP Init
mbed_official 489:119543c9f674 233 * @param hcec: CEC handle
mbed_official 489:119543c9f674 234 * @retval None
mbed_official 489:119543c9f674 235 */
mbed_official 489:119543c9f674 236 __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 237 {
mbed_official 489:119543c9f674 238 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 239 the HAL_CEC_MspInit can be implemented in the user file
mbed_official 489:119543c9f674 240 */
mbed_official 489:119543c9f674 241 }
mbed_official 489:119543c9f674 242
mbed_official 489:119543c9f674 243 /**
mbed_official 489:119543c9f674 244 * @brief CEC MSP DeInit
mbed_official 489:119543c9f674 245 * @param hcec: CEC handle
mbed_official 489:119543c9f674 246 * @retval None
mbed_official 489:119543c9f674 247 */
mbed_official 489:119543c9f674 248 __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 249 {
mbed_official 489:119543c9f674 250 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 251 the HAL_CEC_MspDeInit can be implemented in the user file
mbed_official 489:119543c9f674 252 */
mbed_official 489:119543c9f674 253 }
mbed_official 489:119543c9f674 254
mbed_official 489:119543c9f674 255 /**
mbed_official 489:119543c9f674 256 * @}
mbed_official 489:119543c9f674 257 */
mbed_official 489:119543c9f674 258
mbed_official 489:119543c9f674 259 /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions
mbed_official 489:119543c9f674 260 * @brief CEC Transmit/Receive functions
mbed_official 489:119543c9f674 261 *
mbed_official 489:119543c9f674 262 @verbatim
mbed_official 489:119543c9f674 263 ===============================================================================
mbed_official 489:119543c9f674 264 ##### IO operation functions #####
mbed_official 489:119543c9f674 265 ===============================================================================
mbed_official 489:119543c9f674 266 [..]
mbed_official 489:119543c9f674 267 This subsection provides a set of functions allowing to manage the CEC data transfers.
mbed_official 489:119543c9f674 268
mbed_official 489:119543c9f674 269 (#) There are two modes of transfer:
mbed_official 489:119543c9f674 270 (##) Blocking mode: The communication is performed in polling mode.
mbed_official 489:119543c9f674 271 The HAL status of all data processing is returned by the same function
mbed_official 489:119543c9f674 272 after finishing transfer.
mbed_official 489:119543c9f674 273 (##) No-Blocking mode: The communication is performed using Interrupts.
mbed_official 489:119543c9f674 274 These API's return the HAL status.
mbed_official 489:119543c9f674 275 The end of the data processing will be indicated through the
mbed_official 489:119543c9f674 276 dedicated CEC IRQ when using Interrupt mode.
mbed_official 489:119543c9f674 277 The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks
mbed_official 489:119543c9f674 278 will be executed respectivelly at the end of the Transmit or Receive process.
mbed_official 489:119543c9f674 279 The HAL_CEC_ErrorCallback()user callback will be executed when a communication
mbed_official 489:119543c9f674 280 error is detected
mbed_official 489:119543c9f674 281 (#) Blocking mode API's are :
mbed_official 489:119543c9f674 282 (##) HAL_CEC_Transmit()
mbed_official 489:119543c9f674 283 (##) HAL_CEC_Receive()
mbed_official 489:119543c9f674 284 (#) Non-Blocking mode API's with Interrupt are :
mbed_official 489:119543c9f674 285 (##) HAL_CEC_Transmit_IT()
mbed_official 489:119543c9f674 286 (##) HAL_CEC_Receive_IT()
mbed_official 489:119543c9f674 287 (##) HAL_CEC_IRQHandler()
mbed_official 489:119543c9f674 288 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
mbed_official 489:119543c9f674 289 (##) HAL_CEC_TxCpltCallback()
mbed_official 489:119543c9f674 290 (##) HAL_CEC_RxCpltCallback()
mbed_official 489:119543c9f674 291 (##) HAL_CEC_ErrorCallback()
mbed_official 489:119543c9f674 292
mbed_official 489:119543c9f674 293 @endverbatim
mbed_official 489:119543c9f674 294 * @{
mbed_official 489:119543c9f674 295 */
mbed_official 489:119543c9f674 296
mbed_official 489:119543c9f674 297 /**
mbed_official 489:119543c9f674 298 * @brief Send data in blocking mode
mbed_official 489:119543c9f674 299 * @param hcec: CEC handle
mbed_official 489:119543c9f674 300 * @param DestinationAddress: destination logical address
mbed_official 489:119543c9f674 301 * @param pData: pointer to input byte data buffer
mbed_official 489:119543c9f674 302 * @param Size: amount of data to be sent in bytes (without counting the header).
mbed_official 489:119543c9f674 303 * 0 means only the header is sent (ping operation).
mbed_official 489:119543c9f674 304 * Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
mbed_official 489:119543c9f674 305 * @param Timeout: Timeout duration.
mbed_official 489:119543c9f674 306 * @retval HAL status
mbed_official 489:119543c9f674 307 */
mbed_official 489:119543c9f674 308 HAL_StatusTypeDef HAL_CEC_Transmit(CEC_HandleTypeDef *hcec, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size, uint32_t Timeout)
mbed_official 489:119543c9f674 309 {
mbed_official 489:119543c9f674 310 uint8_t temp = 0;
mbed_official 489:119543c9f674 311 uint32_t tickstart = 0;
mbed_official 489:119543c9f674 312
mbed_official 489:119543c9f674 313 /* If the IP is ready */
mbed_official 489:119543c9f674 314 if((hcec->State == HAL_CEC_STATE_READY)
mbed_official 489:119543c9f674 315 && (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) == RESET))
mbed_official 489:119543c9f674 316 {
mbed_official 489:119543c9f674 317 /* Basic check on pData pointer */
mbed_official 489:119543c9f674 318 if(((pData == NULL) && (Size > 0)) || (! IS_CEC_MSGSIZE(Size)))
mbed_official 489:119543c9f674 319 {
mbed_official 489:119543c9f674 320 return HAL_ERROR;
mbed_official 489:119543c9f674 321 }
mbed_official 489:119543c9f674 322
mbed_official 489:119543c9f674 323 assert_param(IS_CEC_ADDRESS(DestinationAddress));
mbed_official 489:119543c9f674 324
mbed_official 489:119543c9f674 325 /* Process Locked */
mbed_official 489:119543c9f674 326 __HAL_LOCK(hcec);
mbed_official 489:119543c9f674 327
mbed_official 489:119543c9f674 328 /* Enter the transmit mode */
mbed_official 489:119543c9f674 329 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 489:119543c9f674 330 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 489:119543c9f674 331
mbed_official 489:119543c9f674 332 /* Initialize the number of bytes to send,
mbed_official 489:119543c9f674 333 * 0 means only one header is sent (ping operation) */
mbed_official 489:119543c9f674 334 hcec->TxXferCount = Size;
mbed_official 489:119543c9f674 335
mbed_official 489:119543c9f674 336 /* Send header block */
mbed_official 489:119543c9f674 337 temp = (uint8_t)((uint32_t)(hcec->Init.InitiatorAddress) << CEC_INITIATOR_LSB_POS) | DestinationAddress;
mbed_official 489:119543c9f674 338 hcec->Instance->TXD = temp;
mbed_official 489:119543c9f674 339
mbed_official 489:119543c9f674 340 /* In case no data to be sent, sender is only pinging the system */
mbed_official 489:119543c9f674 341 if (Size != 0)
mbed_official 489:119543c9f674 342 {
mbed_official 489:119543c9f674 343 /* Set TX Start of Message (TXSOM) bit */
mbed_official 489:119543c9f674 344 hcec->Instance->CSR = CEC_FLAG_TSOM;
mbed_official 489:119543c9f674 345 }
mbed_official 489:119543c9f674 346 else
mbed_official 489:119543c9f674 347 {
mbed_official 489:119543c9f674 348 /* Send a ping command */
mbed_official 489:119543c9f674 349 hcec->Instance->CSR = CEC_FLAG_TEOM|CEC_FLAG_TSOM;
mbed_official 489:119543c9f674 350 }
mbed_official 489:119543c9f674 351
mbed_official 489:119543c9f674 352 /* Polling TBTRF bit with timeout handling*/
mbed_official 489:119543c9f674 353 while (hcec->TxXferCount > 0)
mbed_official 489:119543c9f674 354 {
mbed_official 489:119543c9f674 355 /* Decreasing of the number of remaining data to receive */
mbed_official 489:119543c9f674 356 hcec->TxXferCount--;
mbed_official 489:119543c9f674 357
mbed_official 489:119543c9f674 358 /* Timeout handling */
mbed_official 489:119543c9f674 359 tickstart = HAL_GetTick();
mbed_official 489:119543c9f674 360
mbed_official 489:119543c9f674 361 /* Waiting for the next data transmission */
mbed_official 489:119543c9f674 362 while(HAL_IS_BIT_CLR(hcec->Instance->CSR, CEC_FLAG_TBTRF))
mbed_official 489:119543c9f674 363 {
mbed_official 489:119543c9f674 364 /* Timeout handling */
mbed_official 489:119543c9f674 365 if(Timeout != HAL_MAX_DELAY)
mbed_official 489:119543c9f674 366 {
mbed_official 489:119543c9f674 367 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 489:119543c9f674 368 {
mbed_official 489:119543c9f674 369 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 370 /* Process Unlocked */
mbed_official 489:119543c9f674 371 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 372 return HAL_TIMEOUT;
mbed_official 489:119543c9f674 373 }
mbed_official 489:119543c9f674 374 }
mbed_official 489:119543c9f674 375
mbed_official 489:119543c9f674 376 /* Check if an error occured */
mbed_official 489:119543c9f674 377 if(HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_TERR) || HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_RERR))
mbed_official 489:119543c9f674 378 {
mbed_official 489:119543c9f674 379 /* Copy ESR for error handling purposes */
mbed_official 489:119543c9f674 380 hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR);
mbed_official 489:119543c9f674 381
mbed_official 489:119543c9f674 382 /* Acknowledgement of the error */
mbed_official 489:119543c9f674 383 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR);
mbed_official 489:119543c9f674 384 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR);
mbed_official 489:119543c9f674 385
mbed_official 489:119543c9f674 386 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 387 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 388 return HAL_ERROR;
mbed_official 489:119543c9f674 389 }
mbed_official 489:119543c9f674 390 }
mbed_official 489:119543c9f674 391
mbed_official 489:119543c9f674 392 /* Write the next data to TX buffer */
mbed_official 489:119543c9f674 393 hcec->Instance->TXD = *pData++;
mbed_official 489:119543c9f674 394
mbed_official 489:119543c9f674 395 /* If this is the last byte of the ongoing transmission */
mbed_official 489:119543c9f674 396 if (hcec->TxXferCount == 0)
mbed_official 489:119543c9f674 397 {
mbed_official 489:119543c9f674 398 /* Acknowledge byte request and signal end of message */
mbed_official 489:119543c9f674 399 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM);
mbed_official 489:119543c9f674 400 }
mbed_official 489:119543c9f674 401 else
mbed_official 489:119543c9f674 402 {
mbed_official 489:119543c9f674 403 /* Acknowledge byte request by writing 0x00 */
mbed_official 489:119543c9f674 404 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00);
mbed_official 489:119543c9f674 405 }
mbed_official 489:119543c9f674 406 }
mbed_official 489:119543c9f674 407
mbed_official 489:119543c9f674 408 /* Timeout handling */
mbed_official 489:119543c9f674 409 tickstart = HAL_GetTick();
mbed_official 489:119543c9f674 410
mbed_official 489:119543c9f674 411 /* Wait for message transmission completion (TBTRF is set) */
mbed_official 489:119543c9f674 412 while (HAL_IS_BIT_CLR(hcec->Instance->CSR, CEC_FLAG_TBTRF))
mbed_official 489:119543c9f674 413 {
mbed_official 489:119543c9f674 414 /* Timeout handling */
mbed_official 489:119543c9f674 415 if(Timeout != HAL_MAX_DELAY)
mbed_official 489:119543c9f674 416 {
mbed_official 489:119543c9f674 417 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 489:119543c9f674 418 {
mbed_official 489:119543c9f674 419 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 420 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 421 return HAL_TIMEOUT;
mbed_official 489:119543c9f674 422 }
mbed_official 489:119543c9f674 423 }
mbed_official 489:119543c9f674 424
mbed_official 489:119543c9f674 425 /* Check of error during transmission of the last byte */
mbed_official 489:119543c9f674 426 if(HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_TERR) || HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_RERR))
mbed_official 489:119543c9f674 427 {
mbed_official 489:119543c9f674 428 /* Copy ESR for error handling purposes */
mbed_official 489:119543c9f674 429 hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR);
mbed_official 489:119543c9f674 430
mbed_official 489:119543c9f674 431 /* Acknowledgement of the error */
mbed_official 489:119543c9f674 432 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR);
mbed_official 489:119543c9f674 433 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR);
mbed_official 489:119543c9f674 434
mbed_official 489:119543c9f674 435 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 436 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 437 return HAL_ERROR;
mbed_official 489:119543c9f674 438 }
mbed_official 489:119543c9f674 439 }
mbed_official 489:119543c9f674 440
mbed_official 489:119543c9f674 441 /* Check of error after the last byte transmission */
mbed_official 489:119543c9f674 442 if(HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_TERR) || HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_RERR))
mbed_official 489:119543c9f674 443 {
mbed_official 489:119543c9f674 444 /* Copy ESR for error handling purposes */
mbed_official 489:119543c9f674 445 hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR);
mbed_official 489:119543c9f674 446
mbed_official 489:119543c9f674 447 /* Acknowledgement of the error */
mbed_official 489:119543c9f674 448 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR);
mbed_official 489:119543c9f674 449 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR);
mbed_official 489:119543c9f674 450
mbed_official 489:119543c9f674 451 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 452 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 453 return HAL_ERROR;
mbed_official 489:119543c9f674 454 }
mbed_official 489:119543c9f674 455
mbed_official 489:119543c9f674 456 /* Acknowledge successful completion by writing 0x00 */
mbed_official 489:119543c9f674 457 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00);
mbed_official 489:119543c9f674 458
mbed_official 489:119543c9f674 459 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 460 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 461
mbed_official 489:119543c9f674 462 return HAL_OK;
mbed_official 489:119543c9f674 463 }
mbed_official 489:119543c9f674 464 else
mbed_official 489:119543c9f674 465 {
mbed_official 489:119543c9f674 466 return HAL_BUSY;
mbed_official 489:119543c9f674 467 }
mbed_official 489:119543c9f674 468 }
mbed_official 489:119543c9f674 469
mbed_official 489:119543c9f674 470 /**
mbed_official 489:119543c9f674 471 * @brief Receive data in blocking mode.
mbed_official 489:119543c9f674 472 * @param hcec: CEC handle
mbed_official 489:119543c9f674 473 * @param pData: pointer to received data buffer.
mbed_official 489:119543c9f674 474 * @param Timeout: Timeout duration.
mbed_official 489:119543c9f674 475 * @note The received data size is not known beforehand, the latter is known
mbed_official 489:119543c9f674 476 * when the reception is complete and is stored in hcec->RxXferSize.
mbed_official 489:119543c9f674 477 * hcec->RxXferSize is the sum of opcodes + operands (0 to 14 operands max).
mbed_official 489:119543c9f674 478 * If only a header is received, hcec->RxXferSize = 0
mbed_official 489:119543c9f674 479 * @retval HAL status
mbed_official 489:119543c9f674 480 */
mbed_official 489:119543c9f674 481 HAL_StatusTypeDef HAL_CEC_Receive(CEC_HandleTypeDef *hcec, uint8_t *pData, uint32_t Timeout)
mbed_official 489:119543c9f674 482 {
mbed_official 489:119543c9f674 483 uint32_t temp = 0;
mbed_official 489:119543c9f674 484 uint32_t tickstart = 0;
mbed_official 489:119543c9f674 485
mbed_official 489:119543c9f674 486 if(hcec->State == HAL_CEC_STATE_READY)
mbed_official 489:119543c9f674 487 {
mbed_official 489:119543c9f674 488 if(pData == NULL)
mbed_official 489:119543c9f674 489 {
mbed_official 489:119543c9f674 490 return HAL_ERROR;
mbed_official 489:119543c9f674 491 }
mbed_official 489:119543c9f674 492
mbed_official 489:119543c9f674 493 /* When a ping is received, RxXferSize is 0*/
mbed_official 489:119543c9f674 494 /* When a message is received, RxXferSize contains the number of received bytes */
mbed_official 489:119543c9f674 495 hcec->RxXferSize = CEC_RXXFERSIZE_INITIALIZE;
mbed_official 489:119543c9f674 496
mbed_official 489:119543c9f674 497 /* Process Locked */
mbed_official 489:119543c9f674 498 __HAL_LOCK(hcec);
mbed_official 489:119543c9f674 499
mbed_official 489:119543c9f674 500 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 489:119543c9f674 501
mbed_official 489:119543c9f674 502 /* Continue the reception until the End Of Message is received (CEC_FLAG_REOM) */
mbed_official 489:119543c9f674 503 do
mbed_official 489:119543c9f674 504 {
mbed_official 489:119543c9f674 505 /* Timeout handling */
mbed_official 489:119543c9f674 506 tickstart = HAL_GetTick();
mbed_official 489:119543c9f674 507
mbed_official 489:119543c9f674 508 /* Wait for next byte to be received */
mbed_official 489:119543c9f674 509 while (HAL_IS_BIT_CLR(hcec->Instance->CSR, CEC_FLAG_RBTF))
mbed_official 489:119543c9f674 510 {
mbed_official 489:119543c9f674 511 /* Timeout handling */
mbed_official 489:119543c9f674 512 if(Timeout != HAL_MAX_DELAY)
mbed_official 489:119543c9f674 513 {
mbed_official 489:119543c9f674 514 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 489:119543c9f674 515 {
mbed_official 489:119543c9f674 516 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 517 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 518 return HAL_TIMEOUT;
mbed_official 489:119543c9f674 519 }
mbed_official 489:119543c9f674 520 }
mbed_official 489:119543c9f674 521
mbed_official 489:119543c9f674 522 /* Check if an error occured during the reception */
mbed_official 489:119543c9f674 523 if(HAL_IS_BIT_SET(hcec->Instance->CSR, CEC_FLAG_RERR))
mbed_official 489:119543c9f674 524 {
mbed_official 489:119543c9f674 525 /* Copy ESR for error handling purposes */
mbed_official 489:119543c9f674 526 hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR);
mbed_official 489:119543c9f674 527
mbed_official 489:119543c9f674 528 /* Acknowledgement of the error */
mbed_official 489:119543c9f674 529 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR);
mbed_official 489:119543c9f674 530
mbed_official 489:119543c9f674 531 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 532 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 533 return HAL_ERROR;
mbed_official 489:119543c9f674 534 }
mbed_official 489:119543c9f674 535 }
mbed_official 489:119543c9f674 536
mbed_official 489:119543c9f674 537 /* Keep the value of CSR register as the register is cleared during reception process */
mbed_official 489:119543c9f674 538 temp = hcec->Instance->CSR;
mbed_official 489:119543c9f674 539
mbed_official 489:119543c9f674 540 /* Read received data */
mbed_official 489:119543c9f674 541 *pData++ = hcec->Instance->RXD;
mbed_official 489:119543c9f674 542
mbed_official 489:119543c9f674 543 /* Acknowledge received byte by writing 0x00 */
mbed_official 489:119543c9f674 544 CLEAR_BIT(hcec->Instance->CSR, CEC_FLAG_RECEIVE_MASK);
mbed_official 489:119543c9f674 545
mbed_official 489:119543c9f674 546 /* Increment the number of received data */
mbed_official 489:119543c9f674 547 if(hcec->RxXferSize == CEC_RXXFERSIZE_INITIALIZE)
mbed_official 489:119543c9f674 548 {
mbed_official 489:119543c9f674 549 hcec->RxXferSize = 0;
mbed_official 489:119543c9f674 550 }
mbed_official 489:119543c9f674 551 else
mbed_official 489:119543c9f674 552 {
mbed_official 489:119543c9f674 553 hcec->RxXferSize++;
mbed_official 489:119543c9f674 554 }
mbed_official 489:119543c9f674 555
mbed_official 489:119543c9f674 556 }while (HAL_IS_BIT_CLR(temp, CEC_FLAG_REOM));
mbed_official 489:119543c9f674 557
mbed_official 489:119543c9f674 558 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 559 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 560
mbed_official 489:119543c9f674 561 if(IS_CEC_MSGSIZE(hcec->RxXferSize))
mbed_official 489:119543c9f674 562 {
mbed_official 489:119543c9f674 563 return HAL_OK;
mbed_official 489:119543c9f674 564 }
mbed_official 489:119543c9f674 565 else
mbed_official 489:119543c9f674 566 {
mbed_official 489:119543c9f674 567 return HAL_ERROR;
mbed_official 489:119543c9f674 568 }
mbed_official 489:119543c9f674 569 }
mbed_official 489:119543c9f674 570 else
mbed_official 489:119543c9f674 571 {
mbed_official 489:119543c9f674 572 return HAL_BUSY;
mbed_official 489:119543c9f674 573 }
mbed_official 489:119543c9f674 574 }
mbed_official 489:119543c9f674 575
mbed_official 489:119543c9f674 576
mbed_official 489:119543c9f674 577 /**
mbed_official 489:119543c9f674 578 * @brief Send data in interrupt mode
mbed_official 489:119543c9f674 579 * @param hcec: CEC handle
mbed_official 489:119543c9f674 580 * @param DestinationAddress: destination logical address
mbed_official 489:119543c9f674 581 * @param pData: pointer to input byte data buffer
mbed_official 489:119543c9f674 582 * @param Size: amount of data to be sent in bytes (without counting the header).
mbed_official 489:119543c9f674 583 * 0 means only the header is sent (ping operation).
mbed_official 489:119543c9f674 584 * Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
mbed_official 489:119543c9f674 585 * @retval HAL status
mbed_official 489:119543c9f674 586 */
mbed_official 489:119543c9f674 587 HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size)
mbed_official 489:119543c9f674 588 {
mbed_official 489:119543c9f674 589 uint8_t temp = 0;
mbed_official 489:119543c9f674 590 uint32_t tmp_state = 0;
mbed_official 489:119543c9f674 591
mbed_official 489:119543c9f674 592 tmp_state = hcec->State;
mbed_official 489:119543c9f674 593 if(((tmp_state == HAL_CEC_STATE_READY) || (tmp_state == HAL_CEC_STATE_BUSY_RX))
mbed_official 489:119543c9f674 594 && (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) == RESET))
mbed_official 489:119543c9f674 595 {
mbed_official 489:119543c9f674 596
mbed_official 489:119543c9f674 597 /* Basic check on pData pointer */
mbed_official 489:119543c9f674 598 if(((pData == NULL) && (Size > 0)) || (! IS_CEC_MSGSIZE(Size)))
mbed_official 489:119543c9f674 599 {
mbed_official 489:119543c9f674 600 return HAL_ERROR;
mbed_official 489:119543c9f674 601 }
mbed_official 489:119543c9f674 602
mbed_official 489:119543c9f674 603 assert_param(IS_CEC_ADDRESS(DestinationAddress));
mbed_official 489:119543c9f674 604
mbed_official 489:119543c9f674 605 /* Process Locked */
mbed_official 489:119543c9f674 606 __HAL_LOCK(hcec);
mbed_official 489:119543c9f674 607 hcec->pTxBuffPtr = pData;
mbed_official 489:119543c9f674 608
mbed_official 489:119543c9f674 609 /* Check if a receive process is ongoing or not */
mbed_official 489:119543c9f674 610 if(hcec->State == HAL_CEC_STATE_BUSY_RX)
mbed_official 489:119543c9f674 611 {
mbed_official 489:119543c9f674 612 hcec->State = HAL_CEC_STATE_BUSY_TX_RX;
mbed_official 489:119543c9f674 613
mbed_official 489:119543c9f674 614 /* Interrupt are not enabled here because they are already enabled in the Reception process */
mbed_official 489:119543c9f674 615 }
mbed_official 489:119543c9f674 616 else
mbed_official 489:119543c9f674 617 {
mbed_official 489:119543c9f674 618 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 489:119543c9f674 619
mbed_official 489:119543c9f674 620 /* Enable the CEC interrupt */
mbed_official 489:119543c9f674 621 __HAL_CEC_ENABLE_IT(hcec, CEC_IT_IE);
mbed_official 489:119543c9f674 622 }
mbed_official 489:119543c9f674 623
mbed_official 489:119543c9f674 624 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 489:119543c9f674 625
mbed_official 489:119543c9f674 626 /* initialize the number of bytes to send,
mbed_official 489:119543c9f674 627 * 0 means only one header is sent (ping operation) */
mbed_official 489:119543c9f674 628 hcec->TxXferCount = Size;
mbed_official 489:119543c9f674 629
mbed_official 489:119543c9f674 630 /* send header block */
mbed_official 489:119543c9f674 631 temp = (uint8_t)((uint32_t)(hcec->Init.InitiatorAddress) << CEC_INITIATOR_LSB_POS) | DestinationAddress;
mbed_official 489:119543c9f674 632 hcec->Instance->TXD = temp;
mbed_official 489:119543c9f674 633
mbed_official 489:119543c9f674 634 /* Process Unlocked */
mbed_official 489:119543c9f674 635 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 636
mbed_official 489:119543c9f674 637 /* case no data to be sent, sender is only pinging the system */
mbed_official 489:119543c9f674 638 if (Size != 0)
mbed_official 489:119543c9f674 639 {
mbed_official 489:119543c9f674 640 /* Set TX Start of Message (TXSOM) bit */
mbed_official 489:119543c9f674 641 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TSOM);
mbed_official 489:119543c9f674 642 }
mbed_official 489:119543c9f674 643 else
mbed_official 489:119543c9f674 644 {
mbed_official 489:119543c9f674 645 /* Send a ping command */
mbed_official 489:119543c9f674 646 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM|CEC_FLAG_TSOM);
mbed_official 489:119543c9f674 647 }
mbed_official 489:119543c9f674 648 return HAL_OK;
mbed_official 489:119543c9f674 649 }
mbed_official 489:119543c9f674 650 else
mbed_official 489:119543c9f674 651 {
mbed_official 489:119543c9f674 652 return HAL_BUSY;
mbed_official 489:119543c9f674 653 }
mbed_official 489:119543c9f674 654 }
mbed_official 489:119543c9f674 655
mbed_official 489:119543c9f674 656
mbed_official 489:119543c9f674 657 /**
mbed_official 489:119543c9f674 658 * @brief Receive data in interrupt mode.
mbed_official 489:119543c9f674 659 * @param hcec: CEC handle
mbed_official 489:119543c9f674 660 * @param pData: pointer to received data buffer.
mbed_official 489:119543c9f674 661 * @note The received data size is not known beforehand, the latter is known
mbed_official 489:119543c9f674 662 * when the reception is complete and is stored in hcec->RxXferSize.
mbed_official 489:119543c9f674 663 * hcec->RxXferSize is the sum of opcodes + operands (0 to 14 operands max).
mbed_official 489:119543c9f674 664 * If only a header is received, hcec->RxXferSize = 0
mbed_official 489:119543c9f674 665 * @retval HAL status
mbed_official 489:119543c9f674 666 */
mbed_official 489:119543c9f674 667 HAL_StatusTypeDef HAL_CEC_Receive_IT(CEC_HandleTypeDef *hcec, uint8_t *pData)
mbed_official 489:119543c9f674 668 {
mbed_official 489:119543c9f674 669 uint32_t tmp_state = 0;
mbed_official 489:119543c9f674 670 tmp_state = hcec->State;
mbed_official 489:119543c9f674 671 if((tmp_state == HAL_CEC_STATE_READY) || (tmp_state == HAL_CEC_STATE_BUSY_TX))
mbed_official 489:119543c9f674 672 {
mbed_official 489:119543c9f674 673 if(pData == NULL)
mbed_official 489:119543c9f674 674 {
mbed_official 489:119543c9f674 675 return HAL_ERROR;
mbed_official 489:119543c9f674 676 }
mbed_official 489:119543c9f674 677
mbed_official 489:119543c9f674 678 /* When a ping is received, RxXferSize is 0 */
mbed_official 489:119543c9f674 679 /* When a message is received, RxXferSize contains the number of received bytes */
mbed_official 489:119543c9f674 680 hcec->RxXferSize = CEC_RXXFERSIZE_INITIALIZE;
mbed_official 489:119543c9f674 681
mbed_official 489:119543c9f674 682 /* Process Locked */
mbed_official 489:119543c9f674 683 __HAL_LOCK(hcec);
mbed_official 489:119543c9f674 684
mbed_official 489:119543c9f674 685 hcec->pRxBuffPtr = pData;
mbed_official 489:119543c9f674 686 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 489:119543c9f674 687
mbed_official 489:119543c9f674 688 /* Process Unlocked */
mbed_official 489:119543c9f674 689 __HAL_UNLOCK(hcec);
mbed_official 489:119543c9f674 690
mbed_official 489:119543c9f674 691 /* Check if a transmit process is ongoing or not */
mbed_official 489:119543c9f674 692 if(hcec->State == HAL_CEC_STATE_BUSY_TX)
mbed_official 489:119543c9f674 693 {
mbed_official 489:119543c9f674 694 hcec->State = HAL_CEC_STATE_BUSY_TX_RX;
mbed_official 489:119543c9f674 695 }
mbed_official 489:119543c9f674 696 else
mbed_official 489:119543c9f674 697 {
mbed_official 489:119543c9f674 698 hcec->State = HAL_CEC_STATE_BUSY_RX;
mbed_official 489:119543c9f674 699
mbed_official 489:119543c9f674 700 /* Enable CEC interrupt */
mbed_official 489:119543c9f674 701 __HAL_CEC_ENABLE_IT(hcec, CEC_IT_IE);
mbed_official 489:119543c9f674 702 }
mbed_official 489:119543c9f674 703
mbed_official 489:119543c9f674 704 return HAL_OK;
mbed_official 489:119543c9f674 705 }
mbed_official 489:119543c9f674 706 else
mbed_official 489:119543c9f674 707 {
mbed_official 489:119543c9f674 708 return HAL_BUSY;
mbed_official 489:119543c9f674 709 }
mbed_official 489:119543c9f674 710 }
mbed_official 489:119543c9f674 711
mbed_official 489:119543c9f674 712 /**
mbed_official 489:119543c9f674 713 * @brief Get size of the received frame.
mbed_official 489:119543c9f674 714 * @param hcec: CEC handle
mbed_official 489:119543c9f674 715 * @retval Frame size
mbed_official 489:119543c9f674 716 */
mbed_official 489:119543c9f674 717 uint32_t HAL_CEC_GetReceivedFrameSize(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 718 {
mbed_official 489:119543c9f674 719 return hcec->RxXferSize;
mbed_official 489:119543c9f674 720 }
mbed_official 489:119543c9f674 721
mbed_official 489:119543c9f674 722 /**
mbed_official 489:119543c9f674 723 * @brief This function handles CEC interrupt requests.
mbed_official 489:119543c9f674 724 * @param hcec: CEC handle
mbed_official 489:119543c9f674 725 * @retval None
mbed_official 489:119543c9f674 726 */
mbed_official 489:119543c9f674 727 void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 728 {
mbed_official 489:119543c9f674 729 /* Save error status register for further error handling purposes */
mbed_official 489:119543c9f674 730 hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR);
mbed_official 489:119543c9f674 731
mbed_official 489:119543c9f674 732 /* Transmit error */
mbed_official 489:119543c9f674 733 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TERR) != RESET))
mbed_official 489:119543c9f674 734 {
mbed_official 489:119543c9f674 735 /* Acknowledgement of the error */
mbed_official 489:119543c9f674 736 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR);
mbed_official 489:119543c9f674 737
mbed_official 489:119543c9f674 738 /* Check if a receive process is ongoing or not */
mbed_official 489:119543c9f674 739 if(hcec->State == HAL_CEC_STATE_BUSY_TX_RX)
mbed_official 489:119543c9f674 740 {
mbed_official 489:119543c9f674 741 /* Interrupts are not disabled due to reception still ongoing */
mbed_official 489:119543c9f674 742
mbed_official 489:119543c9f674 743 hcec->State = HAL_CEC_STATE_BUSY_RX;
mbed_official 489:119543c9f674 744 }
mbed_official 489:119543c9f674 745 else
mbed_official 489:119543c9f674 746 {
mbed_official 489:119543c9f674 747 /* Disable the CEC Transmission Interrupts */
mbed_official 489:119543c9f674 748 __HAL_CEC_DISABLE_IT(hcec, CEC_IT_IE);
mbed_official 489:119543c9f674 749
mbed_official 489:119543c9f674 750 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 751 }
mbed_official 489:119543c9f674 752 }
mbed_official 489:119543c9f674 753
mbed_official 489:119543c9f674 754 /* Receive error */
mbed_official 489:119543c9f674 755 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RERR) != RESET))
mbed_official 489:119543c9f674 756 {
mbed_official 489:119543c9f674 757 /* Acknowledgement of the error */
mbed_official 489:119543c9f674 758 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR);
mbed_official 489:119543c9f674 759
mbed_official 489:119543c9f674 760 /* Check if a transmit process is ongoing or not */
mbed_official 489:119543c9f674 761 if(hcec->State == HAL_CEC_STATE_BUSY_TX_RX)
mbed_official 489:119543c9f674 762 {
mbed_official 489:119543c9f674 763 /* Interrupts are not disabled due to reception still ongoing */
mbed_official 489:119543c9f674 764
mbed_official 489:119543c9f674 765 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 489:119543c9f674 766 }
mbed_official 489:119543c9f674 767 else
mbed_official 489:119543c9f674 768 {
mbed_official 489:119543c9f674 769 /* Disable the CEC Transmission Interrupts */
mbed_official 489:119543c9f674 770 __HAL_CEC_DISABLE_IT(hcec, CEC_IT_IE);
mbed_official 489:119543c9f674 771
mbed_official 489:119543c9f674 772 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 773 }
mbed_official 489:119543c9f674 774 }
mbed_official 489:119543c9f674 775
mbed_official 489:119543c9f674 776 if ((hcec->ErrorCode & CEC_ESR_ALL_ERROR) != 0)
mbed_official 489:119543c9f674 777 {
mbed_official 489:119543c9f674 778 HAL_CEC_ErrorCallback(hcec);
mbed_official 489:119543c9f674 779 }
mbed_official 489:119543c9f674 780
mbed_official 489:119543c9f674 781 /* Transmit byte request or block transfer finished */
mbed_official 489:119543c9f674 782 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TBTRF) != RESET))
mbed_official 489:119543c9f674 783 {
mbed_official 489:119543c9f674 784 CEC_Transmit_IT(hcec);
mbed_official 489:119543c9f674 785 }
mbed_official 489:119543c9f674 786
mbed_official 489:119543c9f674 787 /* Receive byte or block transfer finished */
mbed_official 489:119543c9f674 788 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RBTF) != RESET))
mbed_official 489:119543c9f674 789 {
mbed_official 489:119543c9f674 790 CEC_Receive_IT(hcec);
mbed_official 489:119543c9f674 791 }
mbed_official 489:119543c9f674 792 }
mbed_official 489:119543c9f674 793
mbed_official 489:119543c9f674 794
mbed_official 489:119543c9f674 795 /**
mbed_official 489:119543c9f674 796 * @brief Tx Transfer completed callback
mbed_official 489:119543c9f674 797 * @param hcec: CEC handle
mbed_official 489:119543c9f674 798 * @retval None
mbed_official 489:119543c9f674 799 */
mbed_official 489:119543c9f674 800 __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 801 {
mbed_official 489:119543c9f674 802 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 803 the HAL_CEC_TxCpltCallback can be implemented in the user file
mbed_official 489:119543c9f674 804 */
mbed_official 489:119543c9f674 805 }
mbed_official 489:119543c9f674 806
mbed_official 489:119543c9f674 807 /**
mbed_official 489:119543c9f674 808 * @brief Rx Transfer completed callback
mbed_official 489:119543c9f674 809 * @param hcec: CEC handle
mbed_official 489:119543c9f674 810 * @retval None
mbed_official 489:119543c9f674 811 */
mbed_official 489:119543c9f674 812 __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 813 {
mbed_official 489:119543c9f674 814 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 815 the HAL_CEC_RxCpltCallback can be implemented in the user file
mbed_official 489:119543c9f674 816 */
mbed_official 489:119543c9f674 817 }
mbed_official 489:119543c9f674 818
mbed_official 489:119543c9f674 819 /**
mbed_official 489:119543c9f674 820 * @brief CEC error callbacks
mbed_official 489:119543c9f674 821 * @param hcec: CEC handle
mbed_official 489:119543c9f674 822 * @retval None
mbed_official 489:119543c9f674 823 */
mbed_official 489:119543c9f674 824 __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 825 {
mbed_official 489:119543c9f674 826 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 827 the HAL_CEC_ErrorCallback can be implemented in the user file
mbed_official 489:119543c9f674 828 */
mbed_official 489:119543c9f674 829 }
mbed_official 489:119543c9f674 830
mbed_official 489:119543c9f674 831 /**
mbed_official 489:119543c9f674 832 * @}
mbed_official 489:119543c9f674 833 */
mbed_official 489:119543c9f674 834
mbed_official 489:119543c9f674 835 /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control functions
mbed_official 489:119543c9f674 836 * @brief CEC control functions
mbed_official 489:119543c9f674 837 *
mbed_official 489:119543c9f674 838 @verbatim
mbed_official 489:119543c9f674 839 ===============================================================================
mbed_official 489:119543c9f674 840 ##### Peripheral Control functions #####
mbed_official 489:119543c9f674 841 ===============================================================================
mbed_official 489:119543c9f674 842 [..]
mbed_official 489:119543c9f674 843 This subsection provides a set of functions allowing to control the CEC.
mbed_official 489:119543c9f674 844 (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral.
mbed_official 489:119543c9f674 845 (+) HAL_CEC_GetError() API can be helpful to get the error code of a failed transmission or reception.
mbed_official 489:119543c9f674 846 @endverbatim
mbed_official 489:119543c9f674 847 * @{
mbed_official 489:119543c9f674 848 */
mbed_official 489:119543c9f674 849
mbed_official 489:119543c9f674 850 /**
mbed_official 489:119543c9f674 851 * @brief return the CEC state
mbed_official 489:119543c9f674 852 * @param hcec: CEC handle
mbed_official 489:119543c9f674 853 * @retval HAL state
mbed_official 489:119543c9f674 854 */
mbed_official 489:119543c9f674 855 HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 856 {
mbed_official 489:119543c9f674 857 return hcec->State;
mbed_official 489:119543c9f674 858 }
mbed_official 489:119543c9f674 859
mbed_official 489:119543c9f674 860 /**
mbed_official 489:119543c9f674 861 * @brief Return the CEC error code
mbed_official 489:119543c9f674 862 * @param hcec : pointer to a CEC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 863 * the configuration information for the specified CEC.
mbed_official 489:119543c9f674 864 * @retval CEC Error Code
mbed_official 489:119543c9f674 865 */
mbed_official 489:119543c9f674 866 uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 867 {
mbed_official 489:119543c9f674 868 return hcec->ErrorCode;
mbed_official 489:119543c9f674 869 }
mbed_official 489:119543c9f674 870
mbed_official 489:119543c9f674 871 /**
mbed_official 489:119543c9f674 872 * @}
mbed_official 489:119543c9f674 873 */
mbed_official 489:119543c9f674 874
mbed_official 489:119543c9f674 875 /**
mbed_official 489:119543c9f674 876 * @}
mbed_official 489:119543c9f674 877 */
mbed_official 489:119543c9f674 878
mbed_official 489:119543c9f674 879 /** @addtogroup CEC_Private_Functions
mbed_official 489:119543c9f674 880 * @{
mbed_official 489:119543c9f674 881 */
mbed_official 489:119543c9f674 882
mbed_official 489:119543c9f674 883 /**
mbed_official 489:119543c9f674 884 * @brief Send data in interrupt mode
mbed_official 489:119543c9f674 885 * @param hcec: CEC handle.
mbed_official 489:119543c9f674 886 * Function called under interruption only, once
mbed_official 489:119543c9f674 887 * interruptions have been enabled by HAL_CEC_Transmit_IT()
mbed_official 489:119543c9f674 888 * @retval HAL status
mbed_official 489:119543c9f674 889 */
mbed_official 489:119543c9f674 890 static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 891 {
mbed_official 489:119543c9f674 892 uint32_t tmp_state = 0;
mbed_official 489:119543c9f674 893
mbed_official 489:119543c9f674 894 tmp_state = hcec->State;
mbed_official 489:119543c9f674 895 /* if the IP is already busy or if there is a previous transmission
mbed_official 489:119543c9f674 896 already pending due to arbitration loss */
mbed_official 489:119543c9f674 897 if(((tmp_state == HAL_CEC_STATE_BUSY_TX) || (tmp_state == HAL_CEC_STATE_BUSY_TX_RX))
mbed_official 489:119543c9f674 898 || (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) != RESET))
mbed_official 489:119543c9f674 899 {
mbed_official 489:119543c9f674 900 /* if all data have been sent */
mbed_official 489:119543c9f674 901 if(hcec->TxXferCount == 0)
mbed_official 489:119543c9f674 902 {
mbed_official 489:119543c9f674 903 /* Acknowledge successful completion by writing 0x00 */
mbed_official 489:119543c9f674 904 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00);
mbed_official 489:119543c9f674 905
mbed_official 489:119543c9f674 906 /* Check if a receive process is ongoing or not */
mbed_official 489:119543c9f674 907 if(hcec->State == HAL_CEC_STATE_BUSY_TX_RX)
mbed_official 489:119543c9f674 908 {
mbed_official 489:119543c9f674 909 /* Interrupts are not disabled due to reception still ongoing */
mbed_official 489:119543c9f674 910
mbed_official 489:119543c9f674 911 hcec->State = HAL_CEC_STATE_BUSY_RX;
mbed_official 489:119543c9f674 912 }
mbed_official 489:119543c9f674 913 else
mbed_official 489:119543c9f674 914 {
mbed_official 489:119543c9f674 915 /* Disable the CEC Transmission Interrupts */
mbed_official 489:119543c9f674 916 __HAL_CEC_DISABLE_IT(hcec, CEC_IT_IE);
mbed_official 489:119543c9f674 917
mbed_official 489:119543c9f674 918 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 919 }
mbed_official 489:119543c9f674 920
mbed_official 489:119543c9f674 921 HAL_CEC_TxCpltCallback(hcec);
mbed_official 489:119543c9f674 922
mbed_official 489:119543c9f674 923 return HAL_OK;
mbed_official 489:119543c9f674 924 }
mbed_official 489:119543c9f674 925 else
mbed_official 489:119543c9f674 926 {
mbed_official 489:119543c9f674 927 /* Reduce the number of bytes to transfer by one */
mbed_official 489:119543c9f674 928 hcec->TxXferCount--;
mbed_official 489:119543c9f674 929
mbed_official 489:119543c9f674 930 /* Write data to TX buffer*/
mbed_official 489:119543c9f674 931 hcec->Instance->TXD = *hcec->pTxBuffPtr++;
mbed_official 489:119543c9f674 932
mbed_official 489:119543c9f674 933 /* If this is the last byte of the ongoing transmission */
mbed_official 489:119543c9f674 934 if (hcec->TxXferCount == 0)
mbed_official 489:119543c9f674 935 {
mbed_official 489:119543c9f674 936 /* Acknowledge byte request and signal end of message */
mbed_official 489:119543c9f674 937 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM);
mbed_official 489:119543c9f674 938 }
mbed_official 489:119543c9f674 939 else
mbed_official 489:119543c9f674 940 {
mbed_official 489:119543c9f674 941 /* Acknowledge byte request by writing 0x00 */
mbed_official 489:119543c9f674 942 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00);
mbed_official 489:119543c9f674 943 }
mbed_official 489:119543c9f674 944
mbed_official 489:119543c9f674 945 return HAL_OK;
mbed_official 489:119543c9f674 946 }
mbed_official 489:119543c9f674 947 }
mbed_official 489:119543c9f674 948 else
mbed_official 489:119543c9f674 949 {
mbed_official 489:119543c9f674 950 return HAL_BUSY;
mbed_official 489:119543c9f674 951 }
mbed_official 489:119543c9f674 952 }
mbed_official 489:119543c9f674 953
mbed_official 489:119543c9f674 954 /**
mbed_official 489:119543c9f674 955 * @brief Receive data in interrupt mode.
mbed_official 489:119543c9f674 956 * @param hcec: CEC handle.
mbed_official 489:119543c9f674 957 * Function called under interruption only, once
mbed_official 489:119543c9f674 958 * interruptions have been enabled by HAL_CEC_Receive_IT()
mbed_official 489:119543c9f674 959 * @retval HAL status
mbed_official 489:119543c9f674 960 */
mbed_official 489:119543c9f674 961 static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec)
mbed_official 489:119543c9f674 962 {
mbed_official 489:119543c9f674 963 static uint32_t temp;
mbed_official 489:119543c9f674 964 uint32_t tmp_state = 0;
mbed_official 489:119543c9f674 965
mbed_official 489:119543c9f674 966 tmp_state = hcec->State;
mbed_official 489:119543c9f674 967 if((tmp_state == HAL_CEC_STATE_BUSY_RX) || (tmp_state == HAL_CEC_STATE_BUSY_TX_RX))
mbed_official 489:119543c9f674 968 {
mbed_official 489:119543c9f674 969 temp = hcec->Instance->CSR;
mbed_official 489:119543c9f674 970
mbed_official 489:119543c9f674 971 /* Store received data */
mbed_official 489:119543c9f674 972 *hcec->pRxBuffPtr++ = hcec->Instance->RXD;
mbed_official 489:119543c9f674 973
mbed_official 489:119543c9f674 974 /* Acknowledge received byte by writing 0x00 */
mbed_official 489:119543c9f674 975 MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_RECEIVE_MASK, 0x00);
mbed_official 489:119543c9f674 976
mbed_official 489:119543c9f674 977 /* Increment the number of received data */
mbed_official 489:119543c9f674 978 if(hcec->RxXferSize == CEC_RXXFERSIZE_INITIALIZE)
mbed_official 489:119543c9f674 979 {
mbed_official 489:119543c9f674 980 hcec->RxXferSize = 0;
mbed_official 489:119543c9f674 981 }
mbed_official 489:119543c9f674 982 else
mbed_official 489:119543c9f674 983 {
mbed_official 489:119543c9f674 984 hcec->RxXferSize++;
mbed_official 489:119543c9f674 985 }
mbed_official 489:119543c9f674 986
mbed_official 489:119543c9f674 987 /* If the End Of Message is reached */
mbed_official 489:119543c9f674 988 if(HAL_IS_BIT_SET(temp, CEC_FLAG_REOM))
mbed_official 489:119543c9f674 989 {
mbed_official 489:119543c9f674 990 if(hcec->State == HAL_CEC_STATE_BUSY_TX_RX)
mbed_official 489:119543c9f674 991 {
mbed_official 489:119543c9f674 992 /* Interrupts are not disabled due to transmission still ongoing */
mbed_official 489:119543c9f674 993
mbed_official 489:119543c9f674 994 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 489:119543c9f674 995 }
mbed_official 489:119543c9f674 996 else
mbed_official 489:119543c9f674 997 {
mbed_official 489:119543c9f674 998 /* Disable the CEC Transmission Interrupts */
mbed_official 489:119543c9f674 999 __HAL_CEC_DISABLE_IT(hcec, CEC_IT_IE);
mbed_official 489:119543c9f674 1000
mbed_official 489:119543c9f674 1001 hcec->State = HAL_CEC_STATE_READY;
mbed_official 489:119543c9f674 1002 }
mbed_official 489:119543c9f674 1003
mbed_official 489:119543c9f674 1004 HAL_CEC_RxCpltCallback(hcec);
mbed_official 489:119543c9f674 1005
mbed_official 489:119543c9f674 1006 return HAL_OK;
mbed_official 489:119543c9f674 1007 }
mbed_official 489:119543c9f674 1008 else
mbed_official 489:119543c9f674 1009 {
mbed_official 489:119543c9f674 1010 return HAL_BUSY;
mbed_official 489:119543c9f674 1011 }
mbed_official 489:119543c9f674 1012 }
mbed_official 489:119543c9f674 1013 else
mbed_official 489:119543c9f674 1014 {
mbed_official 489:119543c9f674 1015 return HAL_BUSY;
mbed_official 489:119543c9f674 1016 }
mbed_official 489:119543c9f674 1017 }
mbed_official 489:119543c9f674 1018
mbed_official 489:119543c9f674 1019 /**
mbed_official 489:119543c9f674 1020 * @}
mbed_official 489:119543c9f674 1021 */
mbed_official 489:119543c9f674 1022
mbed_official 489:119543c9f674 1023 /**
mbed_official 489:119543c9f674 1024 * @}
mbed_official 489:119543c9f674 1025 */
mbed_official 489:119543c9f674 1026
mbed_official 489:119543c9f674 1027 #endif /* defined(STM32F100xB) || defined(STM32F100xE) */
mbed_official 489:119543c9f674 1028
mbed_official 489:119543c9f674 1029 #endif /* HAL_CEC_MODULE_ENABLED */
mbed_official 489:119543c9f674 1030 /**
mbed_official 489:119543c9f674 1031 * @}
mbed_official 489:119543c9f674 1032 */
mbed_official 489:119543c9f674 1033
mbed_official 489:119543c9f674 1034 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/