mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Sep 30 17:00:09 2015 +0100
Revision:
636:a11c0372f0ba
Parent:
631:825f75ca301e
Synchronized with git revision d29c98dae61be0946ddf3a3c641c7726056f9452

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

Added support for SAMW25

Who changed what in which revision?

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