SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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