001
targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_cec.c@0:13413ea9a877, 2022-06-12 (annotated)
- Committer:
- ganlikun
- Date:
- Sun Jun 12 14:02:44 2022 +0000
- Revision:
- 0:13413ea9a877
00
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganlikun | 0:13413ea9a877 | 1 | /** |
ganlikun | 0:13413ea9a877 | 2 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 3 | * @file stm32f4xx_hal_cec.c |
ganlikun | 0:13413ea9a877 | 4 | * @author MCD Application Team |
ganlikun | 0:13413ea9a877 | 5 | * @version V1.7.1 |
ganlikun | 0:13413ea9a877 | 6 | * @date 14-April-2017 |
ganlikun | 0:13413ea9a877 | 7 | * @brief CEC HAL module driver. |
ganlikun | 0:13413ea9a877 | 8 | * This file provides firmware functions to manage the following |
ganlikun | 0:13413ea9a877 | 9 | * functionalities of the High Definition Multimedia Interface |
ganlikun | 0:13413ea9a877 | 10 | * Consumer Electronics Control Peripheral (CEC). |
ganlikun | 0:13413ea9a877 | 11 | * + Initialization and de-initialization functions |
ganlikun | 0:13413ea9a877 | 12 | * + IO operation functions |
ganlikun | 0:13413ea9a877 | 13 | * + Peripheral Control functions |
ganlikun | 0:13413ea9a877 | 14 | * |
ganlikun | 0:13413ea9a877 | 15 | * |
ganlikun | 0:13413ea9a877 | 16 | @verbatim |
ganlikun | 0:13413ea9a877 | 17 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 18 | ##### How to use this driver ##### |
ganlikun | 0:13413ea9a877 | 19 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 20 | [..] |
ganlikun | 0:13413ea9a877 | 21 | The CEC HAL driver can be used as follow: |
ganlikun | 0:13413ea9a877 | 22 | |
ganlikun | 0:13413ea9a877 | 23 | (#) Declare a CEC_HandleTypeDef handle structure. |
ganlikun | 0:13413ea9a877 | 24 | (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API: |
ganlikun | 0:13413ea9a877 | 25 | (##) Enable the CEC interface clock. |
ganlikun | 0:13413ea9a877 | 26 | (##) CEC pins configuration: |
ganlikun | 0:13413ea9a877 | 27 | (+++) Enable the clock for the CEC GPIOs. |
ganlikun | 0:13413ea9a877 | 28 | (+++) Configure these CEC pins as alternate function pull-up. |
ganlikun | 0:13413ea9a877 | 29 | (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT() |
ganlikun | 0:13413ea9a877 | 30 | and HAL_CEC_Receive_IT() APIs): |
ganlikun | 0:13413ea9a877 | 31 | (+++) Configure the CEC interrupt priority. |
ganlikun | 0:13413ea9a877 | 32 | (+++) Enable the NVIC CEC IRQ handle. |
ganlikun | 0:13413ea9a877 | 33 | (+++) The specific CEC interrupts (Transmission complete interrupt, |
ganlikun | 0:13413ea9a877 | 34 | RXNE interrupt and Error Interrupts) will be managed using the macros |
ganlikun | 0:13413ea9a877 | 35 | __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit |
ganlikun | 0:13413ea9a877 | 36 | and receive process. |
ganlikun | 0:13413ea9a877 | 37 | |
ganlikun | 0:13413ea9a877 | 38 | (#) Program the Signal Free Time (SFT) and SFT option, Tolerance, reception stop in |
ganlikun | 0:13413ea9a877 | 39 | in case of Bit Rising Error, Error-Bit generation conditions, device logical |
ganlikun | 0:13413ea9a877 | 40 | address and Listen mode in the hcec Init structure. |
ganlikun | 0:13413ea9a877 | 41 | |
ganlikun | 0:13413ea9a877 | 42 | (#) Initialize the CEC registers by calling the HAL_CEC_Init() API. |
ganlikun | 0:13413ea9a877 | 43 | |
ganlikun | 0:13413ea9a877 | 44 | [..] |
ganlikun | 0:13413ea9a877 | 45 | (@) This API (HAL_CEC_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...) |
ganlikun | 0:13413ea9a877 | 46 | by calling the customed HAL_CEC_MspInit() API. |
ganlikun | 0:13413ea9a877 | 47 | |
ganlikun | 0:13413ea9a877 | 48 | @endverbatim |
ganlikun | 0:13413ea9a877 | 49 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 50 | * @attention |
ganlikun | 0:13413ea9a877 | 51 | * |
ganlikun | 0:13413ea9a877 | 52 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
ganlikun | 0:13413ea9a877 | 53 | * |
ganlikun | 0:13413ea9a877 | 54 | * Redistribution and use in source and binary forms, with or without modification, |
ganlikun | 0:13413ea9a877 | 55 | * are permitted provided that the following conditions are met: |
ganlikun | 0:13413ea9a877 | 56 | * 1. Redistributions of source code must retain the above copyright notice, |
ganlikun | 0:13413ea9a877 | 57 | * this list of conditions and the following disclaimer. |
ganlikun | 0:13413ea9a877 | 58 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ganlikun | 0:13413ea9a877 | 59 | * this list of conditions and the following disclaimer in the documentation |
ganlikun | 0:13413ea9a877 | 60 | * and/or other materials provided with the distribution. |
ganlikun | 0:13413ea9a877 | 61 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ganlikun | 0:13413ea9a877 | 62 | * may be used to endorse or promote products derived from this software |
ganlikun | 0:13413ea9a877 | 63 | * without specific prior written permission. |
ganlikun | 0:13413ea9a877 | 64 | * |
ganlikun | 0:13413ea9a877 | 65 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ganlikun | 0:13413ea9a877 | 66 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ganlikun | 0:13413ea9a877 | 67 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ganlikun | 0:13413ea9a877 | 68 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ganlikun | 0:13413ea9a877 | 69 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ganlikun | 0:13413ea9a877 | 70 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ganlikun | 0:13413ea9a877 | 71 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ganlikun | 0:13413ea9a877 | 72 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ganlikun | 0:13413ea9a877 | 73 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ganlikun | 0:13413ea9a877 | 74 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ganlikun | 0:13413ea9a877 | 75 | * |
ganlikun | 0:13413ea9a877 | 76 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 77 | */ |
ganlikun | 0:13413ea9a877 | 78 | |
ganlikun | 0:13413ea9a877 | 79 | /* Includes ------------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 80 | #include "stm32f4xx_hal.h" |
ganlikun | 0:13413ea9a877 | 81 | |
ganlikun | 0:13413ea9a877 | 82 | /** @addtogroup STM32F4xx_HAL_Driver |
ganlikun | 0:13413ea9a877 | 83 | * @{ |
ganlikun | 0:13413ea9a877 | 84 | */ |
ganlikun | 0:13413ea9a877 | 85 | |
ganlikun | 0:13413ea9a877 | 86 | /** @defgroup CEC CEC |
ganlikun | 0:13413ea9a877 | 87 | * @brief HAL CEC module driver |
ganlikun | 0:13413ea9a877 | 88 | * @{ |
ganlikun | 0:13413ea9a877 | 89 | */ |
ganlikun | 0:13413ea9a877 | 90 | #ifdef HAL_CEC_MODULE_ENABLED |
ganlikun | 0:13413ea9a877 | 91 | |
ganlikun | 0:13413ea9a877 | 92 | #if defined(STM32F446xx) |
ganlikun | 0:13413ea9a877 | 93 | |
ganlikun | 0:13413ea9a877 | 94 | /* Private typedef -----------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 95 | /* Private define ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 96 | /** @defgroup CEC_Private_Constants CEC Private Constants |
ganlikun | 0:13413ea9a877 | 97 | * @{ |
ganlikun | 0:13413ea9a877 | 98 | */ |
ganlikun | 0:13413ea9a877 | 99 | /** |
ganlikun | 0:13413ea9a877 | 100 | * @} |
ganlikun | 0:13413ea9a877 | 101 | */ |
ganlikun | 0:13413ea9a877 | 102 | |
ganlikun | 0:13413ea9a877 | 103 | /* Private macro -------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 104 | /* Private variables ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 105 | /* Private function prototypes -----------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 106 | /** @defgroup CEC_Private_Functions CEC Private Functions |
ganlikun | 0:13413ea9a877 | 107 | * @{ |
ganlikun | 0:13413ea9a877 | 108 | */ |
ganlikun | 0:13413ea9a877 | 109 | /** |
ganlikun | 0:13413ea9a877 | 110 | * @} |
ganlikun | 0:13413ea9a877 | 111 | */ |
ganlikun | 0:13413ea9a877 | 112 | |
ganlikun | 0:13413ea9a877 | 113 | /* Exported functions ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 114 | |
ganlikun | 0:13413ea9a877 | 115 | /** @defgroup CEC_Exported_Functions CEC Exported Functions |
ganlikun | 0:13413ea9a877 | 116 | * @{ |
ganlikun | 0:13413ea9a877 | 117 | */ |
ganlikun | 0:13413ea9a877 | 118 | |
ganlikun | 0:13413ea9a877 | 119 | /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions |
ganlikun | 0:13413ea9a877 | 120 | * @brief Initialization and Configuration functions |
ganlikun | 0:13413ea9a877 | 121 | * |
ganlikun | 0:13413ea9a877 | 122 | @verbatim |
ganlikun | 0:13413ea9a877 | 123 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 124 | ##### Initialization and Configuration functions ##### |
ganlikun | 0:13413ea9a877 | 125 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 126 | [..] |
ganlikun | 0:13413ea9a877 | 127 | This subsection provides a set of functions allowing to initialize the CEC |
ganlikun | 0:13413ea9a877 | 128 | (+) The following parameters need to be configured: |
ganlikun | 0:13413ea9a877 | 129 | (++) SignalFreeTime |
ganlikun | 0:13413ea9a877 | 130 | (++) Tolerance |
ganlikun | 0:13413ea9a877 | 131 | (++) BRERxStop (RX stopped or not upon Bit Rising Error) |
ganlikun | 0:13413ea9a877 | 132 | (++) BREErrorBitGen (Error-Bit generation in case of Bit Rising Error) |
ganlikun | 0:13413ea9a877 | 133 | (++) LBPEErrorBitGen (Error-Bit generation in case of Long Bit Period Error) |
ganlikun | 0:13413ea9a877 | 134 | (++) BroadcastMsgNoErrorBitGen (Error-bit generation in case of broadcast message error) |
ganlikun | 0:13413ea9a877 | 135 | (++) SignalFreeTimeOption (SFT Timer start definition) |
ganlikun | 0:13413ea9a877 | 136 | (++) OwnAddress (CEC device address) |
ganlikun | 0:13413ea9a877 | 137 | (++) ListenMode |
ganlikun | 0:13413ea9a877 | 138 | |
ganlikun | 0:13413ea9a877 | 139 | @endverbatim |
ganlikun | 0:13413ea9a877 | 140 | * @{ |
ganlikun | 0:13413ea9a877 | 141 | */ |
ganlikun | 0:13413ea9a877 | 142 | |
ganlikun | 0:13413ea9a877 | 143 | /** |
ganlikun | 0:13413ea9a877 | 144 | * @brief Initializes the CEC mode according to the specified |
ganlikun | 0:13413ea9a877 | 145 | * parameters in the CEC_InitTypeDef and creates the associated handle . |
ganlikun | 0:13413ea9a877 | 146 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 147 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 148 | */ |
ganlikun | 0:13413ea9a877 | 149 | HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 150 | { |
ganlikun | 0:13413ea9a877 | 151 | /* Check the CEC handle allocation */ |
ganlikun | 0:13413ea9a877 | 152 | if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL)) |
ganlikun | 0:13413ea9a877 | 153 | { |
ganlikun | 0:13413ea9a877 | 154 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 155 | } |
ganlikun | 0:13413ea9a877 | 156 | |
ganlikun | 0:13413ea9a877 | 157 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 158 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
ganlikun | 0:13413ea9a877 | 159 | assert_param(IS_CEC_SIGNALFREETIME(hcec->Init.SignalFreeTime)); |
ganlikun | 0:13413ea9a877 | 160 | assert_param(IS_CEC_TOLERANCE(hcec->Init.Tolerance)); |
ganlikun | 0:13413ea9a877 | 161 | assert_param(IS_CEC_BRERXSTOP(hcec->Init.BRERxStop)); |
ganlikun | 0:13413ea9a877 | 162 | assert_param(IS_CEC_BREERRORBITGEN(hcec->Init.BREErrorBitGen)); |
ganlikun | 0:13413ea9a877 | 163 | assert_param(IS_CEC_LBPEERRORBITGEN(hcec->Init.LBPEErrorBitGen)); |
ganlikun | 0:13413ea9a877 | 164 | assert_param(IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(hcec->Init.BroadcastMsgNoErrorBitGen)); |
ganlikun | 0:13413ea9a877 | 165 | assert_param(IS_CEC_SFTOP(hcec->Init.SignalFreeTimeOption)); |
ganlikun | 0:13413ea9a877 | 166 | assert_param(IS_CEC_LISTENING_MODE(hcec->Init.ListenMode)); |
ganlikun | 0:13413ea9a877 | 167 | assert_param(IS_CEC_OWN_ADDRESS(hcec->Init.OwnAddress)); |
ganlikun | 0:13413ea9a877 | 168 | |
ganlikun | 0:13413ea9a877 | 169 | if(hcec->gState == HAL_CEC_STATE_RESET) |
ganlikun | 0:13413ea9a877 | 170 | { |
ganlikun | 0:13413ea9a877 | 171 | /* Allocate lock resource and initialize it */ |
ganlikun | 0:13413ea9a877 | 172 | hcec->Lock = HAL_UNLOCKED; |
ganlikun | 0:13413ea9a877 | 173 | /* Init the low level hardware : GPIO, CLOCK */ |
ganlikun | 0:13413ea9a877 | 174 | HAL_CEC_MspInit(hcec); |
ganlikun | 0:13413ea9a877 | 175 | } |
ganlikun | 0:13413ea9a877 | 176 | hcec->gState = HAL_CEC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 177 | |
ganlikun | 0:13413ea9a877 | 178 | /* Disable the Peripheral */ |
ganlikun | 0:13413ea9a877 | 179 | __HAL_CEC_DISABLE(hcec); |
ganlikun | 0:13413ea9a877 | 180 | |
ganlikun | 0:13413ea9a877 | 181 | /* Write to CEC Control Register */ |
ganlikun | 0:13413ea9a877 | 182 | hcec->Instance->CFGR = hcec->Init.SignalFreeTime | hcec->Init.Tolerance | hcec->Init.BRERxStop|\ |
ganlikun | 0:13413ea9a877 | 183 | hcec->Init.BREErrorBitGen | hcec->Init.LBPEErrorBitGen | hcec->Init.BroadcastMsgNoErrorBitGen |\ |
ganlikun | 0:13413ea9a877 | 184 | hcec->Init.SignalFreeTimeOption |((uint32_t)(hcec->Init.OwnAddress)<<16U) |\ |
ganlikun | 0:13413ea9a877 | 185 | hcec->Init.ListenMode; |
ganlikun | 0:13413ea9a877 | 186 | |
ganlikun | 0:13413ea9a877 | 187 | /* Enable the following CEC Transmission/Reception interrupts as |
ganlikun | 0:13413ea9a877 | 188 | * well as the following CEC Transmission/Reception Errors interrupts |
ganlikun | 0:13413ea9a877 | 189 | * Rx Byte Received IT |
ganlikun | 0:13413ea9a877 | 190 | * End of Reception IT |
ganlikun | 0:13413ea9a877 | 191 | * Rx overrun |
ganlikun | 0:13413ea9a877 | 192 | * Rx bit rising error |
ganlikun | 0:13413ea9a877 | 193 | * Rx short bit period error |
ganlikun | 0:13413ea9a877 | 194 | * Rx long bit period error |
ganlikun | 0:13413ea9a877 | 195 | * Rx missing acknowledge |
ganlikun | 0:13413ea9a877 | 196 | * Tx Byte Request IT |
ganlikun | 0:13413ea9a877 | 197 | * End of Transmission IT |
ganlikun | 0:13413ea9a877 | 198 | * Tx Missing Acknowledge IT |
ganlikun | 0:13413ea9a877 | 199 | * Tx-Error IT |
ganlikun | 0:13413ea9a877 | 200 | * Tx-Buffer Underrun IT |
ganlikun | 0:13413ea9a877 | 201 | * Tx arbitration lost */ |
ganlikun | 0:13413ea9a877 | 202 | __HAL_CEC_ENABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR); |
ganlikun | 0:13413ea9a877 | 203 | |
ganlikun | 0:13413ea9a877 | 204 | /* Enable the CEC Peripheral */ |
ganlikun | 0:13413ea9a877 | 205 | __HAL_CEC_ENABLE(hcec); |
ganlikun | 0:13413ea9a877 | 206 | |
ganlikun | 0:13413ea9a877 | 207 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
ganlikun | 0:13413ea9a877 | 208 | hcec->gState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 209 | hcec->RxState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 210 | |
ganlikun | 0:13413ea9a877 | 211 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 212 | } |
ganlikun | 0:13413ea9a877 | 213 | |
ganlikun | 0:13413ea9a877 | 214 | /** |
ganlikun | 0:13413ea9a877 | 215 | * @brief DeInitializes the CEC peripheral |
ganlikun | 0:13413ea9a877 | 216 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 217 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 218 | */ |
ganlikun | 0:13413ea9a877 | 219 | HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 220 | { |
ganlikun | 0:13413ea9a877 | 221 | /* Check the CEC handle allocation */ |
ganlikun | 0:13413ea9a877 | 222 | if(hcec == NULL) |
ganlikun | 0:13413ea9a877 | 223 | { |
ganlikun | 0:13413ea9a877 | 224 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 225 | } |
ganlikun | 0:13413ea9a877 | 226 | |
ganlikun | 0:13413ea9a877 | 227 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 228 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
ganlikun | 0:13413ea9a877 | 229 | |
ganlikun | 0:13413ea9a877 | 230 | hcec->gState = HAL_CEC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 231 | |
ganlikun | 0:13413ea9a877 | 232 | /* DeInit the low level hardware */ |
ganlikun | 0:13413ea9a877 | 233 | HAL_CEC_MspDeInit(hcec); |
ganlikun | 0:13413ea9a877 | 234 | /* Disable the Peripheral */ |
ganlikun | 0:13413ea9a877 | 235 | __HAL_CEC_DISABLE(hcec); |
ganlikun | 0:13413ea9a877 | 236 | |
ganlikun | 0:13413ea9a877 | 237 | /* Clear Flags */ |
ganlikun | 0:13413ea9a877 | 238 | __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXEND|CEC_FLAG_TXBR|CEC_FLAG_RXBR|CEC_FLAG_RXEND|CEC_ISR_ALL_ERROR); |
ganlikun | 0:13413ea9a877 | 239 | |
ganlikun | 0:13413ea9a877 | 240 | /* Disable the following CEC Transmission/Reception interrupts as |
ganlikun | 0:13413ea9a877 | 241 | * well as the following CEC Transmission/Reception Errors interrupts |
ganlikun | 0:13413ea9a877 | 242 | * Rx Byte Received IT |
ganlikun | 0:13413ea9a877 | 243 | * End of Reception IT |
ganlikun | 0:13413ea9a877 | 244 | * Rx overrun |
ganlikun | 0:13413ea9a877 | 245 | * Rx bit rising error |
ganlikun | 0:13413ea9a877 | 246 | * Rx short bit period error |
ganlikun | 0:13413ea9a877 | 247 | * Rx long bit period error |
ganlikun | 0:13413ea9a877 | 248 | * Rx missing acknowledge |
ganlikun | 0:13413ea9a877 | 249 | * Tx Byte Request IT |
ganlikun | 0:13413ea9a877 | 250 | * End of Transmission IT |
ganlikun | 0:13413ea9a877 | 251 | * Tx Missing Acknowledge IT |
ganlikun | 0:13413ea9a877 | 252 | * Tx-Error IT |
ganlikun | 0:13413ea9a877 | 253 | * Tx-Buffer Underrun IT |
ganlikun | 0:13413ea9a877 | 254 | * Tx arbitration lost */ |
ganlikun | 0:13413ea9a877 | 255 | __HAL_CEC_DISABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR); |
ganlikun | 0:13413ea9a877 | 256 | |
ganlikun | 0:13413ea9a877 | 257 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
ganlikun | 0:13413ea9a877 | 258 | hcec->gState = HAL_CEC_STATE_RESET; |
ganlikun | 0:13413ea9a877 | 259 | hcec->RxState = HAL_CEC_STATE_RESET; |
ganlikun | 0:13413ea9a877 | 260 | |
ganlikun | 0:13413ea9a877 | 261 | /* Process Unlock */ |
ganlikun | 0:13413ea9a877 | 262 | __HAL_UNLOCK(hcec); |
ganlikun | 0:13413ea9a877 | 263 | |
ganlikun | 0:13413ea9a877 | 264 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 265 | } |
ganlikun | 0:13413ea9a877 | 266 | |
ganlikun | 0:13413ea9a877 | 267 | /** |
ganlikun | 0:13413ea9a877 | 268 | * @brief Initializes the Own Address of the CEC device |
ganlikun | 0:13413ea9a877 | 269 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 270 | * @param CEC_OwnAddress: The CEC own address. |
ganlikun | 0:13413ea9a877 | 271 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 272 | */ |
ganlikun | 0:13413ea9a877 | 273 | HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress) |
ganlikun | 0:13413ea9a877 | 274 | { |
ganlikun | 0:13413ea9a877 | 275 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 276 | assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress)); |
ganlikun | 0:13413ea9a877 | 277 | |
ganlikun | 0:13413ea9a877 | 278 | if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY)) |
ganlikun | 0:13413ea9a877 | 279 | { |
ganlikun | 0:13413ea9a877 | 280 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 281 | __HAL_LOCK(hcec); |
ganlikun | 0:13413ea9a877 | 282 | |
ganlikun | 0:13413ea9a877 | 283 | hcec->gState = HAL_CEC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 284 | |
ganlikun | 0:13413ea9a877 | 285 | /* Disable the Peripheral */ |
ganlikun | 0:13413ea9a877 | 286 | __HAL_CEC_DISABLE(hcec); |
ganlikun | 0:13413ea9a877 | 287 | |
ganlikun | 0:13413ea9a877 | 288 | if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE) |
ganlikun | 0:13413ea9a877 | 289 | { |
ganlikun | 0:13413ea9a877 | 290 | hcec->Instance->CFGR |= ((uint32_t)CEC_OwnAddress<<16U); |
ganlikun | 0:13413ea9a877 | 291 | } |
ganlikun | 0:13413ea9a877 | 292 | else |
ganlikun | 0:13413ea9a877 | 293 | { |
ganlikun | 0:13413ea9a877 | 294 | hcec->Instance->CFGR &= ~(CEC_CFGR_OAR); |
ganlikun | 0:13413ea9a877 | 295 | } |
ganlikun | 0:13413ea9a877 | 296 | |
ganlikun | 0:13413ea9a877 | 297 | hcec->gState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 298 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
ganlikun | 0:13413ea9a877 | 299 | |
ganlikun | 0:13413ea9a877 | 300 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 301 | __HAL_UNLOCK(hcec); |
ganlikun | 0:13413ea9a877 | 302 | |
ganlikun | 0:13413ea9a877 | 303 | /* Enable the Peripheral */ |
ganlikun | 0:13413ea9a877 | 304 | __HAL_CEC_ENABLE(hcec); |
ganlikun | 0:13413ea9a877 | 305 | |
ganlikun | 0:13413ea9a877 | 306 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 307 | } |
ganlikun | 0:13413ea9a877 | 308 | else |
ganlikun | 0:13413ea9a877 | 309 | { |
ganlikun | 0:13413ea9a877 | 310 | return HAL_BUSY; |
ganlikun | 0:13413ea9a877 | 311 | } |
ganlikun | 0:13413ea9a877 | 312 | } |
ganlikun | 0:13413ea9a877 | 313 | |
ganlikun | 0:13413ea9a877 | 314 | /** |
ganlikun | 0:13413ea9a877 | 315 | * @brief CEC MSP Init |
ganlikun | 0:13413ea9a877 | 316 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 317 | * @retval None |
ganlikun | 0:13413ea9a877 | 318 | */ |
ganlikun | 0:13413ea9a877 | 319 | __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 320 | { |
ganlikun | 0:13413ea9a877 | 321 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 322 | UNUSED(hcec); |
ganlikun | 0:13413ea9a877 | 323 | /* NOTE : This function should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 324 | the HAL_CEC_MspInit can be implemented in the user file |
ganlikun | 0:13413ea9a877 | 325 | */ |
ganlikun | 0:13413ea9a877 | 326 | } |
ganlikun | 0:13413ea9a877 | 327 | |
ganlikun | 0:13413ea9a877 | 328 | /** |
ganlikun | 0:13413ea9a877 | 329 | * @brief CEC MSP DeInit |
ganlikun | 0:13413ea9a877 | 330 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 331 | * @retval None |
ganlikun | 0:13413ea9a877 | 332 | */ |
ganlikun | 0:13413ea9a877 | 333 | __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 334 | { |
ganlikun | 0:13413ea9a877 | 335 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 336 | UNUSED(hcec); |
ganlikun | 0:13413ea9a877 | 337 | /* NOTE : This function should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 338 | the HAL_CEC_MspDeInit can be implemented in the user file |
ganlikun | 0:13413ea9a877 | 339 | */ |
ganlikun | 0:13413ea9a877 | 340 | } |
ganlikun | 0:13413ea9a877 | 341 | |
ganlikun | 0:13413ea9a877 | 342 | /** |
ganlikun | 0:13413ea9a877 | 343 | * @} |
ganlikun | 0:13413ea9a877 | 344 | */ |
ganlikun | 0:13413ea9a877 | 345 | |
ganlikun | 0:13413ea9a877 | 346 | /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions |
ganlikun | 0:13413ea9a877 | 347 | * @brief CEC Transmit/Receive functions |
ganlikun | 0:13413ea9a877 | 348 | * |
ganlikun | 0:13413ea9a877 | 349 | @verbatim |
ganlikun | 0:13413ea9a877 | 350 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 351 | ##### IO operation functions ##### |
ganlikun | 0:13413ea9a877 | 352 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 353 | This subsection provides a set of functions allowing to manage the CEC data transfers. |
ganlikun | 0:13413ea9a877 | 354 | |
ganlikun | 0:13413ea9a877 | 355 | (#) The CEC handle must contain the initiator (TX side) and the destination (RX side) |
ganlikun | 0:13413ea9a877 | 356 | logical addresses (4-bit long addresses, 0x0F for broadcast messages destination) |
ganlikun | 0:13413ea9a877 | 357 | |
ganlikun | 0:13413ea9a877 | 358 | (#) The communication is performed using Interrupts. |
ganlikun | 0:13413ea9a877 | 359 | These API's return the HAL status. |
ganlikun | 0:13413ea9a877 | 360 | The end of the data processing will be indicated through the |
ganlikun | 0:13413ea9a877 | 361 | dedicated CEC IRQ when using Interrupt mode. |
ganlikun | 0:13413ea9a877 | 362 | The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks |
ganlikun | 0:13413ea9a877 | 363 | will be executed respectivelly at the end of the transmit or Receive process |
ganlikun | 0:13413ea9a877 | 364 | The HAL_CEC_ErrorCallback()user callback will be executed when a communication |
ganlikun | 0:13413ea9a877 | 365 | error is detected |
ganlikun | 0:13413ea9a877 | 366 | |
ganlikun | 0:13413ea9a877 | 367 | (#) API's with Interrupt are : |
ganlikun | 0:13413ea9a877 | 368 | (+) HAL_CEC_Transmit_IT() |
ganlikun | 0:13413ea9a877 | 369 | (+) HAL_CEC_IRQHandler() |
ganlikun | 0:13413ea9a877 | 370 | |
ganlikun | 0:13413ea9a877 | 371 | (#) A set of User Callbacks are provided: |
ganlikun | 0:13413ea9a877 | 372 | (+) HAL_CEC_TxCpltCallback() |
ganlikun | 0:13413ea9a877 | 373 | (+) HAL_CEC_RxCpltCallback() |
ganlikun | 0:13413ea9a877 | 374 | (+) HAL_CEC_ErrorCallback() |
ganlikun | 0:13413ea9a877 | 375 | |
ganlikun | 0:13413ea9a877 | 376 | @endverbatim |
ganlikun | 0:13413ea9a877 | 377 | * @{ |
ganlikun | 0:13413ea9a877 | 378 | */ |
ganlikun | 0:13413ea9a877 | 379 | |
ganlikun | 0:13413ea9a877 | 380 | /** |
ganlikun | 0:13413ea9a877 | 381 | * @brief Send data in interrupt mode |
ganlikun | 0:13413ea9a877 | 382 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 383 | * @param InitiatorAddress: Initiator logical address |
ganlikun | 0:13413ea9a877 | 384 | * @param DestinationAddress: destination logical address |
ganlikun | 0:13413ea9a877 | 385 | * @param pData: pointer to input byte data buffer |
ganlikun | 0:13413ea9a877 | 386 | * @param Size: amount of data to be sent in bytes (without counting the header). |
ganlikun | 0:13413ea9a877 | 387 | * 0 means only the header is sent (ping operation). |
ganlikun | 0:13413ea9a877 | 388 | * Maximum TX size is 15 bytes (1 opcode and up to 14 operands). |
ganlikun | 0:13413ea9a877 | 389 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 390 | */ |
ganlikun | 0:13413ea9a877 | 391 | HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 392 | { |
ganlikun | 0:13413ea9a877 | 393 | /* if the IP isn't already busy and if there is no previous transmission |
ganlikun | 0:13413ea9a877 | 394 | already pending due to arbitration lost */ |
ganlikun | 0:13413ea9a877 | 395 | if (hcec->gState == HAL_CEC_STATE_READY) |
ganlikun | 0:13413ea9a877 | 396 | { |
ganlikun | 0:13413ea9a877 | 397 | if((pData == NULL ) && (Size > 0U)) |
ganlikun | 0:13413ea9a877 | 398 | { |
ganlikun | 0:13413ea9a877 | 399 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 400 | } |
ganlikun | 0:13413ea9a877 | 401 | |
ganlikun | 0:13413ea9a877 | 402 | assert_param(IS_CEC_ADDRESS(DestinationAddress)); |
ganlikun | 0:13413ea9a877 | 403 | assert_param(IS_CEC_ADDRESS(InitiatorAddress)); |
ganlikun | 0:13413ea9a877 | 404 | assert_param(IS_CEC_MSGSIZE(Size)); |
ganlikun | 0:13413ea9a877 | 405 | |
ganlikun | 0:13413ea9a877 | 406 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 407 | __HAL_LOCK(hcec); |
ganlikun | 0:13413ea9a877 | 408 | hcec->pTxBuffPtr = pData; |
ganlikun | 0:13413ea9a877 | 409 | hcec->gState = HAL_CEC_STATE_BUSY_TX; |
ganlikun | 0:13413ea9a877 | 410 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
ganlikun | 0:13413ea9a877 | 411 | |
ganlikun | 0:13413ea9a877 | 412 | /* initialize the number of bytes to send, |
ganlikun | 0:13413ea9a877 | 413 | * 0 means only one header is sent (ping operation) */ |
ganlikun | 0:13413ea9a877 | 414 | hcec->TxXferCount = Size; |
ganlikun | 0:13413ea9a877 | 415 | |
ganlikun | 0:13413ea9a877 | 416 | /* in case of no payload (Size = 0), sender is only pinging the system; |
ganlikun | 0:13413ea9a877 | 417 | Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */ |
ganlikun | 0:13413ea9a877 | 418 | if (Size == 0U) |
ganlikun | 0:13413ea9a877 | 419 | { |
ganlikun | 0:13413ea9a877 | 420 | __HAL_CEC_LAST_BYTE_TX_SET(hcec); |
ganlikun | 0:13413ea9a877 | 421 | } |
ganlikun | 0:13413ea9a877 | 422 | |
ganlikun | 0:13413ea9a877 | 423 | /* send header block */ |
ganlikun | 0:13413ea9a877 | 424 | hcec->Instance->TXDR = ((uint8_t)(InitiatorAddress << CEC_INITIATOR_LSB_POS) |(uint8_t) DestinationAddress); |
ganlikun | 0:13413ea9a877 | 425 | /* Set TX Start of Message (TXSOM) bit */ |
ganlikun | 0:13413ea9a877 | 426 | __HAL_CEC_FIRST_BYTE_TX_SET(hcec); |
ganlikun | 0:13413ea9a877 | 427 | |
ganlikun | 0:13413ea9a877 | 428 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 429 | __HAL_UNLOCK(hcec); |
ganlikun | 0:13413ea9a877 | 430 | |
ganlikun | 0:13413ea9a877 | 431 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 432 | |
ganlikun | 0:13413ea9a877 | 433 | } |
ganlikun | 0:13413ea9a877 | 434 | else |
ganlikun | 0:13413ea9a877 | 435 | { |
ganlikun | 0:13413ea9a877 | 436 | return HAL_BUSY; |
ganlikun | 0:13413ea9a877 | 437 | } |
ganlikun | 0:13413ea9a877 | 438 | } |
ganlikun | 0:13413ea9a877 | 439 | |
ganlikun | 0:13413ea9a877 | 440 | /** |
ganlikun | 0:13413ea9a877 | 441 | * @brief Get size of the received frame. |
ganlikun | 0:13413ea9a877 | 442 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 443 | * @retval Frame size |
ganlikun | 0:13413ea9a877 | 444 | */ |
ganlikun | 0:13413ea9a877 | 445 | uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 446 | { |
ganlikun | 0:13413ea9a877 | 447 | return hcec->RxXferSize; |
ganlikun | 0:13413ea9a877 | 448 | } |
ganlikun | 0:13413ea9a877 | 449 | |
ganlikun | 0:13413ea9a877 | 450 | /** |
ganlikun | 0:13413ea9a877 | 451 | * @brief Change Rx Buffer. |
ganlikun | 0:13413ea9a877 | 452 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 453 | * @param Rxbuffer: Rx Buffer |
ganlikun | 0:13413ea9a877 | 454 | * @note This function can be called only inside the HAL_CEC_RxCpltCallback() |
ganlikun | 0:13413ea9a877 | 455 | * @retval Frame size |
ganlikun | 0:13413ea9a877 | 456 | */ |
ganlikun | 0:13413ea9a877 | 457 | void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer) |
ganlikun | 0:13413ea9a877 | 458 | { |
ganlikun | 0:13413ea9a877 | 459 | hcec->Init.RxBuffer = Rxbuffer; |
ganlikun | 0:13413ea9a877 | 460 | } |
ganlikun | 0:13413ea9a877 | 461 | |
ganlikun | 0:13413ea9a877 | 462 | /** |
ganlikun | 0:13413ea9a877 | 463 | * @brief This function handles CEC interrupt requests. |
ganlikun | 0:13413ea9a877 | 464 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 465 | * @retval None |
ganlikun | 0:13413ea9a877 | 466 | */ |
ganlikun | 0:13413ea9a877 | 467 | void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 468 | { |
ganlikun | 0:13413ea9a877 | 469 | |
ganlikun | 0:13413ea9a877 | 470 | /* save interrupts register for further error or interrupts handling purposes */ |
ganlikun | 0:13413ea9a877 | 471 | uint32_t reg = 0U; |
ganlikun | 0:13413ea9a877 | 472 | reg = hcec->Instance->ISR; |
ganlikun | 0:13413ea9a877 | 473 | |
ganlikun | 0:13413ea9a877 | 474 | |
ganlikun | 0:13413ea9a877 | 475 | /* ----------------------------Arbitration Lost Management----------------------------------*/ |
ganlikun | 0:13413ea9a877 | 476 | /* CEC TX arbitration error interrupt occurred --------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 477 | if((reg & CEC_FLAG_ARBLST) != RESET) |
ganlikun | 0:13413ea9a877 | 478 | { |
ganlikun | 0:13413ea9a877 | 479 | hcec->ErrorCode = HAL_CEC_ERROR_ARBLST; |
ganlikun | 0:13413ea9a877 | 480 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST); |
ganlikun | 0:13413ea9a877 | 481 | } |
ganlikun | 0:13413ea9a877 | 482 | |
ganlikun | 0:13413ea9a877 | 483 | /* ----------------------------Rx Management----------------------------------*/ |
ganlikun | 0:13413ea9a877 | 484 | /* CEC RX byte received interrupt ---------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 485 | if((reg & CEC_FLAG_RXBR) != RESET) |
ganlikun | 0:13413ea9a877 | 486 | { |
ganlikun | 0:13413ea9a877 | 487 | /* reception is starting */ |
ganlikun | 0:13413ea9a877 | 488 | hcec->RxState = HAL_CEC_STATE_BUSY_RX; |
ganlikun | 0:13413ea9a877 | 489 | hcec->RxXferSize++; |
ganlikun | 0:13413ea9a877 | 490 | /* read received byte */ |
ganlikun | 0:13413ea9a877 | 491 | *hcec->Init.RxBuffer++ = hcec->Instance->RXDR; |
ganlikun | 0:13413ea9a877 | 492 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR); |
ganlikun | 0:13413ea9a877 | 493 | } |
ganlikun | 0:13413ea9a877 | 494 | |
ganlikun | 0:13413ea9a877 | 495 | /* CEC RX end received interrupt ---------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 496 | if((reg & CEC_FLAG_RXEND) != RESET) |
ganlikun | 0:13413ea9a877 | 497 | { |
ganlikun | 0:13413ea9a877 | 498 | /* clear IT */ |
ganlikun | 0:13413ea9a877 | 499 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXEND); |
ganlikun | 0:13413ea9a877 | 500 | |
ganlikun | 0:13413ea9a877 | 501 | /* Rx process is completed, restore hcec->RxState to Ready */ |
ganlikun | 0:13413ea9a877 | 502 | hcec->RxState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 503 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
ganlikun | 0:13413ea9a877 | 504 | hcec->Init.RxBuffer -= hcec->RxXferSize; |
ganlikun | 0:13413ea9a877 | 505 | HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize); |
ganlikun | 0:13413ea9a877 | 506 | hcec->RxXferSize = 0U; |
ganlikun | 0:13413ea9a877 | 507 | } |
ganlikun | 0:13413ea9a877 | 508 | |
ganlikun | 0:13413ea9a877 | 509 | /* ----------------------------Tx Management----------------------------------*/ |
ganlikun | 0:13413ea9a877 | 510 | /* CEC TX byte request interrupt ------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 511 | if((reg & CEC_FLAG_TXBR) != RESET) |
ganlikun | 0:13413ea9a877 | 512 | { |
ganlikun | 0:13413ea9a877 | 513 | if (hcec->TxXferCount == 0U) |
ganlikun | 0:13413ea9a877 | 514 | { |
ganlikun | 0:13413ea9a877 | 515 | /* if this is the last byte transmission, set TX End of Message (TXEOM) bit */ |
ganlikun | 0:13413ea9a877 | 516 | __HAL_CEC_LAST_BYTE_TX_SET(hcec); |
ganlikun | 0:13413ea9a877 | 517 | hcec->Instance->TXDR = *hcec->pTxBuffPtr++; |
ganlikun | 0:13413ea9a877 | 518 | } |
ganlikun | 0:13413ea9a877 | 519 | else |
ganlikun | 0:13413ea9a877 | 520 | { |
ganlikun | 0:13413ea9a877 | 521 | hcec->Instance->TXDR = *hcec->pTxBuffPtr++; |
ganlikun | 0:13413ea9a877 | 522 | hcec->TxXferCount--; |
ganlikun | 0:13413ea9a877 | 523 | } |
ganlikun | 0:13413ea9a877 | 524 | /* clear Tx-Byte request flag */ |
ganlikun | 0:13413ea9a877 | 525 | __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR); |
ganlikun | 0:13413ea9a877 | 526 | } |
ganlikun | 0:13413ea9a877 | 527 | |
ganlikun | 0:13413ea9a877 | 528 | /* CEC TX end interrupt ------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 529 | if((reg & CEC_FLAG_TXEND) != RESET) |
ganlikun | 0:13413ea9a877 | 530 | { |
ganlikun | 0:13413ea9a877 | 531 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXEND); |
ganlikun | 0:13413ea9a877 | 532 | |
ganlikun | 0:13413ea9a877 | 533 | /* Tx process is ended, restore hcec->gState to Ready */ |
ganlikun | 0:13413ea9a877 | 534 | hcec->gState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 535 | /* Call the Process Unlocked before calling the Tx call back API to give the possibility to |
ganlikun | 0:13413ea9a877 | 536 | start again the Transmission under the Tx call back API */ |
ganlikun | 0:13413ea9a877 | 537 | __HAL_UNLOCK(hcec); |
ganlikun | 0:13413ea9a877 | 538 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
ganlikun | 0:13413ea9a877 | 539 | HAL_CEC_TxCpltCallback(hcec); |
ganlikun | 0:13413ea9a877 | 540 | } |
ganlikun | 0:13413ea9a877 | 541 | |
ganlikun | 0:13413ea9a877 | 542 | /* ----------------------------Rx/Tx Error Management----------------------------------*/ |
ganlikun | 0:13413ea9a877 | 543 | if ((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE|CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != 0U) |
ganlikun | 0:13413ea9a877 | 544 | { |
ganlikun | 0:13413ea9a877 | 545 | hcec->ErrorCode = reg; |
ganlikun | 0:13413ea9a877 | 546 | __HAL_CEC_CLEAR_FLAG(hcec, HAL_CEC_ERROR_RXOVR|HAL_CEC_ERROR_BRE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|HAL_CEC_ERROR_RXACKE|HAL_CEC_ERROR_TXUDR|HAL_CEC_ERROR_TXERR|HAL_CEC_ERROR_TXACKE); |
ganlikun | 0:13413ea9a877 | 547 | |
ganlikun | 0:13413ea9a877 | 548 | |
ganlikun | 0:13413ea9a877 | 549 | if((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE)) != RESET) |
ganlikun | 0:13413ea9a877 | 550 | { |
ganlikun | 0:13413ea9a877 | 551 | hcec->Init.RxBuffer-=hcec->RxXferSize; |
ganlikun | 0:13413ea9a877 | 552 | hcec->RxXferSize = 0U; |
ganlikun | 0:13413ea9a877 | 553 | hcec->RxState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 554 | } |
ganlikun | 0:13413ea9a877 | 555 | else if (((reg & (CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != RESET) && ((reg & CEC_ISR_ARBLST) == RESET)) |
ganlikun | 0:13413ea9a877 | 556 | { |
ganlikun | 0:13413ea9a877 | 557 | /* Set the CEC state ready to be able to start again the process */ |
ganlikun | 0:13413ea9a877 | 558 | hcec->gState = HAL_CEC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 559 | } |
ganlikun | 0:13413ea9a877 | 560 | |
ganlikun | 0:13413ea9a877 | 561 | /* Error Call Back */ |
ganlikun | 0:13413ea9a877 | 562 | HAL_CEC_ErrorCallback(hcec); |
ganlikun | 0:13413ea9a877 | 563 | } |
ganlikun | 0:13413ea9a877 | 564 | |
ganlikun | 0:13413ea9a877 | 565 | } |
ganlikun | 0:13413ea9a877 | 566 | |
ganlikun | 0:13413ea9a877 | 567 | /** |
ganlikun | 0:13413ea9a877 | 568 | * @brief Tx Transfer completed callback |
ganlikun | 0:13413ea9a877 | 569 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 570 | * @retval None |
ganlikun | 0:13413ea9a877 | 571 | */ |
ganlikun | 0:13413ea9a877 | 572 | __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 573 | { |
ganlikun | 0:13413ea9a877 | 574 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 575 | UNUSED(hcec); |
ganlikun | 0:13413ea9a877 | 576 | /* NOTE : This function should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 577 | the HAL_CEC_TxCpltCallback can be implemented in the user file |
ganlikun | 0:13413ea9a877 | 578 | */ |
ganlikun | 0:13413ea9a877 | 579 | } |
ganlikun | 0:13413ea9a877 | 580 | |
ganlikun | 0:13413ea9a877 | 581 | /** |
ganlikun | 0:13413ea9a877 | 582 | * @brief Rx Transfer completed callback |
ganlikun | 0:13413ea9a877 | 583 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 584 | * @param RxFrameSize: Size of frame |
ganlikun | 0:13413ea9a877 | 585 | * @retval None |
ganlikun | 0:13413ea9a877 | 586 | */ |
ganlikun | 0:13413ea9a877 | 587 | __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize) |
ganlikun | 0:13413ea9a877 | 588 | { |
ganlikun | 0:13413ea9a877 | 589 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 590 | UNUSED(hcec); |
ganlikun | 0:13413ea9a877 | 591 | UNUSED(RxFrameSize); |
ganlikun | 0:13413ea9a877 | 592 | /* NOTE : This function should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 593 | the HAL_CEC_RxCpltCallback can be implemented in the user file |
ganlikun | 0:13413ea9a877 | 594 | */ |
ganlikun | 0:13413ea9a877 | 595 | } |
ganlikun | 0:13413ea9a877 | 596 | |
ganlikun | 0:13413ea9a877 | 597 | /** |
ganlikun | 0:13413ea9a877 | 598 | * @brief CEC error callbacks |
ganlikun | 0:13413ea9a877 | 599 | * @param hcec: CEC handle |
ganlikun | 0:13413ea9a877 | 600 | * @retval None |
ganlikun | 0:13413ea9a877 | 601 | */ |
ganlikun | 0:13413ea9a877 | 602 | __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 603 | { |
ganlikun | 0:13413ea9a877 | 604 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 605 | UNUSED(hcec); |
ganlikun | 0:13413ea9a877 | 606 | /* NOTE : This function should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 607 | the HAL_CEC_ErrorCallback can be implemented in the user file |
ganlikun | 0:13413ea9a877 | 608 | */ |
ganlikun | 0:13413ea9a877 | 609 | } |
ganlikun | 0:13413ea9a877 | 610 | /** |
ganlikun | 0:13413ea9a877 | 611 | * @} |
ganlikun | 0:13413ea9a877 | 612 | */ |
ganlikun | 0:13413ea9a877 | 613 | |
ganlikun | 0:13413ea9a877 | 614 | /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control function |
ganlikun | 0:13413ea9a877 | 615 | * @brief CEC control functions |
ganlikun | 0:13413ea9a877 | 616 | * |
ganlikun | 0:13413ea9a877 | 617 | @verbatim |
ganlikun | 0:13413ea9a877 | 618 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 619 | ##### Peripheral Control function ##### |
ganlikun | 0:13413ea9a877 | 620 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 621 | [..] |
ganlikun | 0:13413ea9a877 | 622 | This subsection provides a set of functions allowing to control the CEC. |
ganlikun | 0:13413ea9a877 | 623 | (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral. |
ganlikun | 0:13413ea9a877 | 624 | (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral. |
ganlikun | 0:13413ea9a877 | 625 | @endverbatim |
ganlikun | 0:13413ea9a877 | 626 | * @{ |
ganlikun | 0:13413ea9a877 | 627 | */ |
ganlikun | 0:13413ea9a877 | 628 | /** |
ganlikun | 0:13413ea9a877 | 629 | * @brief return the CEC state |
ganlikun | 0:13413ea9a877 | 630 | * @param hcec: pointer to a CEC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 631 | * the configuration information for the specified CEC module. |
ganlikun | 0:13413ea9a877 | 632 | * @retval HAL state |
ganlikun | 0:13413ea9a877 | 633 | */ |
ganlikun | 0:13413ea9a877 | 634 | HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 635 | { |
ganlikun | 0:13413ea9a877 | 636 | uint32_t temp1 = 0x00U, temp2 = 0x00U; |
ganlikun | 0:13413ea9a877 | 637 | temp1 = hcec->gState; |
ganlikun | 0:13413ea9a877 | 638 | temp2 = hcec->RxState; |
ganlikun | 0:13413ea9a877 | 639 | |
ganlikun | 0:13413ea9a877 | 640 | return (HAL_CEC_StateTypeDef)(temp1 | temp2); |
ganlikun | 0:13413ea9a877 | 641 | } |
ganlikun | 0:13413ea9a877 | 642 | |
ganlikun | 0:13413ea9a877 | 643 | /** |
ganlikun | 0:13413ea9a877 | 644 | * @brief Return the CEC error code |
ganlikun | 0:13413ea9a877 | 645 | * @param hcec : pointer to a CEC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 646 | * the configuration information for the specified CEC. |
ganlikun | 0:13413ea9a877 | 647 | * @retval CEC Error Code |
ganlikun | 0:13413ea9a877 | 648 | */ |
ganlikun | 0:13413ea9a877 | 649 | uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec) |
ganlikun | 0:13413ea9a877 | 650 | { |
ganlikun | 0:13413ea9a877 | 651 | return hcec->ErrorCode; |
ganlikun | 0:13413ea9a877 | 652 | } |
ganlikun | 0:13413ea9a877 | 653 | |
ganlikun | 0:13413ea9a877 | 654 | /** |
ganlikun | 0:13413ea9a877 | 655 | * @} |
ganlikun | 0:13413ea9a877 | 656 | */ |
ganlikun | 0:13413ea9a877 | 657 | |
ganlikun | 0:13413ea9a877 | 658 | /** |
ganlikun | 0:13413ea9a877 | 659 | * @} |
ganlikun | 0:13413ea9a877 | 660 | */ |
ganlikun | 0:13413ea9a877 | 661 | |
ganlikun | 0:13413ea9a877 | 662 | #endif /* STM32F446xx */ |
ganlikun | 0:13413ea9a877 | 663 | |
ganlikun | 0:13413ea9a877 | 664 | #endif /* HAL_CEC_MODULE_ENABLED */ |
ganlikun | 0:13413ea9a877 | 665 | /** |
ganlikun | 0:13413ea9a877 | 666 | * @} |
ganlikun | 0:13413ea9a877 | 667 | */ |
ganlikun | 0:13413ea9a877 | 668 | |
ganlikun | 0:13413ea9a877 | 669 | /** |
ganlikun | 0:13413ea9a877 | 670 | * @} |
ganlikun | 0:13413ea9a877 | 671 | */ |
ganlikun | 0:13413ea9a877 | 672 | |
ganlikun | 0:13413ea9a877 | 673 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
ganlikun | 0:13413ea9a877 | 674 |