Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 532:fe11edbda85c 1 /**
mbed_official 532:fe11edbda85c 2 ******************************************************************************
mbed_official 532:fe11edbda85c 3 * @file stm32f4xx_hal_cec.c
mbed_official 532:fe11edbda85c 4 * @author MCD Application Team
mbed_official 613:bc40b8d2aec4 5 * @version V1.3.2
mbed_official 613:bc40b8d2aec4 6 * @date 26-June-2015
mbed_official 532:fe11edbda85c 7 * @brief CEC HAL module driver.
mbed_official 532:fe11edbda85c 8 *
mbed_official 532:fe11edbda85c 9 * This file provides firmware functions to manage the following
mbed_official 532:fe11edbda85c 10 * functionalities of the High Definition Multimedia Interface
mbed_official 532:fe11edbda85c 11 * Consumer Electronics Control Peripheral (CEC).
mbed_official 532:fe11edbda85c 12 * + Initialization and de-initialization functions
mbed_official 532:fe11edbda85c 13 * + IO operation functions
mbed_official 532:fe11edbda85c 14 * + Peripheral Control functions
mbed_official 532:fe11edbda85c 15 *
mbed_official 532:fe11edbda85c 16 *
mbed_official 532:fe11edbda85c 17 @verbatim
mbed_official 532:fe11edbda85c 18 ===============================================================================
mbed_official 532:fe11edbda85c 19 ##### How to use this driver #####
mbed_official 532:fe11edbda85c 20 ===============================================================================
mbed_official 532:fe11edbda85c 21 [..]
mbed_official 532:fe11edbda85c 22 The CEC HAL driver can be used as follow:
mbed_official 532:fe11edbda85c 23
mbed_official 532:fe11edbda85c 24 (#) Declare a CEC_HandleTypeDef handle structure.
mbed_official 532:fe11edbda85c 25 (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API:
mbed_official 532:fe11edbda85c 26 (##) Enable the CEC interface clock.
mbed_official 532:fe11edbda85c 27 (##) CEC pins configuration:
mbed_official 532:fe11edbda85c 28 (+) Enable the clock for the CEC GPIOs.
mbed_official 532:fe11edbda85c 29 (+) Configure these CEC pins as alternate function pull-up.
mbed_official 532:fe11edbda85c 30 (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT()
mbed_official 532:fe11edbda85c 31 and HAL_CEC_Receive_IT() APIs):
mbed_official 532:fe11edbda85c 32 (+) Configure the CEC interrupt priority.
mbed_official 532:fe11edbda85c 33 (+) Enable the NVIC CEC IRQ handle.
mbed_official 532:fe11edbda85c 34 (@) The specific CEC interrupts (Transmission complete interrupt,
mbed_official 532:fe11edbda85c 35 RXNE interrupt and Error Interrupts) will be managed using the macros
mbed_official 532:fe11edbda85c 36 __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit
mbed_official 532:fe11edbda85c 37 and receive process.
mbed_official 532:fe11edbda85c 38
mbed_official 532:fe11edbda85c 39 (#) Program the Signal Free Time (SFT) and SFT option, Tolerance, reception stop in
mbed_official 532:fe11edbda85c 40 in case of Bit Rising Error, Error-Bit generation conditions, device logical
mbed_official 532:fe11edbda85c 41 address and Listen mode in the hcec Init structure.
mbed_official 532:fe11edbda85c 42
mbed_official 532:fe11edbda85c 43 (#) Initialize the CEC registers by calling the HAL_CEC_Init() API.
mbed_official 532:fe11edbda85c 44
mbed_official 532:fe11edbda85c 45 (@) This API (HAL_CEC_Init()) configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
mbed_official 532:fe11edbda85c 46 by calling the customed HAL_CEC_MspInit() API.
mbed_official 532:fe11edbda85c 47
mbed_official 532:fe11edbda85c 48 @endverbatim
mbed_official 532:fe11edbda85c 49 ******************************************************************************
mbed_official 532:fe11edbda85c 50 * @attention
mbed_official 532:fe11edbda85c 51 *
mbed_official 532:fe11edbda85c 52 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 532:fe11edbda85c 53 *
mbed_official 532:fe11edbda85c 54 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 532:fe11edbda85c 55 * are permitted provided that the following conditions are met:
mbed_official 532:fe11edbda85c 56 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 532:fe11edbda85c 57 * this list of conditions and the following disclaimer.
mbed_official 532:fe11edbda85c 58 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 532:fe11edbda85c 59 * this list of conditions and the following disclaimer in the documentation
mbed_official 532:fe11edbda85c 60 * and/or other materials provided with the distribution.
mbed_official 532:fe11edbda85c 61 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 532:fe11edbda85c 62 * may be used to endorse or promote products derived from this software
mbed_official 532:fe11edbda85c 63 * without specific prior written permission.
mbed_official 532:fe11edbda85c 64 *
mbed_official 532:fe11edbda85c 65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 532:fe11edbda85c 66 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 532:fe11edbda85c 67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 532:fe11edbda85c 68 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 532:fe11edbda85c 69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 532:fe11edbda85c 70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 532:fe11edbda85c 71 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 532:fe11edbda85c 72 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 532:fe11edbda85c 73 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 532:fe11edbda85c 74 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 532:fe11edbda85c 75 *
mbed_official 532:fe11edbda85c 76 ******************************************************************************
mbed_official 532:fe11edbda85c 77 */
mbed_official 532:fe11edbda85c 78
mbed_official 532:fe11edbda85c 79 /* Includes ------------------------------------------------------------------*/
mbed_official 532:fe11edbda85c 80 #include "stm32f4xx_hal.h"
mbed_official 532:fe11edbda85c 81
mbed_official 532:fe11edbda85c 82 /** @addtogroup STM32F4xx_HAL_Driver
mbed_official 532:fe11edbda85c 83 * @{
mbed_official 532:fe11edbda85c 84 */
mbed_official 532:fe11edbda85c 85
mbed_official 532:fe11edbda85c 86 /** @defgroup CEC CEC
mbed_official 532:fe11edbda85c 87 * @brief HAL CEC module driver
mbed_official 532:fe11edbda85c 88 * @{
mbed_official 532:fe11edbda85c 89 */
mbed_official 532:fe11edbda85c 90 #ifdef HAL_CEC_MODULE_ENABLED
mbed_official 532:fe11edbda85c 91
mbed_official 532:fe11edbda85c 92 #if defined(STM32F446xx)
mbed_official 532:fe11edbda85c 93
mbed_official 532:fe11edbda85c 94 /* Private typedef -----------------------------------------------------------*/
mbed_official 532:fe11edbda85c 95 /* Private define ------------------------------------------------------------*/
mbed_official 532:fe11edbda85c 96 /** @defgroup CEC_Private_Constants CEC Private Constants
mbed_official 532:fe11edbda85c 97 * @{
mbed_official 532:fe11edbda85c 98 */
mbed_official 532:fe11edbda85c 99 #define CEC_CFGR_FIELDS (CEC_CFGR_SFT | CEC_CFGR_RXTOL | CEC_CFGR_BRESTP \
mbed_official 532:fe11edbda85c 100 | CEC_CFGR_BREGEN | CEC_CFGR_LBPEGEN | CEC_CFGR_SFTOPT \
mbed_official 532:fe11edbda85c 101 | CEC_CFGR_BRDNOGEN | CEC_CFGR_OAR | CEC_CFGR_LSTN)
mbed_official 532:fe11edbda85c 102 /**
mbed_official 532:fe11edbda85c 103 * @}
mbed_official 532:fe11edbda85c 104 */
mbed_official 532:fe11edbda85c 105
mbed_official 532:fe11edbda85c 106 /* Private macro -------------------------------------------------------------*/
mbed_official 532:fe11edbda85c 107 /* Private variables ---------------------------------------------------------*/
mbed_official 532:fe11edbda85c 108 /* Private function prototypes -----------------------------------------------*/
mbed_official 532:fe11edbda85c 109 /** @defgroup CEC_Private_Functions CEC Private Functions
mbed_official 532:fe11edbda85c 110 * @{
mbed_official 532:fe11edbda85c 111 */
mbed_official 532:fe11edbda85c 112 static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec);
mbed_official 532:fe11edbda85c 113 static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec);
mbed_official 532:fe11edbda85c 114 /**
mbed_official 532:fe11edbda85c 115 * @}
mbed_official 532:fe11edbda85c 116 */
mbed_official 532:fe11edbda85c 117
mbed_official 532:fe11edbda85c 118 /* Exported functions ---------------------------------------------------------*/
mbed_official 532:fe11edbda85c 119 /** @defgroup CEC_Exported_Functions CEC Exported Functions
mbed_official 532:fe11edbda85c 120 * @{
mbed_official 532:fe11edbda85c 121 */
mbed_official 532:fe11edbda85c 122
mbed_official 532:fe11edbda85c 123 /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 532:fe11edbda85c 124 * @brief Initialization and Configuration functions
mbed_official 532:fe11edbda85c 125 *
mbed_official 532:fe11edbda85c 126 @verbatim
mbed_official 532:fe11edbda85c 127 ===============================================================================
mbed_official 532:fe11edbda85c 128 ##### Initialization and Configuration functions #####
mbed_official 532:fe11edbda85c 129 ===============================================================================
mbed_official 532:fe11edbda85c 130 [..]
mbed_official 532:fe11edbda85c 131 This subsection provides a set of functions allowing to initialize the CEC
mbed_official 532:fe11edbda85c 132 (+) The following parameters need to be configured:
mbed_official 532:fe11edbda85c 133 (++) SignalFreeTime
mbed_official 532:fe11edbda85c 134 (++) Tolerance
mbed_official 532:fe11edbda85c 135 (++) BRERxStop (RX stopped or not upon Bit Rising Error)
mbed_official 532:fe11edbda85c 136 (++) BREErrorBitGen (Error-Bit generation in case of Bit Rising Error)
mbed_official 532:fe11edbda85c 137 (++) LBPEErrorBitGen (Error-Bit generation in case of Long Bit Period Error)
mbed_official 532:fe11edbda85c 138 (++) BroadcastMsgNoErrorBitGen (Error-bit generation in case of broadcast message error)
mbed_official 532:fe11edbda85c 139 (++) SignalFreeTimeOption (SFT Timer start definition)
mbed_official 532:fe11edbda85c 140 (++) OwnAddress (CEC device address)
mbed_official 532:fe11edbda85c 141 (++) ListenMode
mbed_official 532:fe11edbda85c 142
mbed_official 532:fe11edbda85c 143 @endverbatim
mbed_official 532:fe11edbda85c 144 * @{
mbed_official 532:fe11edbda85c 145 */
mbed_official 532:fe11edbda85c 146
mbed_official 532:fe11edbda85c 147 /**
mbed_official 532:fe11edbda85c 148 * @brief Initializes the CEC mode according to the specified
mbed_official 532:fe11edbda85c 149 * parameters in the CEC_InitTypeDef and creates the associated handle .
mbed_official 532:fe11edbda85c 150 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 151 * @retval HAL status
mbed_official 532:fe11edbda85c 152 */
mbed_official 532:fe11edbda85c 153 HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 154 {
mbed_official 532:fe11edbda85c 155 uint32_t tmpreg = 0x0;
mbed_official 532:fe11edbda85c 156
mbed_official 532:fe11edbda85c 157 /* Check the CEC handle allocation */
mbed_official 532:fe11edbda85c 158 if(hcec == NULL)
mbed_official 532:fe11edbda85c 159 {
mbed_official 532:fe11edbda85c 160 return HAL_ERROR;
mbed_official 532:fe11edbda85c 161 }
mbed_official 532:fe11edbda85c 162
mbed_official 532:fe11edbda85c 163 /* Check the parameters */
mbed_official 532:fe11edbda85c 164 assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
mbed_official 532:fe11edbda85c 165 assert_param(IS_CEC_SIGNALFREETIME(hcec->Init.SignalFreeTime));
mbed_official 532:fe11edbda85c 166 assert_param(IS_CEC_TOLERANCE(hcec->Init.Tolerance));
mbed_official 532:fe11edbda85c 167 assert_param(IS_CEC_BRERXSTOP(hcec->Init.BRERxStop));
mbed_official 532:fe11edbda85c 168 assert_param(IS_CEC_BREERRORBITGEN(hcec->Init.BREErrorBitGen));
mbed_official 532:fe11edbda85c 169 assert_param(IS_CEC_LBPEERRORBITGEN(hcec->Init.LBPEErrorBitGen));
mbed_official 532:fe11edbda85c 170 assert_param(IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(hcec->Init.BroadcastMsgNoErrorBitGen));
mbed_official 532:fe11edbda85c 171 assert_param(IS_CEC_SFTOP(hcec->Init.SignalFreeTimeOption));
mbed_official 532:fe11edbda85c 172 assert_param(IS_CEC_OAR_ADDRESS(hcec->Init.OwnAddress));
mbed_official 532:fe11edbda85c 173 assert_param(IS_CEC_LISTENING_MODE(hcec->Init.ListenMode));
mbed_official 532:fe11edbda85c 174 assert_param(IS_CEC_ADDRESS(hcec->Init.InitiatorAddress));
mbed_official 532:fe11edbda85c 175
mbed_official 532:fe11edbda85c 176
mbed_official 532:fe11edbda85c 177 if(hcec->State == HAL_CEC_STATE_RESET)
mbed_official 532:fe11edbda85c 178 {
mbed_official 532:fe11edbda85c 179 /* Allocate lock resource and initialize it */
mbed_official 532:fe11edbda85c 180 hcec->Lock = HAL_UNLOCKED;
mbed_official 532:fe11edbda85c 181 /* Init the low level hardware : GPIO, CLOCK */
mbed_official 532:fe11edbda85c 182 HAL_CEC_MspInit(hcec);
mbed_official 532:fe11edbda85c 183 }
mbed_official 532:fe11edbda85c 184
mbed_official 532:fe11edbda85c 185 hcec->State = HAL_CEC_STATE_BUSY;
mbed_official 532:fe11edbda85c 186
mbed_official 532:fe11edbda85c 187 /* Disable the Peripheral */
mbed_official 532:fe11edbda85c 188 __HAL_CEC_DISABLE(hcec);
mbed_official 532:fe11edbda85c 189
mbed_official 532:fe11edbda85c 190 tmpreg = hcec->Init.SignalFreeTime;
mbed_official 532:fe11edbda85c 191 tmpreg |= hcec->Init.Tolerance;
mbed_official 532:fe11edbda85c 192 tmpreg |= hcec->Init.BRERxStop;
mbed_official 532:fe11edbda85c 193 tmpreg |= hcec->Init.BREErrorBitGen;
mbed_official 532:fe11edbda85c 194 tmpreg |= hcec->Init.LBPEErrorBitGen;
mbed_official 532:fe11edbda85c 195 tmpreg |= hcec->Init.BroadcastMsgNoErrorBitGen;
mbed_official 532:fe11edbda85c 196 tmpreg |= hcec->Init.SignalFreeTimeOption;
mbed_official 532:fe11edbda85c 197 tmpreg |= (hcec->Init.OwnAddress << CEC_CFGR_OAR_LSB_POS);
mbed_official 532:fe11edbda85c 198 tmpreg |= hcec->Init.ListenMode;
mbed_official 532:fe11edbda85c 199
mbed_official 532:fe11edbda85c 200 /* Write to CEC Control Register */
mbed_official 532:fe11edbda85c 201 MODIFY_REG(hcec->Instance->CFGR, CEC_CFGR_FIELDS, tmpreg);
mbed_official 532:fe11edbda85c 202
mbed_official 532:fe11edbda85c 203 /* Enable the Peripheral */
mbed_official 532:fe11edbda85c 204 __HAL_CEC_ENABLE(hcec);
mbed_official 532:fe11edbda85c 205
mbed_official 532:fe11edbda85c 206 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 207
mbed_official 532:fe11edbda85c 208 return HAL_OK;
mbed_official 532:fe11edbda85c 209 }
mbed_official 532:fe11edbda85c 210
mbed_official 532:fe11edbda85c 211 /**
mbed_official 532:fe11edbda85c 212 * @brief DeInitializes the CEC peripheral
mbed_official 532:fe11edbda85c 213 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 214 * @retval HAL status
mbed_official 532:fe11edbda85c 215 */
mbed_official 532:fe11edbda85c 216 HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 217 {
mbed_official 532:fe11edbda85c 218 /* Check the CEC handle allocation */
mbed_official 532:fe11edbda85c 219 if(hcec == NULL)
mbed_official 532:fe11edbda85c 220 {
mbed_official 532:fe11edbda85c 221 return HAL_ERROR;
mbed_official 532:fe11edbda85c 222 }
mbed_official 532:fe11edbda85c 223
mbed_official 532:fe11edbda85c 224 /* Check the parameters */
mbed_official 532:fe11edbda85c 225 assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
mbed_official 532:fe11edbda85c 226
mbed_official 532:fe11edbda85c 227 hcec->State = HAL_CEC_STATE_BUSY;
mbed_official 532:fe11edbda85c 228
mbed_official 532:fe11edbda85c 229 /* DeInit the low level hardware */
mbed_official 532:fe11edbda85c 230 HAL_CEC_MspDeInit(hcec);
mbed_official 532:fe11edbda85c 231 /* Disable the Peripheral */
mbed_official 532:fe11edbda85c 232 __HAL_CEC_DISABLE(hcec);
mbed_official 532:fe11edbda85c 233
mbed_official 532:fe11edbda85c 234 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 532:fe11edbda85c 235 hcec->State = HAL_CEC_STATE_RESET;
mbed_official 532:fe11edbda85c 236
mbed_official 532:fe11edbda85c 237 /* Process Unlock */
mbed_official 532:fe11edbda85c 238 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 239
mbed_official 532:fe11edbda85c 240 return HAL_OK;
mbed_official 532:fe11edbda85c 241 }
mbed_official 532:fe11edbda85c 242
mbed_official 532:fe11edbda85c 243 /**
mbed_official 532:fe11edbda85c 244 * @brief CEC MSP Init
mbed_official 532:fe11edbda85c 245 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 246 * @retval None
mbed_official 532:fe11edbda85c 247 */
mbed_official 532:fe11edbda85c 248 __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 249 {
mbed_official 532:fe11edbda85c 250 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 251 the HAL_CEC_MspInit can be implemented in the user file
mbed_official 532:fe11edbda85c 252 */
mbed_official 532:fe11edbda85c 253 }
mbed_official 532:fe11edbda85c 254
mbed_official 532:fe11edbda85c 255 /**
mbed_official 532:fe11edbda85c 256 * @brief CEC MSP DeInit
mbed_official 532:fe11edbda85c 257 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 258 * @retval None
mbed_official 532:fe11edbda85c 259 */
mbed_official 532:fe11edbda85c 260 __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 261 {
mbed_official 532:fe11edbda85c 262 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 263 the HAL_CEC_MspDeInit can be implemented in the user file
mbed_official 532:fe11edbda85c 264 */
mbed_official 532:fe11edbda85c 265 }
mbed_official 532:fe11edbda85c 266 /**
mbed_official 532:fe11edbda85c 267 * @}
mbed_official 532:fe11edbda85c 268 */
mbed_official 532:fe11edbda85c 269
mbed_official 532:fe11edbda85c 270 /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions
mbed_official 532:fe11edbda85c 271 * @brief CEC Transmit/Receive functions
mbed_official 532:fe11edbda85c 272 *
mbed_official 532:fe11edbda85c 273 @verbatim
mbed_official 532:fe11edbda85c 274 ===============================================================================
mbed_official 532:fe11edbda85c 275 ##### I/O operation functions #####
mbed_official 532:fe11edbda85c 276 ===============================================================================
mbed_official 532:fe11edbda85c 277 This subsection provides a set of functions allowing to manage the CEC data transfers.
mbed_official 532:fe11edbda85c 278
mbed_official 532:fe11edbda85c 279 (#) The CEC handle must contain the initiator (TX side) and the destination (RX side)
mbed_official 532:fe11edbda85c 280 logical addresses (4-bit long addresses, 0xF for broadcast messages destination)
mbed_official 532:fe11edbda85c 281
mbed_official 532:fe11edbda85c 282 (#) There are two mode of transfer:
mbed_official 532:fe11edbda85c 283 (+) Blocking mode: The communication is performed in polling mode.
mbed_official 532:fe11edbda85c 284 The HAL status of all data processing is returned by the same function
mbed_official 532:fe11edbda85c 285 after finishing transfer.
mbed_official 532:fe11edbda85c 286 (+) No-Blocking mode: The communication is performed using Interrupts.
mbed_official 532:fe11edbda85c 287 These API's return the HAL status.
mbed_official 532:fe11edbda85c 288 The end of the data processing will be indicated through the
mbed_official 532:fe11edbda85c 289 dedicated CEC IRQ when using Interrupt mode.
mbed_official 532:fe11edbda85c 290 The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks
mbed_official 532:fe11edbda85c 291 will be executed respectivelly at the end of the transmit or Receive process
mbed_official 532:fe11edbda85c 292 The HAL_CEC_ErrorCallback()user callback will be executed when a communication
mbed_official 532:fe11edbda85c 293 error is detected
mbed_official 532:fe11edbda85c 294
mbed_official 532:fe11edbda85c 295 (#) Blocking mode API's are :
mbed_official 532:fe11edbda85c 296 (+) HAL_CEC_Transmit()
mbed_official 532:fe11edbda85c 297 (+) HAL_CEC_Receive()
mbed_official 532:fe11edbda85c 298
mbed_official 532:fe11edbda85c 299 (#) Non-Blocking mode API's with Interrupt are :
mbed_official 532:fe11edbda85c 300 (+) HAL_CEC_Transmit_IT()
mbed_official 532:fe11edbda85c 301 (+) HAL_CEC_Receive_IT()
mbed_official 532:fe11edbda85c 302 (+) HAL_CEC_IRQHandler()
mbed_official 532:fe11edbda85c 303
mbed_official 532:fe11edbda85c 304 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
mbed_official 532:fe11edbda85c 305 (+) HAL_CEC_TxCpltCallback()
mbed_official 532:fe11edbda85c 306 (+) HAL_CEC_RxCpltCallback()
mbed_official 532:fe11edbda85c 307 (+) HAL_CEC_ErrorCallback()
mbed_official 532:fe11edbda85c 308
mbed_official 532:fe11edbda85c 309 @endverbatim
mbed_official 532:fe11edbda85c 310 * @{
mbed_official 532:fe11edbda85c 311 */
mbed_official 532:fe11edbda85c 312
mbed_official 532:fe11edbda85c 313 /**
mbed_official 532:fe11edbda85c 314 * @brief Send data in blocking mode
mbed_official 532:fe11edbda85c 315 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 316 * @param DestinationAddress: destination logical address
mbed_official 532:fe11edbda85c 317 * @param pData: pointer to input byte data buffer
mbed_official 532:fe11edbda85c 318 * @param Size: amount of data to be sent in bytes (without counting the header).
mbed_official 532:fe11edbda85c 319 * 0 means only the header is sent (ping operation).
mbed_official 532:fe11edbda85c 320 * Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
mbed_official 532:fe11edbda85c 321 * @param Timeout: Timeout duration.
mbed_official 532:fe11edbda85c 322 * @retval HAL status
mbed_official 532:fe11edbda85c 323 */
mbed_official 532:fe11edbda85c 324 HAL_StatusTypeDef HAL_CEC_Transmit(CEC_HandleTypeDef *hcec, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size, uint32_t Timeout)
mbed_official 532:fe11edbda85c 325 {
mbed_official 532:fe11edbda85c 326 uint8_t temp = 0;
mbed_official 532:fe11edbda85c 327 uint32_t tempisr = 0;
mbed_official 532:fe11edbda85c 328 uint32_t tickstart = 0;
mbed_official 532:fe11edbda85c 329
mbed_official 532:fe11edbda85c 330 if((hcec->State == HAL_CEC_STATE_READY) && (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) == RESET))
mbed_official 532:fe11edbda85c 331 {
mbed_official 532:fe11edbda85c 332 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 532:fe11edbda85c 333 if((pData == NULL ) && (Size > 0))
mbed_official 532:fe11edbda85c 334 {
mbed_official 532:fe11edbda85c 335 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 336 return HAL_ERROR;
mbed_official 532:fe11edbda85c 337 }
mbed_official 532:fe11edbda85c 338
mbed_official 532:fe11edbda85c 339 assert_param(IS_CEC_ADDRESS(DestinationAddress));
mbed_official 532:fe11edbda85c 340 assert_param(IS_CEC_MSGSIZE(Size));
mbed_official 532:fe11edbda85c 341
mbed_official 532:fe11edbda85c 342 /* Process Locked */
mbed_official 532:fe11edbda85c 343 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 344
mbed_official 532:fe11edbda85c 345 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 532:fe11edbda85c 346
mbed_official 532:fe11edbda85c 347 hcec->TxXferCount = Size;
mbed_official 532:fe11edbda85c 348
mbed_official 532:fe11edbda85c 349 /* case no data to be sent, sender is only pinging the system */
mbed_official 532:fe11edbda85c 350 if (Size == 0)
mbed_official 532:fe11edbda85c 351 {
mbed_official 532:fe11edbda85c 352 /* Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */
mbed_official 532:fe11edbda85c 353 __HAL_CEC_LAST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 354 }
mbed_official 532:fe11edbda85c 355
mbed_official 532:fe11edbda85c 356 /* send header block */
mbed_official 532:fe11edbda85c 357 temp = ((uint32_t)hcec->Init.InitiatorAddress << CEC_INITIATOR_LSB_POS) | DestinationAddress;
mbed_official 532:fe11edbda85c 358 hcec->Instance->TXDR = temp;
mbed_official 532:fe11edbda85c 359 /* Set TX Start of Message (TXSOM) bit */
mbed_official 532:fe11edbda85c 360 __HAL_CEC_FIRST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 361
mbed_official 532:fe11edbda85c 362 while (hcec->TxXferCount > 0)
mbed_official 532:fe11edbda85c 363 {
mbed_official 532:fe11edbda85c 364 hcec->TxXferCount--;
mbed_official 532:fe11edbda85c 365
mbed_official 532:fe11edbda85c 366 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 367 while(HAL_IS_BIT_CLR(hcec->Instance->ISR, CEC_FLAG_TXBR))
mbed_official 532:fe11edbda85c 368 {
mbed_official 532:fe11edbda85c 369 if(Timeout != HAL_MAX_DELAY)
mbed_official 532:fe11edbda85c 370 {
mbed_official 532:fe11edbda85c 371 if((HAL_GetTick() - tickstart) > Timeout)
mbed_official 532:fe11edbda85c 372 {
mbed_official 532:fe11edbda85c 373 hcec->State = HAL_CEC_STATE_TIMEOUT;
mbed_official 532:fe11edbda85c 374 /* Process Unlocked */
mbed_official 532:fe11edbda85c 375 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 376 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 377 }
mbed_official 532:fe11edbda85c 378 }
mbed_official 532:fe11edbda85c 379
mbed_official 532:fe11edbda85c 380 /* check whether error occured while waiting for TXBR to be set:
mbed_official 532:fe11edbda85c 381 * has Tx underrun occurred ?
mbed_official 532:fe11edbda85c 382 * has Tx error occurred ?
mbed_official 532:fe11edbda85c 383 * has Tx Missing Acknowledge error occurred ?
mbed_official 532:fe11edbda85c 384 * has Arbitration Loss error occurred ? */
mbed_official 532:fe11edbda85c 385 tempisr = hcec->Instance->ISR;
mbed_official 532:fe11edbda85c 386 if ((tempisr & (CEC_FLAG_TXUDR|CEC_FLAG_TXERR|CEC_FLAG_TXACKE|CEC_FLAG_ARBLST)) != 0)
mbed_official 532:fe11edbda85c 387 {
mbed_official 532:fe11edbda85c 388 /* copy ISR for error handling purposes */
mbed_official 532:fe11edbda85c 389 hcec->ErrorCode = tempisr;
mbed_official 532:fe11edbda85c 390 /* clear all error flags by default */
mbed_official 532:fe11edbda85c 391 __HAL_CEC_CLEAR_FLAG(hcec, (CEC_FLAG_TXUDR|CEC_FLAG_TXERR|CEC_FLAG_TXACKE|CEC_FLAG_ARBLST));
mbed_official 532:fe11edbda85c 392 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 393 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 394 return HAL_ERROR;
mbed_official 532:fe11edbda85c 395 }
mbed_official 532:fe11edbda85c 396 }
mbed_official 532:fe11edbda85c 397 /* TXBR to clear BEFORE writing TXDR register */
mbed_official 532:fe11edbda85c 398 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXBR);
mbed_official 532:fe11edbda85c 399 if (hcec->TxXferCount == 0)
mbed_official 532:fe11edbda85c 400 {
mbed_official 532:fe11edbda85c 401 /* if last byte transmission, set TX End of Message (TXEOM) bit */
mbed_official 532:fe11edbda85c 402 __HAL_CEC_LAST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 403 }
mbed_official 532:fe11edbda85c 404 hcec->Instance->TXDR = *pData++;
mbed_official 532:fe11edbda85c 405
mbed_official 532:fe11edbda85c 406 /* error check after TX byte write up */
mbed_official 532:fe11edbda85c 407 tempisr = hcec->Instance->ISR;
mbed_official 532:fe11edbda85c 408 if ((tempisr & (CEC_FLAG_TXUDR|CEC_FLAG_TXERR|CEC_FLAG_TXACKE|CEC_FLAG_ARBLST)) != 0)
mbed_official 532:fe11edbda85c 409 {
mbed_official 532:fe11edbda85c 410 /* copy ISR for error handling purposes */
mbed_official 532:fe11edbda85c 411 hcec->ErrorCode = tempisr;
mbed_official 532:fe11edbda85c 412 /* clear all error flags by default */
mbed_official 532:fe11edbda85c 413 __HAL_CEC_CLEAR_FLAG(hcec, (CEC_FLAG_TXUDR|CEC_FLAG_TXERR|CEC_FLAG_TXACKE|CEC_FLAG_ARBLST));
mbed_official 532:fe11edbda85c 414 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 415 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 416 return HAL_ERROR;
mbed_official 532:fe11edbda85c 417 }
mbed_official 532:fe11edbda85c 418 } /* end while (while (hcec->TxXferCount > 0)) */
mbed_official 532:fe11edbda85c 419
mbed_official 532:fe11edbda85c 420
mbed_official 532:fe11edbda85c 421 /* if no error up to this point, check that transmission is
mbed_official 532:fe11edbda85c 422 * complete, that is wait until TXEOM is reset */
mbed_official 532:fe11edbda85c 423 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 424
mbed_official 532:fe11edbda85c 425 while (HAL_IS_BIT_SET(hcec->Instance->CR, CEC_CR_TXEOM))
mbed_official 532:fe11edbda85c 426 {
mbed_official 532:fe11edbda85c 427 if(Timeout != HAL_MAX_DELAY)
mbed_official 532:fe11edbda85c 428 {
mbed_official 532:fe11edbda85c 429 if((HAL_GetTick() - tickstart) > Timeout)
mbed_official 532:fe11edbda85c 430 {
mbed_official 532:fe11edbda85c 431 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 432 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 433 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 434 }
mbed_official 532:fe11edbda85c 435 }
mbed_official 532:fe11edbda85c 436 }
mbed_official 532:fe11edbda85c 437
mbed_official 532:fe11edbda85c 438 /* Final error check once all bytes have been transmitted */
mbed_official 532:fe11edbda85c 439 tempisr = hcec->Instance->ISR;
mbed_official 532:fe11edbda85c 440 if ((tempisr & (CEC_FLAG_TXUDR|CEC_FLAG_TXERR|CEC_FLAG_TXACKE)) != 0)
mbed_official 532:fe11edbda85c 441 {
mbed_official 532:fe11edbda85c 442 /* copy ISR for error handling purposes */
mbed_official 532:fe11edbda85c 443 hcec->ErrorCode = tempisr;
mbed_official 532:fe11edbda85c 444 /* clear all error flags by default */
mbed_official 532:fe11edbda85c 445 __HAL_CEC_CLEAR_FLAG(hcec, (CEC_FLAG_TXUDR|CEC_FLAG_TXERR|CEC_FLAG_TXACKE));
mbed_official 532:fe11edbda85c 446 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 447 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 448 return HAL_ERROR;
mbed_official 532:fe11edbda85c 449 }
mbed_official 532:fe11edbda85c 450
mbed_official 532:fe11edbda85c 451 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 452 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 453
mbed_official 532:fe11edbda85c 454 return HAL_OK;
mbed_official 532:fe11edbda85c 455 }
mbed_official 532:fe11edbda85c 456 else
mbed_official 532:fe11edbda85c 457 {
mbed_official 532:fe11edbda85c 458 return HAL_BUSY;
mbed_official 532:fe11edbda85c 459 }
mbed_official 532:fe11edbda85c 460 }
mbed_official 532:fe11edbda85c 461
mbed_official 532:fe11edbda85c 462 /**
mbed_official 532:fe11edbda85c 463 * @brief Receive data in blocking mode. Must be invoked when RXBR has been set.
mbed_official 532:fe11edbda85c 464 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 465 * @param pData: pointer to received data buffer.
mbed_official 532:fe11edbda85c 466 * @param Timeout: Timeout duration.
mbed_official 532:fe11edbda85c 467 * Note that the received data size is not known beforehand, the latter is known
mbed_official 532:fe11edbda85c 468 * when the reception is complete and is stored in hcec->RxXferSize.
mbed_official 532:fe11edbda85c 469 * hcec->RxXferSize is the sum of opcodes + operands (0 to 14 operands max).
mbed_official 532:fe11edbda85c 470 * If only a header is received, hcec->RxXferSize = 0
mbed_official 532:fe11edbda85c 471 * @retval HAL status
mbed_official 532:fe11edbda85c 472 */
mbed_official 532:fe11edbda85c 473 HAL_StatusTypeDef HAL_CEC_Receive(CEC_HandleTypeDef *hcec, uint8_t *pData, uint32_t Timeout)
mbed_official 532:fe11edbda85c 474 {
mbed_official 532:fe11edbda85c 475 uint32_t temp;
mbed_official 532:fe11edbda85c 476 uint32_t tickstart = 0;
mbed_official 532:fe11edbda85c 477
mbed_official 532:fe11edbda85c 478 if (hcec->State == HAL_CEC_STATE_READY)
mbed_official 532:fe11edbda85c 479 {
mbed_official 532:fe11edbda85c 480 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 532:fe11edbda85c 481 if (pData == NULL )
mbed_official 532:fe11edbda85c 482 {
mbed_official 532:fe11edbda85c 483 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 484 return HAL_ERROR;
mbed_official 532:fe11edbda85c 485 }
mbed_official 532:fe11edbda85c 486
mbed_official 532:fe11edbda85c 487 hcec->RxXferSize = 0;
mbed_official 532:fe11edbda85c 488 /* Process Locked */
mbed_official 532:fe11edbda85c 489 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 490
mbed_official 532:fe11edbda85c 491
mbed_official 532:fe11edbda85c 492 /* Rx loop until CEC_ISR_RXEND is set */
mbed_official 532:fe11edbda85c 493 while (HAL_IS_BIT_CLR(hcec->Instance->ISR, CEC_FLAG_RXEND))
mbed_official 532:fe11edbda85c 494 {
mbed_official 532:fe11edbda85c 495 tickstart = HAL_GetTick();
mbed_official 532:fe11edbda85c 496 /* Wait for next byte to be received */
mbed_official 532:fe11edbda85c 497 while (HAL_IS_BIT_CLR(hcec->Instance->ISR, CEC_FLAG_RXBR))
mbed_official 532:fe11edbda85c 498 {
mbed_official 532:fe11edbda85c 499 if(Timeout != HAL_MAX_DELAY)
mbed_official 532:fe11edbda85c 500 {
mbed_official 532:fe11edbda85c 501 if((HAL_GetTick() - tickstart) > Timeout)
mbed_official 532:fe11edbda85c 502 {
mbed_official 532:fe11edbda85c 503 hcec->State = HAL_CEC_STATE_TIMEOUT;
mbed_official 532:fe11edbda85c 504 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 505 return HAL_TIMEOUT;
mbed_official 532:fe11edbda85c 506 }
mbed_official 532:fe11edbda85c 507 }
mbed_official 532:fe11edbda85c 508 /* any error so far ?
mbed_official 532:fe11edbda85c 509 * has Rx Missing Acknowledge occurred ?
mbed_official 532:fe11edbda85c 510 * has Rx Long Bit Period error occurred ?
mbed_official 532:fe11edbda85c 511 * has Rx Short Bit Period error occurred ?
mbed_official 532:fe11edbda85c 512 * has Rx Bit Rising error occurred ?
mbed_official 532:fe11edbda85c 513 * has Rx Overrun error occurred ? */
mbed_official 532:fe11edbda85c 514 temp = (uint32_t) (hcec->Instance->ISR);
mbed_official 532:fe11edbda85c 515 if ((temp & (CEC_FLAG_RXACKE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|CEC_FLAG_BRE|CEC_FLAG_RXOVR)) != 0)
mbed_official 532:fe11edbda85c 516 {
mbed_official 532:fe11edbda85c 517 /* copy ISR for error handling purposes */
mbed_official 532:fe11edbda85c 518 hcec->ErrorCode = temp;
mbed_official 532:fe11edbda85c 519 /* clear all error flags by default */
mbed_official 532:fe11edbda85c 520 __HAL_CEC_CLEAR_FLAG(hcec,(CEC_FLAG_RXACKE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|CEC_FLAG_BRE|CEC_FLAG_RXOVR));
mbed_official 532:fe11edbda85c 521 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 522 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 523 return HAL_ERROR;
mbed_official 532:fe11edbda85c 524 }
mbed_official 532:fe11edbda85c 525 } /* while (HAL_IS_BIT_CLR(hcec->Instance->ISR, CEC_ISR_RXBR)) */
mbed_official 532:fe11edbda85c 526
mbed_official 532:fe11edbda85c 527
mbed_official 532:fe11edbda85c 528 /* read received data */
mbed_official 532:fe11edbda85c 529 *pData++ = hcec->Instance->RXDR;
mbed_official 532:fe11edbda85c 530 temp = (uint32_t) (hcec->Instance->ISR);
mbed_official 532:fe11edbda85c 531 /* end of message ? */
mbed_official 532:fe11edbda85c 532 if ((temp & CEC_ISR_RXEND) != 0)
mbed_official 532:fe11edbda85c 533 {
mbed_official 532:fe11edbda85c 534 assert_param(IS_CEC_MSGSIZE(hcec->RxXferSize));
mbed_official 532:fe11edbda85c 535 __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_RXEND);
mbed_official 532:fe11edbda85c 536 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 537 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 538 return HAL_OK;
mbed_official 532:fe11edbda85c 539 }
mbed_official 532:fe11edbda85c 540
mbed_official 532:fe11edbda85c 541 /* clear Rx-Byte Received flag */
mbed_official 532:fe11edbda85c 542 __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_RXBR);
mbed_official 532:fe11edbda85c 543 /* increment payload byte counter */
mbed_official 532:fe11edbda85c 544 hcec->RxXferSize++;
mbed_official 532:fe11edbda85c 545 } /* while (HAL_IS_BIT_CLR(hcec->Instance->ISR, CEC_ISR_RXEND)) */
mbed_official 532:fe11edbda85c 546
mbed_official 532:fe11edbda85c 547 /* if the instructions below are executed, it means RXEND was set when RXBR was
mbed_official 532:fe11edbda85c 548 * set for the first time:
mbed_official 532:fe11edbda85c 549 * the code within the "while (HAL_IS_BIT_CLR(hcec->Instance->ISR, CEC_ISR_RXEND))"
mbed_official 532:fe11edbda85c 550 * loop has not been executed and this means a single byte has been sent */
mbed_official 532:fe11edbda85c 551 *pData++ = hcec->Instance->RXDR;
mbed_official 532:fe11edbda85c 552 /* only one header is received: RxXferSize is set to 0 (no operand, no opcode) */
mbed_official 532:fe11edbda85c 553 hcec->RxXferSize = 0;
mbed_official 532:fe11edbda85c 554 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXEND);
mbed_official 532:fe11edbda85c 555
mbed_official 532:fe11edbda85c 556 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 557 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 558 return HAL_OK;
mbed_official 532:fe11edbda85c 559 }
mbed_official 532:fe11edbda85c 560 else
mbed_official 532:fe11edbda85c 561 {
mbed_official 532:fe11edbda85c 562 return HAL_BUSY;
mbed_official 532:fe11edbda85c 563 }
mbed_official 532:fe11edbda85c 564 }
mbed_official 532:fe11edbda85c 565
mbed_official 532:fe11edbda85c 566 /**
mbed_official 532:fe11edbda85c 567 * @brief Send data in interrupt mode
mbed_official 532:fe11edbda85c 568 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 569 * @param DestinationAddress: destination logical address
mbed_official 532:fe11edbda85c 570 * @param pData: pointer to input byte data buffer
mbed_official 532:fe11edbda85c 571 * @param Size: amount of data to be sent in bytes (without counting the header).
mbed_official 532:fe11edbda85c 572 * 0 means only the header is sent (ping operation).
mbed_official 532:fe11edbda85c 573 * Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
mbed_official 532:fe11edbda85c 574 * @retval HAL status
mbed_official 532:fe11edbda85c 575 */
mbed_official 532:fe11edbda85c 576 HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size)
mbed_official 532:fe11edbda85c 577 {
mbed_official 532:fe11edbda85c 578 uint8_t temp = 0;
mbed_official 532:fe11edbda85c 579 /* if the IP isn't already busy and if there is no previous transmission
mbed_official 532:fe11edbda85c 580 already pending due to arbitration lost */
mbed_official 532:fe11edbda85c 581 if (((hcec->State == HAL_CEC_STATE_READY) || (hcec->State == HAL_CEC_STATE_STANDBY_RX))
mbed_official 532:fe11edbda85c 582 && (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) == RESET))
mbed_official 532:fe11edbda85c 583 {
mbed_official 532:fe11edbda85c 584 if((pData == NULL) && (Size > 0))
mbed_official 532:fe11edbda85c 585 {
mbed_official 532:fe11edbda85c 586 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 587 return HAL_ERROR;
mbed_official 532:fe11edbda85c 588 }
mbed_official 532:fe11edbda85c 589
mbed_official 532:fe11edbda85c 590 assert_param(IS_CEC_ADDRESS(DestinationAddress));
mbed_official 532:fe11edbda85c 591 assert_param(IS_CEC_MSGSIZE(Size));
mbed_official 532:fe11edbda85c 592
mbed_official 532:fe11edbda85c 593 /* Process Locked */
mbed_official 532:fe11edbda85c 594 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 595 hcec->pTxBuffPtr = pData;
mbed_official 532:fe11edbda85c 596 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 532:fe11edbda85c 597 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 532:fe11edbda85c 598
mbed_official 532:fe11edbda85c 599 /* Disable Peripheral to write CEC_IER register */
mbed_official 532:fe11edbda85c 600 __HAL_CEC_DISABLE(hcec);
mbed_official 532:fe11edbda85c 601
mbed_official 532:fe11edbda85c 602 /* Enable the following two CEC Transmission interrupts as
mbed_official 532:fe11edbda85c 603 * well as the following CEC Transmission Errors interrupts:
mbed_official 532:fe11edbda85c 604 * Tx Byte Request IT
mbed_official 532:fe11edbda85c 605 * End of Transmission IT
mbed_official 532:fe11edbda85c 606 * Tx Missing Acknowledge IT
mbed_official 532:fe11edbda85c 607 * Tx-Error IT
mbed_official 532:fe11edbda85c 608 * Tx-Buffer Underrun IT
mbed_official 532:fe11edbda85c 609 * Tx arbitration lost */
mbed_official 532:fe11edbda85c 610 __HAL_CEC_ENABLE_IT(hcec, CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
mbed_official 532:fe11edbda85c 611
mbed_official 532:fe11edbda85c 612 /* Enable the Peripheral */
mbed_official 532:fe11edbda85c 613 __HAL_CEC_ENABLE(hcec);
mbed_official 532:fe11edbda85c 614
mbed_official 532:fe11edbda85c 615 /* initialize the number of bytes to send,
mbed_official 532:fe11edbda85c 616 * 0 means only one header is sent (ping operation) */
mbed_official 532:fe11edbda85c 617 hcec->TxXferCount = Size;
mbed_official 532:fe11edbda85c 618
mbed_official 532:fe11edbda85c 619 /* Process Unlocked */
mbed_official 532:fe11edbda85c 620 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 621
mbed_official 532:fe11edbda85c 622 /* in case of no payload (Size = 0), sender is only pinging the system;
mbed_official 532:fe11edbda85c 623 * Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */
mbed_official 532:fe11edbda85c 624 if (Size == 0)
mbed_official 532:fe11edbda85c 625 {
mbed_official 532:fe11edbda85c 626 __HAL_CEC_LAST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 627 }
mbed_official 532:fe11edbda85c 628
mbed_official 532:fe11edbda85c 629 /* send header block */
mbed_official 532:fe11edbda85c 630 temp = (uint8_t)((uint32_t)(hcec->Init.InitiatorAddress) << CEC_INITIATOR_LSB_POS) | DestinationAddress;
mbed_official 532:fe11edbda85c 631 hcec->Instance->TXDR = temp;
mbed_official 532:fe11edbda85c 632 /* Set TX Start of Message (TXSOM) bit */
mbed_official 532:fe11edbda85c 633 __HAL_CEC_FIRST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 634
mbed_official 532:fe11edbda85c 635 return HAL_OK;
mbed_official 532:fe11edbda85c 636 }
mbed_official 532:fe11edbda85c 637 /* if the IP is already busy or if there is a previous transmission
mbed_official 532:fe11edbda85c 638 already pending due to arbitration loss */
mbed_official 532:fe11edbda85c 639 else if ((hcec->State == HAL_CEC_STATE_BUSY_TX)
mbed_official 532:fe11edbda85c 640 || (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) != RESET))
mbed_official 532:fe11edbda85c 641 {
mbed_official 532:fe11edbda85c 642 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 643 /* set state to BUSY TX, in case it wasn't set already (case
mbed_official 532:fe11edbda85c 644 * of transmission new attempt after arbitration loss) */
mbed_official 532:fe11edbda85c 645 if (hcec->State != HAL_CEC_STATE_BUSY_TX)
mbed_official 532:fe11edbda85c 646 {
mbed_official 532:fe11edbda85c 647 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 532:fe11edbda85c 648 }
mbed_official 532:fe11edbda85c 649
mbed_official 532:fe11edbda85c 650 /* if all data have been sent */
mbed_official 532:fe11edbda85c 651 if(hcec->TxXferCount == 0)
mbed_official 532:fe11edbda85c 652 {
mbed_official 532:fe11edbda85c 653 /* Disable Peripheral to write CEC_IER register */
mbed_official 532:fe11edbda85c 654 __HAL_CEC_DISABLE(hcec);
mbed_official 532:fe11edbda85c 655
mbed_official 532:fe11edbda85c 656 /* Disable the CEC Transmission Interrupts */
mbed_official 532:fe11edbda85c 657 __HAL_CEC_DISABLE_IT(hcec, CEC_IT_TXBR|CEC_IT_TXEND);
mbed_official 532:fe11edbda85c 658 /* Disable the CEC Transmission Error Interrupts */
mbed_official 532:fe11edbda85c 659 __HAL_CEC_DISABLE_IT(hcec, CEC_IER_TX_ALL_ERR);
mbed_official 532:fe11edbda85c 660
mbed_official 532:fe11edbda85c 661 /* Enable the Peripheral */
mbed_official 532:fe11edbda85c 662 __HAL_CEC_ENABLE(hcec);
mbed_official 532:fe11edbda85c 663
mbed_official 532:fe11edbda85c 664 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXBR|CEC_FLAG_TXEND);
mbed_official 532:fe11edbda85c 665
mbed_official 532:fe11edbda85c 666 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 667 /* Call the Process Unlocked before calling the Tx call back API to give the possibility to
mbed_official 532:fe11edbda85c 668 start again the Transmission under the Tx call back API */
mbed_official 532:fe11edbda85c 669 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 670
mbed_official 532:fe11edbda85c 671 HAL_CEC_TxCpltCallback(hcec);
mbed_official 532:fe11edbda85c 672
mbed_official 532:fe11edbda85c 673 return HAL_OK;
mbed_official 532:fe11edbda85c 674 }
mbed_official 532:fe11edbda85c 675 else
mbed_official 532:fe11edbda85c 676 {
mbed_official 532:fe11edbda85c 677 if (hcec->TxXferCount == 1)
mbed_official 532:fe11edbda85c 678 {
mbed_official 532:fe11edbda85c 679 /* if this is the last byte transmission, set TX End of Message (TXEOM) bit */
mbed_official 532:fe11edbda85c 680 __HAL_CEC_LAST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 681 }
mbed_official 532:fe11edbda85c 682 /* clear Tx-Byte request flag */
mbed_official 532:fe11edbda85c 683 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXBR);
mbed_official 532:fe11edbda85c 684 hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
mbed_official 532:fe11edbda85c 685 hcec->TxXferCount--;
mbed_official 532:fe11edbda85c 686
mbed_official 532:fe11edbda85c 687 /* Process Unlocked */
mbed_official 532:fe11edbda85c 688 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 689
mbed_official 532:fe11edbda85c 690 return HAL_OK;
mbed_official 532:fe11edbda85c 691 }
mbed_official 532:fe11edbda85c 692 }
mbed_official 532:fe11edbda85c 693 else
mbed_official 532:fe11edbda85c 694 {
mbed_official 532:fe11edbda85c 695 return HAL_BUSY;
mbed_official 532:fe11edbda85c 696 }
mbed_official 532:fe11edbda85c 697 }
mbed_official 532:fe11edbda85c 698
mbed_official 532:fe11edbda85c 699 /**
mbed_official 532:fe11edbda85c 700 * @brief Receive data in interrupt mode.
mbed_official 532:fe11edbda85c 701 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 702 * @param pData: pointer to received data buffer.
mbed_official 532:fe11edbda85c 703 * Note that the received data size is not known beforehand, the latter is known
mbed_official 532:fe11edbda85c 704 * when the reception is complete and is stored in hcec->RxXferSize.
mbed_official 532:fe11edbda85c 705 * hcec->RxXferSize is the sum of opcodes + operands (0 to 14 operands max).
mbed_official 532:fe11edbda85c 706 * If only a header is received, hcec->RxXferSize = 0
mbed_official 532:fe11edbda85c 707 * @retval HAL status
mbed_official 532:fe11edbda85c 708 */
mbed_official 532:fe11edbda85c 709 HAL_StatusTypeDef HAL_CEC_Receive_IT(CEC_HandleTypeDef *hcec, uint8_t *pData)
mbed_official 532:fe11edbda85c 710 {
mbed_official 532:fe11edbda85c 711 if(hcec->State == HAL_CEC_STATE_READY)
mbed_official 532:fe11edbda85c 712 {
mbed_official 532:fe11edbda85c 713 if(pData == NULL)
mbed_official 532:fe11edbda85c 714 {
mbed_official 532:fe11edbda85c 715 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 716 return HAL_ERROR;
mbed_official 532:fe11edbda85c 717 }
mbed_official 532:fe11edbda85c 718
mbed_official 532:fe11edbda85c 719 /* Process Locked */
mbed_official 532:fe11edbda85c 720 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 721 hcec->RxXferSize = 0;
mbed_official 532:fe11edbda85c 722 hcec->pRxBuffPtr = pData;
mbed_official 532:fe11edbda85c 723 hcec->ErrorCode = HAL_CEC_ERROR_NONE;
mbed_official 532:fe11edbda85c 724 /* the IP is moving to a ready to receive state */
mbed_official 532:fe11edbda85c 725 hcec->State = HAL_CEC_STATE_STANDBY_RX;
mbed_official 532:fe11edbda85c 726
mbed_official 532:fe11edbda85c 727 /* Disable Peripheral to write CEC_IER register */
mbed_official 532:fe11edbda85c 728 __HAL_CEC_DISABLE(hcec);
mbed_official 532:fe11edbda85c 729
mbed_official 532:fe11edbda85c 730 /* Enable the following CEC Reception Error Interrupts:
mbed_official 532:fe11edbda85c 731 * Rx overrun
mbed_official 532:fe11edbda85c 732 * Rx bit rising error
mbed_official 532:fe11edbda85c 733 * Rx short bit period error
mbed_official 532:fe11edbda85c 734 * Rx long bit period error
mbed_official 532:fe11edbda85c 735 * Rx missing acknowledge */
mbed_official 532:fe11edbda85c 736 __HAL_CEC_ENABLE_IT(hcec, CEC_IER_RX_ALL_ERR);
mbed_official 532:fe11edbda85c 737
mbed_official 532:fe11edbda85c 738 /* Process Unlocked */
mbed_official 532:fe11edbda85c 739 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 740
mbed_official 532:fe11edbda85c 741 /* Enable the following two CEC Reception interrupts:
mbed_official 532:fe11edbda85c 742 * Rx Byte Received IT
mbed_official 532:fe11edbda85c 743 * End of Reception IT */
mbed_official 532:fe11edbda85c 744 __HAL_CEC_ENABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND);
mbed_official 532:fe11edbda85c 745
mbed_official 532:fe11edbda85c 746 __HAL_CEC_ENABLE(hcec);
mbed_official 532:fe11edbda85c 747
mbed_official 532:fe11edbda85c 748 return HAL_OK;
mbed_official 532:fe11edbda85c 749 }
mbed_official 532:fe11edbda85c 750 else
mbed_official 532:fe11edbda85c 751 {
mbed_official 532:fe11edbda85c 752 return HAL_BUSY;
mbed_official 532:fe11edbda85c 753 }
mbed_official 532:fe11edbda85c 754 }
mbed_official 532:fe11edbda85c 755
mbed_official 532:fe11edbda85c 756 /**
mbed_official 532:fe11edbda85c 757 * @brief Get size of the received frame.
mbed_official 532:fe11edbda85c 758 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 759 * @retval Frame size
mbed_official 532:fe11edbda85c 760 */
mbed_official 532:fe11edbda85c 761 uint32_t HAL_CEC_GetReceivedFrameSize(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 762 {
mbed_official 532:fe11edbda85c 763 return hcec->RxXferSize;
mbed_official 532:fe11edbda85c 764 }
mbed_official 532:fe11edbda85c 765
mbed_official 532:fe11edbda85c 766 /**
mbed_official 532:fe11edbda85c 767 * @brief This function handles CEC interrupt requests.
mbed_official 532:fe11edbda85c 768 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 769 * @retval None
mbed_official 532:fe11edbda85c 770 */
mbed_official 532:fe11edbda85c 771 void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 772 {
mbed_official 532:fe11edbda85c 773 /* save interrupts register for further error or interrupts handling purposes */
mbed_official 532:fe11edbda85c 774 hcec->ErrorCode = hcec->Instance->ISR;
mbed_official 532:fe11edbda85c 775 /* CEC TX missing acknowledge error interrupt occurred -------------------------------------*/
mbed_official 532:fe11edbda85c 776 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TXACKE) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_TXACKE) != RESET))
mbed_official 532:fe11edbda85c 777 {
mbed_official 532:fe11edbda85c 778 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXACKE);
mbed_official 532:fe11edbda85c 779 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 780 }
mbed_official 532:fe11edbda85c 781
mbed_official 532:fe11edbda85c 782 /* CEC transmit error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 783 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TXERR) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_TXERR) != RESET))
mbed_official 532:fe11edbda85c 784 {
mbed_official 532:fe11edbda85c 785 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXERR);
mbed_official 532:fe11edbda85c 786 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 787 }
mbed_official 532:fe11edbda85c 788
mbed_official 532:fe11edbda85c 789 /* CEC TX underrun error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 790 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TXUDR) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_TXUDR) != RESET))
mbed_official 532:fe11edbda85c 791 {
mbed_official 532:fe11edbda85c 792 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXUDR);
mbed_official 532:fe11edbda85c 793 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 794 }
mbed_official 532:fe11edbda85c 795
mbed_official 532:fe11edbda85c 796 /* CEC TX arbitration error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 797 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_ARBLST) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_ARBLST) != RESET))
mbed_official 532:fe11edbda85c 798 {
mbed_official 532:fe11edbda85c 799 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST);
mbed_official 532:fe11edbda85c 800 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 801 }
mbed_official 532:fe11edbda85c 802
mbed_official 532:fe11edbda85c 803 /* CEC RX overrun error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 804 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RXOVR) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_RXOVR) != RESET))
mbed_official 532:fe11edbda85c 805 {
mbed_official 532:fe11edbda85c 806 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXOVR);
mbed_official 532:fe11edbda85c 807 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 808 }
mbed_official 532:fe11edbda85c 809
mbed_official 532:fe11edbda85c 810 /* CEC RX bit rising error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 811 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_BRE) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_BRE) != RESET))
mbed_official 532:fe11edbda85c 812 {
mbed_official 532:fe11edbda85c 813 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_BRE);
mbed_official 532:fe11edbda85c 814 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 815 }
mbed_official 532:fe11edbda85c 816
mbed_official 532:fe11edbda85c 817 /* CEC RX short bit period error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 818 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_SBPE) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_SBPE) != RESET))
mbed_official 532:fe11edbda85c 819 {
mbed_official 532:fe11edbda85c 820 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_SBPE);
mbed_official 532:fe11edbda85c 821 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 822 }
mbed_official 532:fe11edbda85c 823
mbed_official 532:fe11edbda85c 824 /* CEC RX long bit period error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 825 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_LBPE) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_LBPE) != RESET))
mbed_official 532:fe11edbda85c 826 {
mbed_official 532:fe11edbda85c 827 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_LBPE);
mbed_official 532:fe11edbda85c 828 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 829 }
mbed_official 532:fe11edbda85c 830
mbed_official 532:fe11edbda85c 831 /* CEC RX missing acknowledge error interrupt occured --------------------------------------*/
mbed_official 532:fe11edbda85c 832 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RXACKE) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_RXACKE) != RESET))
mbed_official 532:fe11edbda85c 833 {
mbed_official 532:fe11edbda85c 834 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXACKE);
mbed_official 532:fe11edbda85c 835 hcec->State = HAL_CEC_STATE_ERROR;
mbed_official 532:fe11edbda85c 836 }
mbed_official 532:fe11edbda85c 837
mbed_official 532:fe11edbda85c 838 if ((hcec->ErrorCode & CEC_ISR_ALL_ERROR) != 0)
mbed_official 532:fe11edbda85c 839 {
mbed_official 532:fe11edbda85c 840 HAL_CEC_ErrorCallback(hcec);
mbed_official 532:fe11edbda85c 841 }
mbed_official 532:fe11edbda85c 842
mbed_official 532:fe11edbda85c 843 /* CEC RX byte received interrupt ---------------------------------------------------*/
mbed_official 532:fe11edbda85c 844 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RXBR) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_RXBR) != RESET))
mbed_official 532:fe11edbda85c 845 {
mbed_official 532:fe11edbda85c 846 /* RXBR IT is cleared during HAL_CEC_Transmit_IT processing */
mbed_official 532:fe11edbda85c 847 CEC_Receive_IT(hcec);
mbed_official 532:fe11edbda85c 848 }
mbed_official 532:fe11edbda85c 849
mbed_official 532:fe11edbda85c 850 /* CEC RX end received interrupt ---------------------------------------------------*/
mbed_official 532:fe11edbda85c 851 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RXEND) != RESET) && (__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_RXEND) != RESET))
mbed_official 532:fe11edbda85c 852 {
mbed_official 532:fe11edbda85c 853 /* RXBR IT is cleared during HAL_CEC_Transmit_IT processing */
mbed_official 532:fe11edbda85c 854 CEC_Receive_IT(hcec);
mbed_official 532:fe11edbda85c 855 }
mbed_official 532:fe11edbda85c 856
mbed_official 532:fe11edbda85c 857
mbed_official 532:fe11edbda85c 858 /* CEC TX byte request interrupt ------------------------------------------------*/
mbed_official 532:fe11edbda85c 859 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TXBR) != RESET) &&(__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_TXBR) != RESET))
mbed_official 532:fe11edbda85c 860 {
mbed_official 532:fe11edbda85c 861 /* TXBR IT is cleared during HAL_CEC_Transmit_IT processing */
mbed_official 532:fe11edbda85c 862 CEC_Transmit_IT(hcec);
mbed_official 532:fe11edbda85c 863 }
mbed_official 532:fe11edbda85c 864
mbed_official 532:fe11edbda85c 865 /* CEC TX end interrupt ------------------------------------------------*/
mbed_official 532:fe11edbda85c 866 if((__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TXEND) != RESET) &&(__HAL_CEC_GET_IT_SOURCE(hcec, CEC_IT_TXEND) != RESET))
mbed_official 532:fe11edbda85c 867 {
mbed_official 532:fe11edbda85c 868 /* TXEND IT is cleared during HAL_CEC_Transmit_IT processing */
mbed_official 532:fe11edbda85c 869 CEC_Transmit_IT(hcec);
mbed_official 532:fe11edbda85c 870 }
mbed_official 532:fe11edbda85c 871 }
mbed_official 532:fe11edbda85c 872
mbed_official 532:fe11edbda85c 873 /**
mbed_official 532:fe11edbda85c 874 * @brief Tx Transfer completed callback
mbed_official 532:fe11edbda85c 875 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 876 * @retval None
mbed_official 532:fe11edbda85c 877 */
mbed_official 532:fe11edbda85c 878 __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 879 {
mbed_official 532:fe11edbda85c 880 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 881 the HAL_CEC_TxCpltCallback can be implemented in the user file
mbed_official 532:fe11edbda85c 882 */
mbed_official 532:fe11edbda85c 883 }
mbed_official 532:fe11edbda85c 884
mbed_official 532:fe11edbda85c 885 /**
mbed_official 532:fe11edbda85c 886 * @brief Rx Transfer completed callback
mbed_official 532:fe11edbda85c 887 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 888 * @retval None
mbed_official 532:fe11edbda85c 889 */
mbed_official 532:fe11edbda85c 890 __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 891 {
mbed_official 532:fe11edbda85c 892 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 893 the HAL_CEC_TxCpltCallback can be implemented in the user file
mbed_official 532:fe11edbda85c 894 */
mbed_official 532:fe11edbda85c 895 }
mbed_official 532:fe11edbda85c 896
mbed_official 532:fe11edbda85c 897 /**
mbed_official 532:fe11edbda85c 898 * @brief CEC error callbacks
mbed_official 532:fe11edbda85c 899 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 900 * @retval None
mbed_official 532:fe11edbda85c 901 */
mbed_official 532:fe11edbda85c 902 __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 903 {
mbed_official 532:fe11edbda85c 904 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 905 the HAL_CEC_ErrorCallback can be implemented in the user file
mbed_official 532:fe11edbda85c 906 */
mbed_official 532:fe11edbda85c 907 }
mbed_official 532:fe11edbda85c 908 /**
mbed_official 532:fe11edbda85c 909 * @}
mbed_official 532:fe11edbda85c 910 */
mbed_official 532:fe11edbda85c 911
mbed_official 532:fe11edbda85c 912 /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control function
mbed_official 532:fe11edbda85c 913 * @brief CEC control functions
mbed_official 532:fe11edbda85c 914 *
mbed_official 532:fe11edbda85c 915 @verbatim
mbed_official 532:fe11edbda85c 916 ===============================================================================
mbed_official 532:fe11edbda85c 917 ##### Peripheral Control function #####
mbed_official 532:fe11edbda85c 918 ===============================================================================
mbed_official 532:fe11edbda85c 919 [..]
mbed_official 532:fe11edbda85c 920 This subsection provides a set of functions allowing to control the CEC.
mbed_official 532:fe11edbda85c 921 (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral.
mbed_official 532:fe11edbda85c 922 @endverbatim
mbed_official 532:fe11edbda85c 923 * @{
mbed_official 532:fe11edbda85c 924 */
mbed_official 532:fe11edbda85c 925 /**
mbed_official 532:fe11edbda85c 926 * @brief return the CEC state
mbed_official 532:fe11edbda85c 927 * @param hcec: CEC handle
mbed_official 532:fe11edbda85c 928 * @retval HAL state
mbed_official 532:fe11edbda85c 929 */
mbed_official 532:fe11edbda85c 930 HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 931 {
mbed_official 532:fe11edbda85c 932 return hcec->State;
mbed_official 532:fe11edbda85c 933 }
mbed_official 532:fe11edbda85c 934
mbed_official 532:fe11edbda85c 935 /**
mbed_official 532:fe11edbda85c 936 * @brief Return the CEC error code
mbed_official 532:fe11edbda85c 937 * @param hcec : pointer to a CEC_HandleTypeDef structure that contains
mbed_official 532:fe11edbda85c 938 * the configuration information for the specified CEC.
mbed_official 532:fe11edbda85c 939 * @retval CEC Error Code
mbed_official 532:fe11edbda85c 940 */
mbed_official 532:fe11edbda85c 941 uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 942 {
mbed_official 532:fe11edbda85c 943 return hcec->ErrorCode;
mbed_official 532:fe11edbda85c 944 }
mbed_official 532:fe11edbda85c 945
mbed_official 532:fe11edbda85c 946 /**
mbed_official 532:fe11edbda85c 947 * @}
mbed_official 532:fe11edbda85c 948 */
mbed_official 532:fe11edbda85c 949
mbed_official 532:fe11edbda85c 950 /**
mbed_official 532:fe11edbda85c 951 * @brief Send data in interrupt mode
mbed_official 532:fe11edbda85c 952 * @param hcec: CEC handle.
mbed_official 532:fe11edbda85c 953 * Function called under interruption only, once
mbed_official 532:fe11edbda85c 954 * interruptions have been enabled by HAL_CEC_Transmit_IT()
mbed_official 532:fe11edbda85c 955 * @retval HAL status
mbed_official 532:fe11edbda85c 956 */
mbed_official 532:fe11edbda85c 957 static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 958 {
mbed_official 532:fe11edbda85c 959 /* if the IP is already busy or if there is a previous transmission
mbed_official 532:fe11edbda85c 960 already pending due to arbitration loss */
mbed_official 532:fe11edbda85c 961 if ((hcec->State == HAL_CEC_STATE_BUSY_TX)
mbed_official 532:fe11edbda85c 962 || (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) != RESET))
mbed_official 532:fe11edbda85c 963 {
mbed_official 532:fe11edbda85c 964 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 965 /* set state to BUSY TX, in case it wasn't set already (case
mbed_official 532:fe11edbda85c 966 * of transmission new attempt after arbitration loss) */
mbed_official 532:fe11edbda85c 967 if (hcec->State != HAL_CEC_STATE_BUSY_TX)
mbed_official 532:fe11edbda85c 968 {
mbed_official 532:fe11edbda85c 969 hcec->State = HAL_CEC_STATE_BUSY_TX;
mbed_official 532:fe11edbda85c 970 }
mbed_official 532:fe11edbda85c 971
mbed_official 532:fe11edbda85c 972 /* if all data have been sent */
mbed_official 532:fe11edbda85c 973 if(hcec->TxXferCount == 0)
mbed_official 532:fe11edbda85c 974 {
mbed_official 532:fe11edbda85c 975 /* Disable Peripheral to write CEC_IER register */
mbed_official 532:fe11edbda85c 976 __HAL_CEC_DISABLE(hcec);
mbed_official 532:fe11edbda85c 977
mbed_official 532:fe11edbda85c 978 /* Disable the CEC Transmission Interrupts */
mbed_official 532:fe11edbda85c 979 __HAL_CEC_DISABLE_IT(hcec, CEC_IT_TXBR|CEC_IT_TXEND);
mbed_official 532:fe11edbda85c 980 /* Disable the CEC Transmission Error Interrupts */
mbed_official 532:fe11edbda85c 981 __HAL_CEC_DISABLE_IT(hcec, CEC_IER_TX_ALL_ERR);
mbed_official 532:fe11edbda85c 982
mbed_official 532:fe11edbda85c 983 /* Enable the Peripheral */
mbed_official 532:fe11edbda85c 984 __HAL_CEC_ENABLE(hcec);
mbed_official 532:fe11edbda85c 985
mbed_official 532:fe11edbda85c 986 __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR|CEC_FLAG_TXEND);
mbed_official 532:fe11edbda85c 987
mbed_official 532:fe11edbda85c 988 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 989 /* Call the Process Unlocked before calling the Tx call back API to give the possibility to
mbed_official 532:fe11edbda85c 990 start again the Transmission under the Tx call back API */
mbed_official 532:fe11edbda85c 991 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 992
mbed_official 532:fe11edbda85c 993 HAL_CEC_TxCpltCallback(hcec);
mbed_official 532:fe11edbda85c 994
mbed_official 532:fe11edbda85c 995 return HAL_OK;
mbed_official 532:fe11edbda85c 996 }
mbed_official 532:fe11edbda85c 997 else
mbed_official 532:fe11edbda85c 998 {
mbed_official 532:fe11edbda85c 999 if (hcec->TxXferCount == 1)
mbed_official 532:fe11edbda85c 1000 {
mbed_official 532:fe11edbda85c 1001 /* if this is the last byte transmission, set TX End of Message (TXEOM) bit */
mbed_official 532:fe11edbda85c 1002 __HAL_CEC_LAST_BYTE_TX_SET(hcec);
mbed_official 532:fe11edbda85c 1003 }
mbed_official 532:fe11edbda85c 1004 /* clear Tx-Byte request flag */
mbed_official 532:fe11edbda85c 1005 __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR);
mbed_official 532:fe11edbda85c 1006 hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
mbed_official 532:fe11edbda85c 1007 hcec->TxXferCount--;
mbed_official 532:fe11edbda85c 1008
mbed_official 532:fe11edbda85c 1009 /* Process Unlocked */
mbed_official 532:fe11edbda85c 1010 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 1011
mbed_official 532:fe11edbda85c 1012 return HAL_OK;
mbed_official 532:fe11edbda85c 1013 }
mbed_official 532:fe11edbda85c 1014 }
mbed_official 532:fe11edbda85c 1015 else
mbed_official 532:fe11edbda85c 1016 {
mbed_official 532:fe11edbda85c 1017 return HAL_BUSY;
mbed_official 532:fe11edbda85c 1018 }
mbed_official 532:fe11edbda85c 1019 }
mbed_official 532:fe11edbda85c 1020
mbed_official 532:fe11edbda85c 1021
mbed_official 532:fe11edbda85c 1022 /**
mbed_official 532:fe11edbda85c 1023 * @brief Receive data in interrupt mode.
mbed_official 532:fe11edbda85c 1024 * @param hcec: CEC handle.
mbed_official 532:fe11edbda85c 1025 * Function called under interruption only, once
mbed_official 532:fe11edbda85c 1026 * interruptions have been enabled by HAL_CEC_Receive_IT()
mbed_official 532:fe11edbda85c 1027 * @retval HAL status
mbed_official 532:fe11edbda85c 1028 */
mbed_official 532:fe11edbda85c 1029 static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec)
mbed_official 532:fe11edbda85c 1030 {
mbed_official 532:fe11edbda85c 1031 uint32_t tempisr;
mbed_official 532:fe11edbda85c 1032
mbed_official 532:fe11edbda85c 1033 /* Three different conditions are tested to carry out the RX IT processing:
mbed_official 532:fe11edbda85c 1034 * - the IP is in reception stand-by (the IP state is HAL_CEC_STATE_STANDBY_RX) and
mbed_official 532:fe11edbda85c 1035 * the reception of the first byte is starting
mbed_official 532:fe11edbda85c 1036 * - a message reception is already on-going (the IP state is HAL_CEC_STATE_BUSY_RX)
mbed_official 532:fe11edbda85c 1037 * and a new byte is being received
mbed_official 532:fe11edbda85c 1038 * - a transmission has just been started (the IP state is HAL_CEC_STATE_BUSY_TX)
mbed_official 532:fe11edbda85c 1039 * but has been interrupted by a new message reception or discarded due to
mbed_official 532:fe11edbda85c 1040 * arbitration loss: the reception of the first or higher priority message
mbed_official 532:fe11edbda85c 1041 * (the arbitration winner) is starting */
mbed_official 532:fe11edbda85c 1042 if ((hcec->State == HAL_CEC_STATE_STANDBY_RX)
mbed_official 532:fe11edbda85c 1043 || (hcec->State == HAL_CEC_STATE_BUSY_RX)
mbed_official 532:fe11edbda85c 1044 || (hcec->State == HAL_CEC_STATE_BUSY_TX))
mbed_official 532:fe11edbda85c 1045 {
mbed_official 532:fe11edbda85c 1046 /* reception is starting */
mbed_official 532:fe11edbda85c 1047 hcec->State = HAL_CEC_STATE_BUSY_RX;
mbed_official 532:fe11edbda85c 1048 tempisr = (uint32_t) (hcec->Instance->ISR);
mbed_official 532:fe11edbda85c 1049 if ((tempisr & CEC_FLAG_RXBR) != 0)
mbed_official 532:fe11edbda85c 1050 {
mbed_official 532:fe11edbda85c 1051 /* Process Locked */
mbed_official 532:fe11edbda85c 1052 __HAL_LOCK(hcec);
mbed_official 532:fe11edbda85c 1053 /* read received byte */
mbed_official 532:fe11edbda85c 1054 *hcec->pRxBuffPtr++ = hcec->Instance->RXDR;
mbed_official 532:fe11edbda85c 1055 /* if last byte has been received */
mbed_official 532:fe11edbda85c 1056 if ((tempisr & CEC_FLAG_RXEND) != 0)
mbed_official 532:fe11edbda85c 1057 {
mbed_official 532:fe11edbda85c 1058 /* clear IT */
mbed_official 532:fe11edbda85c 1059 __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_RXBR|CEC_FLAG_RXEND);
mbed_official 532:fe11edbda85c 1060 /* RX interrupts are not disabled at this point.
mbed_official 532:fe11edbda85c 1061 * Indeed, to disable the IT, the IP must be disabled first
mbed_official 532:fe11edbda85c 1062 * which resets the TXSOM flag. In case of arbitration loss,
mbed_official 532:fe11edbda85c 1063 * this leads to a transmission abort.
mbed_official 532:fe11edbda85c 1064 * Therefore, RX interruptions disabling if so required,
mbed_official 532:fe11edbda85c 1065 * is done in HAL_CEC_RxCpltCallback */
mbed_official 532:fe11edbda85c 1066
mbed_official 532:fe11edbda85c 1067 /* IP state is moved to READY.
mbed_official 532:fe11edbda85c 1068 * If the IP must remain in standby mode to listen
mbed_official 532:fe11edbda85c 1069 * any new message, it is up to HAL_CEC_RxCpltCallback
mbed_official 532:fe11edbda85c 1070 * to move it again to HAL_CEC_STATE_STANDBY_RX */
mbed_official 532:fe11edbda85c 1071 hcec->State = HAL_CEC_STATE_READY;
mbed_official 532:fe11edbda85c 1072
mbed_official 532:fe11edbda85c 1073 /* Call the Process Unlocked before calling the Rx call back API */
mbed_official 532:fe11edbda85c 1074 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 1075 HAL_CEC_RxCpltCallback(hcec);
mbed_official 532:fe11edbda85c 1076
mbed_official 532:fe11edbda85c 1077 return HAL_OK;
mbed_official 532:fe11edbda85c 1078 }
mbed_official 532:fe11edbda85c 1079 __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR);
mbed_official 532:fe11edbda85c 1080
mbed_official 532:fe11edbda85c 1081 hcec->RxXferSize++;
mbed_official 532:fe11edbda85c 1082 /* Process Unlocked */
mbed_official 532:fe11edbda85c 1083 __HAL_UNLOCK(hcec);
mbed_official 532:fe11edbda85c 1084
mbed_official 532:fe11edbda85c 1085 return HAL_OK;
mbed_official 532:fe11edbda85c 1086 }
mbed_official 532:fe11edbda85c 1087 else
mbed_official 532:fe11edbda85c 1088 {
mbed_official 532:fe11edbda85c 1089 return HAL_BUSY;
mbed_official 532:fe11edbda85c 1090 }
mbed_official 532:fe11edbda85c 1091 }
mbed_official 532:fe11edbda85c 1092 else
mbed_official 532:fe11edbda85c 1093 {
mbed_official 532:fe11edbda85c 1094 return HAL_BUSY;
mbed_official 532:fe11edbda85c 1095 }
mbed_official 532:fe11edbda85c 1096 }
mbed_official 532:fe11edbda85c 1097 /**
mbed_official 532:fe11edbda85c 1098 * @}
mbed_official 532:fe11edbda85c 1099 */
mbed_official 532:fe11edbda85c 1100
mbed_official 532:fe11edbda85c 1101 #endif /* STM32F446xx */
mbed_official 532:fe11edbda85c 1102
mbed_official 532:fe11edbda85c 1103 #endif /* HAL_CEC_MODULE_ENABLED */
mbed_official 532:fe11edbda85c 1104 /**
mbed_official 532:fe11edbda85c 1105 * @}
mbed_official 532:fe11edbda85c 1106 */
mbed_official 532:fe11edbda85c 1107
mbed_official 532:fe11edbda85c 1108 /**
mbed_official 532:fe11edbda85c 1109 * @}
mbed_official 532:fe11edbda85c 1110 */
mbed_official 532:fe11edbda85c 1111
mbed_official 532:fe11edbda85c 1112 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/