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