001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_hal_irda.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 IRDA HAL module driver.
ganlikun 0:13413ea9a877 8 * This file provides firmware functions to manage the following
ganlikun 0:13413ea9a877 9 * functionalities of the IrDA SIR ENDEC block (IrDA):
ganlikun 0:13413ea9a877 10 * + Initialization and de-initialization methods
ganlikun 0:13413ea9a877 11 * + IO operation methods
ganlikun 0:13413ea9a877 12 * + Peripheral Control methods
ganlikun 0:13413ea9a877 13 *
ganlikun 0:13413ea9a877 14 @verbatim
ganlikun 0:13413ea9a877 15 ==============================================================================
ganlikun 0:13413ea9a877 16 ##### How to use this driver #####
ganlikun 0:13413ea9a877 17 ==============================================================================
ganlikun 0:13413ea9a877 18 [..]
ganlikun 0:13413ea9a877 19 The IRDA HAL driver can be used as follows:
ganlikun 0:13413ea9a877 20
ganlikun 0:13413ea9a877 21 (#) Declare a IRDA_HandleTypeDef handle structure.
ganlikun 0:13413ea9a877 22 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API:
ganlikun 0:13413ea9a877 23 (##) Enable the USARTx interface clock.
ganlikun 0:13413ea9a877 24 (##) IRDA pins configuration:
ganlikun 0:13413ea9a877 25 (+++) Enable the clock for the IRDA GPIOs.
ganlikun 0:13413ea9a877 26 (+++) Configure these IRDA pins as alternate function pull-up.
ganlikun 0:13413ea9a877 27 (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
ganlikun 0:13413ea9a877 28 and HAL_IRDA_Receive_IT() APIs):
ganlikun 0:13413ea9a877 29 (+++) Configure the USARTx interrupt priority.
ganlikun 0:13413ea9a877 30 (+++) Enable the NVIC USART IRQ handle.
ganlikun 0:13413ea9a877 31 (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
ganlikun 0:13413ea9a877 32 and HAL_IRDA_Receive_DMA() APIs):
ganlikun 0:13413ea9a877 33 (+++) Declare a DMA handle structure for the Tx/Rx stream.
ganlikun 0:13413ea9a877 34 (+++) Enable the DMAx interface clock.
ganlikun 0:13413ea9a877 35 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
ganlikun 0:13413ea9a877 36 (+++) Configure the DMA Tx/Rx Stream.
ganlikun 0:13413ea9a877 37 (+++) Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle.
ganlikun 0:13413ea9a877 38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
ganlikun 0:13413ea9a877 39
ganlikun 0:13413ea9a877 40 (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler
ganlikun 0:13413ea9a877 41 and Mode(Receiver/Transmitter) in the hirda Init structure.
ganlikun 0:13413ea9a877 42
ganlikun 0:13413ea9a877 43 (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
ganlikun 0:13413ea9a877 44 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
ganlikun 0:13413ea9a877 45 by calling the customized HAL_IRDA_MspInit() API.
ganlikun 0:13413ea9a877 46 -@@- The specific IRDA interrupts (Transmission complete interrupt,
ganlikun 0:13413ea9a877 47 RXNE interrupt and Error Interrupts) will be managed using the macros
ganlikun 0:13413ea9a877 48 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
ganlikun 0:13413ea9a877 49
ganlikun 0:13413ea9a877 50 (#) Three operation modes are available within this driver :
ganlikun 0:13413ea9a877 51
ganlikun 0:13413ea9a877 52 *** Polling mode IO operation ***
ganlikun 0:13413ea9a877 53 =================================
ganlikun 0:13413ea9a877 54 [..]
ganlikun 0:13413ea9a877 55 (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
ganlikun 0:13413ea9a877 56 (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
ganlikun 0:13413ea9a877 57
ganlikun 0:13413ea9a877 58 *** Interrupt mode IO operation ***
ganlikun 0:13413ea9a877 59 ===================================
ganlikun 0:13413ea9a877 60 [..]
ganlikun 0:13413ea9a877 61 (+) Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT()
ganlikun 0:13413ea9a877 62 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
ganlikun 0:13413ea9a877 63 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
ganlikun 0:13413ea9a877 64 (+) Receive an amount of data in non blocking mode using HAL_IRDA_Receive_IT()
ganlikun 0:13413ea9a877 65 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
ganlikun 0:13413ea9a877 66 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
ganlikun 0:13413ea9a877 67 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 68 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
ganlikun 0:13413ea9a877 69
ganlikun 0:13413ea9a877 70 *** DMA mode IO operation ***
ganlikun 0:13413ea9a877 71 =============================
ganlikun 0:13413ea9a877 72 [..]
ganlikun 0:13413ea9a877 73 (+) Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
ganlikun 0:13413ea9a877 74 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
ganlikun 0:13413ea9a877 75 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
ganlikun 0:13413ea9a877 76 (+) Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA()
ganlikun 0:13413ea9a877 77 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
ganlikun 0:13413ea9a877 78 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
ganlikun 0:13413ea9a877 79 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 80 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
ganlikun 0:13413ea9a877 81
ganlikun 0:13413ea9a877 82 *** IRDA HAL driver macros list ***
ganlikun 0:13413ea9a877 83 ===================================
ganlikun 0:13413ea9a877 84 [..]
ganlikun 0:13413ea9a877 85 Below the list of most used macros in IRDA HAL driver.
ganlikun 0:13413ea9a877 86
ganlikun 0:13413ea9a877 87 (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
ganlikun 0:13413ea9a877 88 (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
ganlikun 0:13413ea9a877 89 (+) __HAL_IRDA_GET_FLAG : Checks whether the specified IRDA flag is set or not
ganlikun 0:13413ea9a877 90 (+) __HAL_IRDA_CLEAR_FLAG : Clears the specified IRDA pending flag
ganlikun 0:13413ea9a877 91 (+) __HAL_IRDA_ENABLE_IT: Enables the specified IRDA interrupt
ganlikun 0:13413ea9a877 92 (+) __HAL_IRDA_DISABLE_IT: Disables the specified IRDA interrupt
ganlikun 0:13413ea9a877 93
ganlikun 0:13413ea9a877 94 [..]
ganlikun 0:13413ea9a877 95 (@) You can refer to the IRDA HAL driver header file for more useful macros
ganlikun 0:13413ea9a877 96
ganlikun 0:13413ea9a877 97 @endverbatim
ganlikun 0:13413ea9a877 98 ******************************************************************************
ganlikun 0:13413ea9a877 99 * @attention
ganlikun 0:13413ea9a877 100 *
ganlikun 0:13413ea9a877 101 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 102 *
ganlikun 0:13413ea9a877 103 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 104 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 105 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 106 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 107 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 108 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 109 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 110 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 111 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 112 * without specific prior written permission.
ganlikun 0:13413ea9a877 113 *
ganlikun 0:13413ea9a877 114 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 115 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 116 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 117 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 118 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 119 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 121 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 122 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 123 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 124 *
ganlikun 0:13413ea9a877 125 ******************************************************************************
ganlikun 0:13413ea9a877 126 */
ganlikun 0:13413ea9a877 127
ganlikun 0:13413ea9a877 128 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 129 #include "stm32f4xx_hal.h"
ganlikun 0:13413ea9a877 130
ganlikun 0:13413ea9a877 131 /** @addtogroup STM32F4xx_HAL_Driver
ganlikun 0:13413ea9a877 132 * @{
ganlikun 0:13413ea9a877 133 */
ganlikun 0:13413ea9a877 134
ganlikun 0:13413ea9a877 135 /** @defgroup IRDA IRDA
ganlikun 0:13413ea9a877 136 * @brief HAL IRDA module driver
ganlikun 0:13413ea9a877 137 * @{
ganlikun 0:13413ea9a877 138 */
ganlikun 0:13413ea9a877 139
ganlikun 0:13413ea9a877 140 #ifdef HAL_IRDA_MODULE_ENABLED
ganlikun 0:13413ea9a877 141
ganlikun 0:13413ea9a877 142 /* Private typedef -----------------------------------------------------------*/
ganlikun 0:13413ea9a877 143 /* Private define ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 144 /** @addtogroup IRDA_Private_Constants
ganlikun 0:13413ea9a877 145 * @{
ganlikun 0:13413ea9a877 146 */
ganlikun 0:13413ea9a877 147 /**
ganlikun 0:13413ea9a877 148 * @}
ganlikun 0:13413ea9a877 149 */
ganlikun 0:13413ea9a877 150 /* Private macro -------------------------------------------------------------*/
ganlikun 0:13413ea9a877 151 /* Private variables ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 152 /* Private function prototypes -----------------------------------------------*/
ganlikun 0:13413ea9a877 153 /** @addtogroup IRDA_Private_Functions
ganlikun 0:13413ea9a877 154 * @{
ganlikun 0:13413ea9a877 155 */
ganlikun 0:13413ea9a877 156 static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda);
ganlikun 0:13413ea9a877 157 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
ganlikun 0:13413ea9a877 158 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
ganlikun 0:13413ea9a877 159 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
ganlikun 0:13413ea9a877 160 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 161 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 162 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 163 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 164 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 165 static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 166 static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 167 static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 168 static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 169 static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 170 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart,uint32_t Timeout);
ganlikun 0:13413ea9a877 171 static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda);
ganlikun 0:13413ea9a877 172 static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda);
ganlikun 0:13413ea9a877 173 /**
ganlikun 0:13413ea9a877 174 * @}
ganlikun 0:13413ea9a877 175 */
ganlikun 0:13413ea9a877 176 /* Exported functions --------------------------------------------------------*/
ganlikun 0:13413ea9a877 177 /** @defgroup IRDA_Exported_Functions IrDA Exported Functions
ganlikun 0:13413ea9a877 178 * @{
ganlikun 0:13413ea9a877 179 */
ganlikun 0:13413ea9a877 180
ganlikun 0:13413ea9a877 181 /** @defgroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
ganlikun 0:13413ea9a877 182 * @brief Initialization and Configuration functions
ganlikun 0:13413ea9a877 183 *
ganlikun 0:13413ea9a877 184 @verbatim
ganlikun 0:13413ea9a877 185
ganlikun 0:13413ea9a877 186 ===============================================================================
ganlikun 0:13413ea9a877 187 ##### Initialization and Configuration functions #####
ganlikun 0:13413ea9a877 188 ===============================================================================
ganlikun 0:13413ea9a877 189 [..]
ganlikun 0:13413ea9a877 190 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
ganlikun 0:13413ea9a877 191 in IrDA mode.
ganlikun 0:13413ea9a877 192 (+) For the asynchronous mode only these parameters can be configured:
ganlikun 0:13413ea9a877 193 (++) BaudRate
ganlikun 0:13413ea9a877 194 (++) WordLength
ganlikun 0:13413ea9a877 195 (++) Parity: If the parity is enabled, then the MSB bit of the data written
ganlikun 0:13413ea9a877 196 in the data register is transmitted but is changed by the parity bit.
ganlikun 0:13413ea9a877 197 Depending on the frame length defined by the M bit (8-bits or 9-bits),
ganlikun 0:13413ea9a877 198 please refer to Reference manual for possible IRDA frame formats.
ganlikun 0:13413ea9a877 199 (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
ganlikun 0:13413ea9a877 200 not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
ganlikun 0:13413ea9a877 201 specification specifies a minimum of 10 ms delay between transmission and
ganlikun 0:13413ea9a877 202 reception (IrDA is a half duplex protocol).
ganlikun 0:13413ea9a877 203 (++) Mode: Receiver/transmitter modes
ganlikun 0:13413ea9a877 204 (++) IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.
ganlikun 0:13413ea9a877 205 [..]
ganlikun 0:13413ea9a877 206 The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures
ganlikun 0:13413ea9a877 207 are available in reference manual).
ganlikun 0:13413ea9a877 208
ganlikun 0:13413ea9a877 209 @endverbatim
ganlikun 0:13413ea9a877 210 * @{
ganlikun 0:13413ea9a877 211 */
ganlikun 0:13413ea9a877 212
ganlikun 0:13413ea9a877 213 /**
ganlikun 0:13413ea9a877 214 * @brief Initializes the IRDA mode according to the specified
ganlikun 0:13413ea9a877 215 * parameters in the IRDA_InitTypeDef and create the associated handle.
ganlikun 0:13413ea9a877 216 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 217 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 218 * @retval HAL status
ganlikun 0:13413ea9a877 219 */
ganlikun 0:13413ea9a877 220 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 221 {
ganlikun 0:13413ea9a877 222 /* Check the IRDA handle allocation */
ganlikun 0:13413ea9a877 223 if(hirda == NULL)
ganlikun 0:13413ea9a877 224 {
ganlikun 0:13413ea9a877 225 return HAL_ERROR;
ganlikun 0:13413ea9a877 226 }
ganlikun 0:13413ea9a877 227
ganlikun 0:13413ea9a877 228 /* Check the IRDA instance parameters */
ganlikun 0:13413ea9a877 229 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
ganlikun 0:13413ea9a877 230 /* Check the IRDA mode parameter in the IRDA handle */
ganlikun 0:13413ea9a877 231 assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
ganlikun 0:13413ea9a877 232
ganlikun 0:13413ea9a877 233 if(hirda->gState == HAL_IRDA_STATE_RESET)
ganlikun 0:13413ea9a877 234 {
ganlikun 0:13413ea9a877 235 /* Allocate lock resource and initialize it */
ganlikun 0:13413ea9a877 236 hirda->Lock = HAL_UNLOCKED;
ganlikun 0:13413ea9a877 237 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
ganlikun 0:13413ea9a877 238 HAL_IRDA_MspInit(hirda);
ganlikun 0:13413ea9a877 239 }
ganlikun 0:13413ea9a877 240
ganlikun 0:13413ea9a877 241 hirda->gState = HAL_IRDA_STATE_BUSY;
ganlikun 0:13413ea9a877 242
ganlikun 0:13413ea9a877 243 /* Disable the IRDA peripheral */
ganlikun 0:13413ea9a877 244 __HAL_IRDA_DISABLE(hirda);
ganlikun 0:13413ea9a877 245
ganlikun 0:13413ea9a877 246 /* Set the IRDA communication parameters */
ganlikun 0:13413ea9a877 247 IRDA_SetConfig(hirda);
ganlikun 0:13413ea9a877 248
ganlikun 0:13413ea9a877 249 /* In IrDA mode, the following bits must be kept cleared:
ganlikun 0:13413ea9a877 250 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
ganlikun 0:13413ea9a877 251 - SCEN and HDSEL bits in the USART_CR3 register.*/
ganlikun 0:13413ea9a877 252 CLEAR_BIT(hirda->Instance->CR2, USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN);
ganlikun 0:13413ea9a877 253 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_SCEN | USART_CR3_HDSEL);
ganlikun 0:13413ea9a877 254
ganlikun 0:13413ea9a877 255 /* Enable the IRDA peripheral */
ganlikun 0:13413ea9a877 256 __HAL_IRDA_ENABLE(hirda);
ganlikun 0:13413ea9a877 257
ganlikun 0:13413ea9a877 258 /* Set the prescaler */
ganlikun 0:13413ea9a877 259 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
ganlikun 0:13413ea9a877 260
ganlikun 0:13413ea9a877 261 /* Configure the IrDA mode */
ganlikun 0:13413ea9a877 262 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
ganlikun 0:13413ea9a877 263
ganlikun 0:13413ea9a877 264 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
ganlikun 0:13413ea9a877 265 SET_BIT(hirda->Instance->CR3, USART_CR3_IREN);
ganlikun 0:13413ea9a877 266
ganlikun 0:13413ea9a877 267 /* Initialize the IRDA state*/
ganlikun 0:13413ea9a877 268 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 269 hirda->gState= HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 270 hirda->RxState= HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 271
ganlikun 0:13413ea9a877 272 return HAL_OK;
ganlikun 0:13413ea9a877 273 }
ganlikun 0:13413ea9a877 274
ganlikun 0:13413ea9a877 275 /**
ganlikun 0:13413ea9a877 276 * @brief DeInitializes the IRDA peripheral
ganlikun 0:13413ea9a877 277 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 278 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 279 * @retval HAL status
ganlikun 0:13413ea9a877 280 */
ganlikun 0:13413ea9a877 281 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 282 {
ganlikun 0:13413ea9a877 283 /* Check the IRDA handle allocation */
ganlikun 0:13413ea9a877 284 if(hirda == NULL)
ganlikun 0:13413ea9a877 285 {
ganlikun 0:13413ea9a877 286 return HAL_ERROR;
ganlikun 0:13413ea9a877 287 }
ganlikun 0:13413ea9a877 288
ganlikun 0:13413ea9a877 289 /* Check the parameters */
ganlikun 0:13413ea9a877 290 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
ganlikun 0:13413ea9a877 291
ganlikun 0:13413ea9a877 292 hirda->gState = HAL_IRDA_STATE_BUSY;
ganlikun 0:13413ea9a877 293
ganlikun 0:13413ea9a877 294 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 295 __HAL_IRDA_DISABLE(hirda);
ganlikun 0:13413ea9a877 296
ganlikun 0:13413ea9a877 297 /* DeInit the low level hardware */
ganlikun 0:13413ea9a877 298 HAL_IRDA_MspDeInit(hirda);
ganlikun 0:13413ea9a877 299
ganlikun 0:13413ea9a877 300 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 301
ganlikun 0:13413ea9a877 302 hirda->gState = HAL_IRDA_STATE_RESET;
ganlikun 0:13413ea9a877 303 hirda->RxState = HAL_IRDA_STATE_RESET;
ganlikun 0:13413ea9a877 304
ganlikun 0:13413ea9a877 305 /* Release Lock */
ganlikun 0:13413ea9a877 306 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 307
ganlikun 0:13413ea9a877 308 return HAL_OK;
ganlikun 0:13413ea9a877 309 }
ganlikun 0:13413ea9a877 310
ganlikun 0:13413ea9a877 311 /**
ganlikun 0:13413ea9a877 312 * @brief IRDA MSP Init.
ganlikun 0:13413ea9a877 313 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 314 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 315 * @retval None
ganlikun 0:13413ea9a877 316 */
ganlikun 0:13413ea9a877 317 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 318 {
ganlikun 0:13413ea9a877 319 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 320 UNUSED(hirda);
ganlikun 0:13413ea9a877 321 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 322 the HAL_IRDA_MspInit could be implemented in the user file
ganlikun 0:13413ea9a877 323 */
ganlikun 0:13413ea9a877 324 }
ganlikun 0:13413ea9a877 325
ganlikun 0:13413ea9a877 326 /**
ganlikun 0:13413ea9a877 327 * @brief IRDA MSP DeInit.
ganlikun 0:13413ea9a877 328 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 329 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 330 * @retval None
ganlikun 0:13413ea9a877 331 */
ganlikun 0:13413ea9a877 332 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 333 {
ganlikun 0:13413ea9a877 334 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 335 UNUSED(hirda);
ganlikun 0:13413ea9a877 336 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 337 the HAL_IRDA_MspDeInit could be implemented in the user file
ganlikun 0:13413ea9a877 338 */
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 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
ganlikun 0:13413ea9a877 346 * @brief IRDA Transmit/Receive functions
ganlikun 0:13413ea9a877 347 *
ganlikun 0:13413ea9a877 348 @verbatim
ganlikun 0:13413ea9a877 349 ===============================================================================
ganlikun 0:13413ea9a877 350 ##### IO operation functions #####
ganlikun 0:13413ea9a877 351 ===============================================================================
ganlikun 0:13413ea9a877 352 This subsection provides a set of functions allowing to manage the IRDA data transfers.
ganlikun 0:13413ea9a877 353 [..]
ganlikun 0:13413ea9a877 354 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
ganlikun 0:13413ea9a877 355 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
ganlikun 0:13413ea9a877 356 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
ganlikun 0:13413ea9a877 357 While receiving data, transmission should be avoided as the data to be transmitted
ganlikun 0:13413ea9a877 358 could be corrupted.
ganlikun 0:13413ea9a877 359
ganlikun 0:13413ea9a877 360 (#) There are two modes of transfer:
ganlikun 0:13413ea9a877 361 (++) Blocking mode: The communication is performed in polling mode.
ganlikun 0:13413ea9a877 362 The HAL status of all data processing is returned by the same function
ganlikun 0:13413ea9a877 363 after finishing transfer.
ganlikun 0:13413ea9a877 364 (++) No-Blocking mode: The communication is performed using Interrupts
ganlikun 0:13413ea9a877 365 or DMA, These APIs return the HAL status.
ganlikun 0:13413ea9a877 366 The end of the data processing will be indicated through the
ganlikun 0:13413ea9a877 367 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
ganlikun 0:13413ea9a877 368 using DMA mode.
ganlikun 0:13413ea9a877 369 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
ganlikun 0:13413ea9a877 370 will be executed respectively at the end of the transmit or Receive process
ganlikun 0:13413ea9a877 371 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
ganlikun 0:13413ea9a877 372
ganlikun 0:13413ea9a877 373 (#) Blocking mode API's are :
ganlikun 0:13413ea9a877 374 (++) HAL_IRDA_Transmit()
ganlikun 0:13413ea9a877 375 (++) HAL_IRDA_Receive()
ganlikun 0:13413ea9a877 376
ganlikun 0:13413ea9a877 377 (#) Non Blocking mode APIs with Interrupt are :
ganlikun 0:13413ea9a877 378 (++) HAL_IRDA_Transmit_IT()
ganlikun 0:13413ea9a877 379 (++) HAL_IRDA_Receive_IT()
ganlikun 0:13413ea9a877 380 (++) HAL_IRDA_IRQHandler()
ganlikun 0:13413ea9a877 381
ganlikun 0:13413ea9a877 382 (#) Non Blocking mode functions with DMA are :
ganlikun 0:13413ea9a877 383 (++) HAL_IRDA_Transmit_DMA()
ganlikun 0:13413ea9a877 384 (++) HAL_IRDA_Receive_DMA()
ganlikun 0:13413ea9a877 385
ganlikun 0:13413ea9a877 386 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
ganlikun 0:13413ea9a877 387 (++) HAL_IRDA_TxCpltCallback()
ganlikun 0:13413ea9a877 388 (++) HAL_IRDA_RxCpltCallback()
ganlikun 0:13413ea9a877 389 (++) HAL_IRDA_ErrorCallback()
ganlikun 0:13413ea9a877 390
ganlikun 0:13413ea9a877 391 @endverbatim
ganlikun 0:13413ea9a877 392 * @{
ganlikun 0:13413ea9a877 393 */
ganlikun 0:13413ea9a877 394
ganlikun 0:13413ea9a877 395 /**
ganlikun 0:13413ea9a877 396 * @brief Sends an amount of data in blocking mode.
ganlikun 0:13413ea9a877 397 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 398 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 399 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 400 * @param Size: Amount of data to be sent
ganlikun 0:13413ea9a877 401 * @param Timeout: Specify timeout value
ganlikun 0:13413ea9a877 402 * @retval HAL status
ganlikun 0:13413ea9a877 403 */
ganlikun 0:13413ea9a877 404 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 405 {
ganlikun 0:13413ea9a877 406 uint16_t* tmp;
ganlikun 0:13413ea9a877 407 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 408
ganlikun 0:13413ea9a877 409 /* Check that a Tx process is not already ongoing */
ganlikun 0:13413ea9a877 410 if(hirda->gState == HAL_IRDA_STATE_READY)
ganlikun 0:13413ea9a877 411 {
ganlikun 0:13413ea9a877 412 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 413 {
ganlikun 0:13413ea9a877 414 return HAL_ERROR;
ganlikun 0:13413ea9a877 415 }
ganlikun 0:13413ea9a877 416
ganlikun 0:13413ea9a877 417 /* Process Locked */
ganlikun 0:13413ea9a877 418 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 419
ganlikun 0:13413ea9a877 420 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 421 hirda->gState = HAL_IRDA_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 422
ganlikun 0:13413ea9a877 423 /* Init tickstart for timeout managment*/
ganlikun 0:13413ea9a877 424 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 425
ganlikun 0:13413ea9a877 426 hirda->TxXferSize = Size;
ganlikun 0:13413ea9a877 427 hirda->TxXferCount = Size;
ganlikun 0:13413ea9a877 428 while(hirda->TxXferCount > 0U)
ganlikun 0:13413ea9a877 429 {
ganlikun 0:13413ea9a877 430 hirda->TxXferCount--;
ganlikun 0:13413ea9a877 431 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
ganlikun 0:13413ea9a877 432 {
ganlikun 0:13413ea9a877 433 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 434 {
ganlikun 0:13413ea9a877 435 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 436 }
ganlikun 0:13413ea9a877 437 tmp = (uint16_t*) pData;
ganlikun 0:13413ea9a877 438 hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
ganlikun 0:13413ea9a877 439 if(hirda->Init.Parity == IRDA_PARITY_NONE)
ganlikun 0:13413ea9a877 440 {
ganlikun 0:13413ea9a877 441 pData +=2;
ganlikun 0:13413ea9a877 442 }
ganlikun 0:13413ea9a877 443 else
ganlikun 0:13413ea9a877 444 {
ganlikun 0:13413ea9a877 445 pData +=1;
ganlikun 0:13413ea9a877 446 }
ganlikun 0:13413ea9a877 447 }
ganlikun 0:13413ea9a877 448 else
ganlikun 0:13413ea9a877 449 {
ganlikun 0:13413ea9a877 450 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 451 {
ganlikun 0:13413ea9a877 452 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 453 }
ganlikun 0:13413ea9a877 454 hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
ganlikun 0:13413ea9a877 455 }
ganlikun 0:13413ea9a877 456 }
ganlikun 0:13413ea9a877 457
ganlikun 0:13413ea9a877 458 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 459 {
ganlikun 0:13413ea9a877 460 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 461 }
ganlikun 0:13413ea9a877 462
ganlikun 0:13413ea9a877 463 /* At end of Tx process, restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 464 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 465
ganlikun 0:13413ea9a877 466 /* Process Unlocked */
ganlikun 0:13413ea9a877 467 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 468
ganlikun 0:13413ea9a877 469 return HAL_OK;
ganlikun 0:13413ea9a877 470 }
ganlikun 0:13413ea9a877 471 else
ganlikun 0:13413ea9a877 472 {
ganlikun 0:13413ea9a877 473 return HAL_BUSY;
ganlikun 0:13413ea9a877 474 }
ganlikun 0:13413ea9a877 475 }
ganlikun 0:13413ea9a877 476
ganlikun 0:13413ea9a877 477 /**
ganlikun 0:13413ea9a877 478 * @brief Receive an amount of data in blocking mode.
ganlikun 0:13413ea9a877 479 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 480 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 481 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 482 * @param Size: Amount of data to be received
ganlikun 0:13413ea9a877 483 * @param Timeout: Specify timeout value
ganlikun 0:13413ea9a877 484 * @retval HAL status
ganlikun 0:13413ea9a877 485 */
ganlikun 0:13413ea9a877 486 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 487 {
ganlikun 0:13413ea9a877 488 uint16_t* tmp;
ganlikun 0:13413ea9a877 489 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 490
ganlikun 0:13413ea9a877 491 /* Check that a Rx process is not already ongoing */
ganlikun 0:13413ea9a877 492 if(hirda->RxState == HAL_IRDA_STATE_READY)
ganlikun 0:13413ea9a877 493 {
ganlikun 0:13413ea9a877 494 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 495 {
ganlikun 0:13413ea9a877 496 return HAL_ERROR;
ganlikun 0:13413ea9a877 497 }
ganlikun 0:13413ea9a877 498
ganlikun 0:13413ea9a877 499 /* Process Locked */
ganlikun 0:13413ea9a877 500 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 501
ganlikun 0:13413ea9a877 502 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 503 hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 504
ganlikun 0:13413ea9a877 505 /* Init tickstart for timeout managment*/
ganlikun 0:13413ea9a877 506 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 507
ganlikun 0:13413ea9a877 508 hirda->RxXferSize = Size;
ganlikun 0:13413ea9a877 509 hirda->RxXferCount = Size;
ganlikun 0:13413ea9a877 510 /* Check the remain data to be received */
ganlikun 0:13413ea9a877 511 while(hirda->RxXferCount > 0U)
ganlikun 0:13413ea9a877 512 {
ganlikun 0:13413ea9a877 513 hirda->RxXferCount--;
ganlikun 0:13413ea9a877 514 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
ganlikun 0:13413ea9a877 515 {
ganlikun 0:13413ea9a877 516 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 517 {
ganlikun 0:13413ea9a877 518 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 519 }
ganlikun 0:13413ea9a877 520 tmp = (uint16_t*) pData ;
ganlikun 0:13413ea9a877 521 if(hirda->Init.Parity == IRDA_PARITY_NONE)
ganlikun 0:13413ea9a877 522 {
ganlikun 0:13413ea9a877 523 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
ganlikun 0:13413ea9a877 524 pData +=2;
ganlikun 0:13413ea9a877 525 }
ganlikun 0:13413ea9a877 526 else
ganlikun 0:13413ea9a877 527 {
ganlikun 0:13413ea9a877 528 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
ganlikun 0:13413ea9a877 529 pData +=1;
ganlikun 0:13413ea9a877 530 }
ganlikun 0:13413ea9a877 531 }
ganlikun 0:13413ea9a877 532 else
ganlikun 0:13413ea9a877 533 {
ganlikun 0:13413ea9a877 534 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 535 {
ganlikun 0:13413ea9a877 536 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 537 }
ganlikun 0:13413ea9a877 538 if(hirda->Init.Parity == IRDA_PARITY_NONE)
ganlikun 0:13413ea9a877 539 {
ganlikun 0:13413ea9a877 540 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
ganlikun 0:13413ea9a877 541 }
ganlikun 0:13413ea9a877 542 else
ganlikun 0:13413ea9a877 543 {
ganlikun 0:13413ea9a877 544 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
ganlikun 0:13413ea9a877 545 }
ganlikun 0:13413ea9a877 546 }
ganlikun 0:13413ea9a877 547 }
ganlikun 0:13413ea9a877 548
ganlikun 0:13413ea9a877 549 /* At end of Rx process, restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 550 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 551
ganlikun 0:13413ea9a877 552 /* Process Unlocked */
ganlikun 0:13413ea9a877 553 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 554
ganlikun 0:13413ea9a877 555 return HAL_OK;
ganlikun 0:13413ea9a877 556 }
ganlikun 0:13413ea9a877 557 else
ganlikun 0:13413ea9a877 558 {
ganlikun 0:13413ea9a877 559 return HAL_BUSY;
ganlikun 0:13413ea9a877 560 }
ganlikun 0:13413ea9a877 561 }
ganlikun 0:13413ea9a877 562
ganlikun 0:13413ea9a877 563 /**
ganlikun 0:13413ea9a877 564 * @brief Send an amount of data in non blocking mode.
ganlikun 0:13413ea9a877 565 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 566 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 567 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 568 * @param Size: Amount of data to be sent
ganlikun 0:13413ea9a877 569 * @retval HAL status
ganlikun 0:13413ea9a877 570 */
ganlikun 0:13413ea9a877 571 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 572 {
ganlikun 0:13413ea9a877 573 /* Check that a Tx process is not already ongoing */
ganlikun 0:13413ea9a877 574 if(hirda->gState == HAL_IRDA_STATE_READY)
ganlikun 0:13413ea9a877 575 {
ganlikun 0:13413ea9a877 576 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 577 {
ganlikun 0:13413ea9a877 578 return HAL_ERROR;
ganlikun 0:13413ea9a877 579 }
ganlikun 0:13413ea9a877 580 /* Process Locked */
ganlikun 0:13413ea9a877 581 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 582
ganlikun 0:13413ea9a877 583 hirda->pTxBuffPtr = pData;
ganlikun 0:13413ea9a877 584 hirda->TxXferSize = Size;
ganlikun 0:13413ea9a877 585 hirda->TxXferCount = Size;
ganlikun 0:13413ea9a877 586 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 587 hirda->gState = HAL_IRDA_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 588
ganlikun 0:13413ea9a877 589 /* Process Unlocked */
ganlikun 0:13413ea9a877 590 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 591
ganlikun 0:13413ea9a877 592 /* Enable the IRDA Transmit Data Register Empty Interrupt */
ganlikun 0:13413ea9a877 593 SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
ganlikun 0:13413ea9a877 594
ganlikun 0:13413ea9a877 595 return HAL_OK;
ganlikun 0:13413ea9a877 596 }
ganlikun 0:13413ea9a877 597 else
ganlikun 0:13413ea9a877 598 {
ganlikun 0:13413ea9a877 599 return HAL_BUSY;
ganlikun 0:13413ea9a877 600 }
ganlikun 0:13413ea9a877 601 }
ganlikun 0:13413ea9a877 602
ganlikun 0:13413ea9a877 603 /**
ganlikun 0:13413ea9a877 604 * @brief Receives an amount of data in non blocking mode.
ganlikun 0:13413ea9a877 605 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 606 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 607 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 608 * @param Size: Amount of data to be received
ganlikun 0:13413ea9a877 609 * @retval HAL status
ganlikun 0:13413ea9a877 610 */
ganlikun 0:13413ea9a877 611 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 612 {
ganlikun 0:13413ea9a877 613 /* Check that a Rx process is not already ongoing */
ganlikun 0:13413ea9a877 614 if(hirda->RxState == HAL_IRDA_STATE_READY)
ganlikun 0:13413ea9a877 615 {
ganlikun 0:13413ea9a877 616 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 617 {
ganlikun 0:13413ea9a877 618 return HAL_ERROR;
ganlikun 0:13413ea9a877 619 }
ganlikun 0:13413ea9a877 620
ganlikun 0:13413ea9a877 621 /* Process Locked */
ganlikun 0:13413ea9a877 622 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 623
ganlikun 0:13413ea9a877 624 hirda->pRxBuffPtr = pData;
ganlikun 0:13413ea9a877 625 hirda->RxXferSize = Size;
ganlikun 0:13413ea9a877 626 hirda->RxXferCount = Size;
ganlikun 0:13413ea9a877 627 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 628 hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 629
ganlikun 0:13413ea9a877 630 /* Process Unlocked */
ganlikun 0:13413ea9a877 631 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 632
ganlikun 0:13413ea9a877 633 /* Enable the IRDA Parity Error and Data Register not empty Interrupts */
ganlikun 0:13413ea9a877 634 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE);
ganlikun 0:13413ea9a877 635
ganlikun 0:13413ea9a877 636 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
ganlikun 0:13413ea9a877 637 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 638
ganlikun 0:13413ea9a877 639 return HAL_OK;
ganlikun 0:13413ea9a877 640 }
ganlikun 0:13413ea9a877 641 else
ganlikun 0:13413ea9a877 642 {
ganlikun 0:13413ea9a877 643 return HAL_BUSY;
ganlikun 0:13413ea9a877 644 }
ganlikun 0:13413ea9a877 645 }
ganlikun 0:13413ea9a877 646
ganlikun 0:13413ea9a877 647 /**
ganlikun 0:13413ea9a877 648 * @brief Sends an amount of data in non blocking mode.
ganlikun 0:13413ea9a877 649 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 650 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 651 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 652 * @param Size: Amount of data to be sent
ganlikun 0:13413ea9a877 653 * @retval HAL status
ganlikun 0:13413ea9a877 654 */
ganlikun 0:13413ea9a877 655 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 656 {
ganlikun 0:13413ea9a877 657 uint32_t *tmp;
ganlikun 0:13413ea9a877 658
ganlikun 0:13413ea9a877 659 /* Check that a Tx process is not already ongoing */
ganlikun 0:13413ea9a877 660 if(hirda->gState == HAL_IRDA_STATE_READY)
ganlikun 0:13413ea9a877 661 {
ganlikun 0:13413ea9a877 662 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 663 {
ganlikun 0:13413ea9a877 664 return HAL_ERROR;
ganlikun 0:13413ea9a877 665 }
ganlikun 0:13413ea9a877 666
ganlikun 0:13413ea9a877 667 /* Process Locked */
ganlikun 0:13413ea9a877 668 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 669
ganlikun 0:13413ea9a877 670 hirda->pTxBuffPtr = pData;
ganlikun 0:13413ea9a877 671 hirda->TxXferSize = Size;
ganlikun 0:13413ea9a877 672 hirda->TxXferCount = Size;
ganlikun 0:13413ea9a877 673 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 674 hirda->gState = HAL_IRDA_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 675
ganlikun 0:13413ea9a877 676 /* Set the IRDA DMA transfer complete callback */
ganlikun 0:13413ea9a877 677 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
ganlikun 0:13413ea9a877 678
ganlikun 0:13413ea9a877 679 /* Set the IRDA DMA half transfer complete callback */
ganlikun 0:13413ea9a877 680 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
ganlikun 0:13413ea9a877 681
ganlikun 0:13413ea9a877 682 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 683 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
ganlikun 0:13413ea9a877 684
ganlikun 0:13413ea9a877 685 /* Set the DMA abort callback */
ganlikun 0:13413ea9a877 686 hirda->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 687
ganlikun 0:13413ea9a877 688 /* Enable the IRDA transmit DMA Stream */
ganlikun 0:13413ea9a877 689 tmp = (uint32_t*)&pData;
ganlikun 0:13413ea9a877 690 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->DR, Size);
ganlikun 0:13413ea9a877 691
ganlikun 0:13413ea9a877 692 /* Clear the TC flag in the SR register by writing 0 to it */
ganlikun 0:13413ea9a877 693 __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_FLAG_TC);
ganlikun 0:13413ea9a877 694
ganlikun 0:13413ea9a877 695 /* Process Unlocked */
ganlikun 0:13413ea9a877 696 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 697
ganlikun 0:13413ea9a877 698 /* Enable the DMA transfer for transmit request by setting the DMAT bit
ganlikun 0:13413ea9a877 699 in the USART CR3 register */
ganlikun 0:13413ea9a877 700 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 701
ganlikun 0:13413ea9a877 702 return HAL_OK;
ganlikun 0:13413ea9a877 703 }
ganlikun 0:13413ea9a877 704 else
ganlikun 0:13413ea9a877 705 {
ganlikun 0:13413ea9a877 706 return HAL_BUSY;
ganlikun 0:13413ea9a877 707 }
ganlikun 0:13413ea9a877 708 }
ganlikun 0:13413ea9a877 709
ganlikun 0:13413ea9a877 710 /**
ganlikun 0:13413ea9a877 711 * @brief Receives an amount of data in non blocking mode.
ganlikun 0:13413ea9a877 712 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 713 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 714 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 715 * @param Size: Amount of data to be received
ganlikun 0:13413ea9a877 716 * @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
ganlikun 0:13413ea9a877 717 * @retval HAL status
ganlikun 0:13413ea9a877 718 */
ganlikun 0:13413ea9a877 719 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 720 {
ganlikun 0:13413ea9a877 721 uint32_t *tmp;
ganlikun 0:13413ea9a877 722
ganlikun 0:13413ea9a877 723 /* Check that a Rx process is not already ongoing */
ganlikun 0:13413ea9a877 724 if(hirda->RxState == HAL_IRDA_STATE_READY)
ganlikun 0:13413ea9a877 725 {
ganlikun 0:13413ea9a877 726 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 727 {
ganlikun 0:13413ea9a877 728 return HAL_ERROR;
ganlikun 0:13413ea9a877 729 }
ganlikun 0:13413ea9a877 730
ganlikun 0:13413ea9a877 731 /* Process Locked */
ganlikun 0:13413ea9a877 732 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 733
ganlikun 0:13413ea9a877 734 hirda->pRxBuffPtr = pData;
ganlikun 0:13413ea9a877 735 hirda->RxXferSize = Size;
ganlikun 0:13413ea9a877 736 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 737 hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 738
ganlikun 0:13413ea9a877 739 /* Set the IRDA DMA transfer complete callback */
ganlikun 0:13413ea9a877 740 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
ganlikun 0:13413ea9a877 741
ganlikun 0:13413ea9a877 742 /* Set the IRDA DMA half transfer complete callback */
ganlikun 0:13413ea9a877 743 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
ganlikun 0:13413ea9a877 744
ganlikun 0:13413ea9a877 745 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 746 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
ganlikun 0:13413ea9a877 747
ganlikun 0:13413ea9a877 748 /* Set the DMA abort callback */
ganlikun 0:13413ea9a877 749 hirda->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 750
ganlikun 0:13413ea9a877 751 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 752 tmp = (uint32_t*)&pData;
ganlikun 0:13413ea9a877 753 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t*)tmp, Size);
ganlikun 0:13413ea9a877 754
ganlikun 0:13413ea9a877 755 /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
ganlikun 0:13413ea9a877 756 __HAL_IRDA_CLEAR_OREFLAG(hirda);
ganlikun 0:13413ea9a877 757
ganlikun 0:13413ea9a877 758 /* Process Unlocked */
ganlikun 0:13413ea9a877 759 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 760
ganlikun 0:13413ea9a877 761 /* Enable the IRDA Parity Error Interrupt */
ganlikun 0:13413ea9a877 762 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
ganlikun 0:13413ea9a877 763
ganlikun 0:13413ea9a877 764 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
ganlikun 0:13413ea9a877 765 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 766
ganlikun 0:13413ea9a877 767 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
ganlikun 0:13413ea9a877 768 in the USART CR3 register */
ganlikun 0:13413ea9a877 769 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 770
ganlikun 0:13413ea9a877 771 return HAL_OK;
ganlikun 0:13413ea9a877 772 }
ganlikun 0:13413ea9a877 773 else
ganlikun 0:13413ea9a877 774 {
ganlikun 0:13413ea9a877 775 return HAL_BUSY;
ganlikun 0:13413ea9a877 776 }
ganlikun 0:13413ea9a877 777 }
ganlikun 0:13413ea9a877 778
ganlikun 0:13413ea9a877 779 /**
ganlikun 0:13413ea9a877 780 * @brief Pauses the DMA Transfer.
ganlikun 0:13413ea9a877 781 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 782 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 783 * @retval HAL status
ganlikun 0:13413ea9a877 784 */
ganlikun 0:13413ea9a877 785 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 786 {
ganlikun 0:13413ea9a877 787 uint32_t dmarequest = 0x00U;
ganlikun 0:13413ea9a877 788
ganlikun 0:13413ea9a877 789 /* Process Locked */
ganlikun 0:13413ea9a877 790 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 791
ganlikun 0:13413ea9a877 792 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 793 if((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
ganlikun 0:13413ea9a877 794 {
ganlikun 0:13413ea9a877 795 /* Disable the IRDA DMA Tx request */
ganlikun 0:13413ea9a877 796 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 797 }
ganlikun 0:13413ea9a877 798
ganlikun 0:13413ea9a877 799 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 800 if((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
ganlikun 0:13413ea9a877 801 {
ganlikun 0:13413ea9a877 802 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 803 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
ganlikun 0:13413ea9a877 804 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 805
ganlikun 0:13413ea9a877 806 /* Disable the IRDA DMA Rx request */
ganlikun 0:13413ea9a877 807 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 808 }
ganlikun 0:13413ea9a877 809
ganlikun 0:13413ea9a877 810 /* Process Unlocked */
ganlikun 0:13413ea9a877 811 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 812
ganlikun 0:13413ea9a877 813 return HAL_OK;
ganlikun 0:13413ea9a877 814 }
ganlikun 0:13413ea9a877 815
ganlikun 0:13413ea9a877 816 /**
ganlikun 0:13413ea9a877 817 * @brief Resumes the DMA Transfer.
ganlikun 0:13413ea9a877 818 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 819 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 820 * @retval HAL status
ganlikun 0:13413ea9a877 821 */
ganlikun 0:13413ea9a877 822 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 823 {
ganlikun 0:13413ea9a877 824 /* Process Locked */
ganlikun 0:13413ea9a877 825 __HAL_LOCK(hirda);
ganlikun 0:13413ea9a877 826
ganlikun 0:13413ea9a877 827 if(hirda->gState == HAL_IRDA_STATE_BUSY_TX)
ganlikun 0:13413ea9a877 828 {
ganlikun 0:13413ea9a877 829 /* Enable the IRDA DMA Tx request */
ganlikun 0:13413ea9a877 830 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 831 }
ganlikun 0:13413ea9a877 832 if(hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
ganlikun 0:13413ea9a877 833 {
ganlikun 0:13413ea9a877 834 /* Clear the Overrun flag before resuming the Rx transfer */
ganlikun 0:13413ea9a877 835 __HAL_IRDA_CLEAR_OREFLAG(hirda);
ganlikun 0:13413ea9a877 836
ganlikun 0:13413ea9a877 837 /* Reenable PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 838 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
ganlikun 0:13413ea9a877 839 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 840
ganlikun 0:13413ea9a877 841 /* Enable the IRDA DMA Rx request */
ganlikun 0:13413ea9a877 842 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 843 }
ganlikun 0:13413ea9a877 844
ganlikun 0:13413ea9a877 845 /* Process Unlocked */
ganlikun 0:13413ea9a877 846 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 847
ganlikun 0:13413ea9a877 848 return HAL_OK;
ganlikun 0:13413ea9a877 849 }
ganlikun 0:13413ea9a877 850
ganlikun 0:13413ea9a877 851 /**
ganlikun 0:13413ea9a877 852 * @brief Stops the DMA Transfer.
ganlikun 0:13413ea9a877 853 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 854 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 855 * @retval HAL status
ganlikun 0:13413ea9a877 856 */
ganlikun 0:13413ea9a877 857 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 858 {
ganlikun 0:13413ea9a877 859 uint32_t dmarequest = 0x00U;
ganlikun 0:13413ea9a877 860 /* The Lock is not implemented on this API to allow the user application
ganlikun 0:13413ea9a877 861 to call the HAL IRDA API under callbacks HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback():
ganlikun 0:13413ea9a877 862 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
ganlikun 0:13413ea9a877 863 and the correspond call back is executed HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback()
ganlikun 0:13413ea9a877 864 */
ganlikun 0:13413ea9a877 865
ganlikun 0:13413ea9a877 866 /* Stop IRDA DMA Tx request if ongoing */
ganlikun 0:13413ea9a877 867 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 868 if((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
ganlikun 0:13413ea9a877 869 {
ganlikun 0:13413ea9a877 870 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 871
ganlikun 0:13413ea9a877 872 /* Abort the IRDA DMA Tx channel */
ganlikun 0:13413ea9a877 873 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 874 {
ganlikun 0:13413ea9a877 875 HAL_DMA_Abort(hirda->hdmatx);
ganlikun 0:13413ea9a877 876 }
ganlikun 0:13413ea9a877 877 IRDA_EndTxTransfer(hirda);
ganlikun 0:13413ea9a877 878 }
ganlikun 0:13413ea9a877 879
ganlikun 0:13413ea9a877 880 /* Stop IRDA DMA Rx request if ongoing */
ganlikun 0:13413ea9a877 881 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 882 if((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
ganlikun 0:13413ea9a877 883 {
ganlikun 0:13413ea9a877 884 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 885
ganlikun 0:13413ea9a877 886 /* Abort the IRDA DMA Rx channel */
ganlikun 0:13413ea9a877 887 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 888 {
ganlikun 0:13413ea9a877 889 HAL_DMA_Abort(hirda->hdmarx);
ganlikun 0:13413ea9a877 890 }
ganlikun 0:13413ea9a877 891 IRDA_EndRxTransfer(hirda);
ganlikun 0:13413ea9a877 892 }
ganlikun 0:13413ea9a877 893 return HAL_OK;
ganlikun 0:13413ea9a877 894 }
ganlikun 0:13413ea9a877 895
ganlikun 0:13413ea9a877 896 /**
ganlikun 0:13413ea9a877 897 * @brief Abort ongoing transfers (blocking mode).
ganlikun 0:13413ea9a877 898 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 899 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
ganlikun 0:13413ea9a877 900 * This procedure performs following operations :
ganlikun 0:13413ea9a877 901 * - Disable PPP Interrupts
ganlikun 0:13413ea9a877 902 * - Disable the DMA transfer in the peripheral register (if enabled)
ganlikun 0:13413ea9a877 903 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
ganlikun 0:13413ea9a877 904 * - Set handle State to READY
ganlikun 0:13413ea9a877 905 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
ganlikun 0:13413ea9a877 906 * @retval HAL status
ganlikun 0:13413ea9a877 907 */
ganlikun 0:13413ea9a877 908 HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 909 {
ganlikun 0:13413ea9a877 910 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 911 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
ganlikun 0:13413ea9a877 912 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 913
ganlikun 0:13413ea9a877 914 /* Disable the IRDA DMA Tx request if enabled */
ganlikun 0:13413ea9a877 915 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
ganlikun 0:13413ea9a877 916 {
ganlikun 0:13413ea9a877 917 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 918
ganlikun 0:13413ea9a877 919 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
ganlikun 0:13413ea9a877 920 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 921 {
ganlikun 0:13413ea9a877 922 /* Set the IRDA DMA Abort callback to Null.
ganlikun 0:13413ea9a877 923 No call back execution at end of DMA abort procedure */
ganlikun 0:13413ea9a877 924 hirda->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 925
ganlikun 0:13413ea9a877 926 HAL_DMA_Abort(hirda->hdmatx);
ganlikun 0:13413ea9a877 927 }
ganlikun 0:13413ea9a877 928 }
ganlikun 0:13413ea9a877 929
ganlikun 0:13413ea9a877 930 /* Disable the IRDA DMA Rx request if enabled */
ganlikun 0:13413ea9a877 931 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
ganlikun 0:13413ea9a877 932 {
ganlikun 0:13413ea9a877 933 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 934
ganlikun 0:13413ea9a877 935 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
ganlikun 0:13413ea9a877 936 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 937 {
ganlikun 0:13413ea9a877 938 /* Set the IRDA DMA Abort callback to Null.
ganlikun 0:13413ea9a877 939 No call back execution at end of DMA abort procedure */
ganlikun 0:13413ea9a877 940 hirda->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 941
ganlikun 0:13413ea9a877 942 HAL_DMA_Abort(hirda->hdmarx);
ganlikun 0:13413ea9a877 943 }
ganlikun 0:13413ea9a877 944 }
ganlikun 0:13413ea9a877 945
ganlikun 0:13413ea9a877 946 /* Reset Tx and Rx transfer counters */
ganlikun 0:13413ea9a877 947 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 948 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 949
ganlikun 0:13413ea9a877 950 /* Reset ErrorCode */
ganlikun 0:13413ea9a877 951 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 952
ganlikun 0:13413ea9a877 953 /* Restore hirda->RxState and hirda->gState to Ready */
ganlikun 0:13413ea9a877 954 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 955 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 956
ganlikun 0:13413ea9a877 957 return HAL_OK;
ganlikun 0:13413ea9a877 958 }
ganlikun 0:13413ea9a877 959
ganlikun 0:13413ea9a877 960 /**
ganlikun 0:13413ea9a877 961 * @brief Abort ongoing Transmit transfer (blocking mode).
ganlikun 0:13413ea9a877 962 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 963 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
ganlikun 0:13413ea9a877 964 * This procedure performs following operations :
ganlikun 0:13413ea9a877 965 * - Disable PPP Interrupts
ganlikun 0:13413ea9a877 966 * - Disable the DMA transfer in the peripheral register (if enabled)
ganlikun 0:13413ea9a877 967 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
ganlikun 0:13413ea9a877 968 * - Set handle State to READY
ganlikun 0:13413ea9a877 969 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
ganlikun 0:13413ea9a877 970 * @retval HAL status
ganlikun 0:13413ea9a877 971 */
ganlikun 0:13413ea9a877 972 HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 973 {
ganlikun 0:13413ea9a877 974 /* Disable TXEIE and TCIE interrupts */
ganlikun 0:13413ea9a877 975 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
ganlikun 0:13413ea9a877 976
ganlikun 0:13413ea9a877 977 /* Disable the IRDA DMA Tx request if enabled */
ganlikun 0:13413ea9a877 978 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
ganlikun 0:13413ea9a877 979 {
ganlikun 0:13413ea9a877 980 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 981
ganlikun 0:13413ea9a877 982 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
ganlikun 0:13413ea9a877 983 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 984 {
ganlikun 0:13413ea9a877 985 /* Set the IRDA DMA Abort callback to Null.
ganlikun 0:13413ea9a877 986 No call back execution at end of DMA abort procedure */
ganlikun 0:13413ea9a877 987 hirda->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 988
ganlikun 0:13413ea9a877 989 HAL_DMA_Abort(hirda->hdmatx);
ganlikun 0:13413ea9a877 990 }
ganlikun 0:13413ea9a877 991 }
ganlikun 0:13413ea9a877 992
ganlikun 0:13413ea9a877 993 /* Reset Tx transfer counter */
ganlikun 0:13413ea9a877 994 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 995
ganlikun 0:13413ea9a877 996 /* Restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 997 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 998
ganlikun 0:13413ea9a877 999 return HAL_OK;
ganlikun 0:13413ea9a877 1000 }
ganlikun 0:13413ea9a877 1001
ganlikun 0:13413ea9a877 1002 /**
ganlikun 0:13413ea9a877 1003 * @brief Abort ongoing Receive transfer (blocking mode).
ganlikun 0:13413ea9a877 1004 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1005 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
ganlikun 0:13413ea9a877 1006 * This procedure performs following operations :
ganlikun 0:13413ea9a877 1007 * - Disable PPP Interrupts
ganlikun 0:13413ea9a877 1008 * - Disable the DMA transfer in the peripheral register (if enabled)
ganlikun 0:13413ea9a877 1009 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
ganlikun 0:13413ea9a877 1010 * - Set handle State to READY
ganlikun 0:13413ea9a877 1011 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
ganlikun 0:13413ea9a877 1012 * @retval HAL status
ganlikun 0:13413ea9a877 1013 */
ganlikun 0:13413ea9a877 1014 HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1015 {
ganlikun 0:13413ea9a877 1016 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 1017 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ganlikun 0:13413ea9a877 1018 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1019
ganlikun 0:13413ea9a877 1020 /* Disable the IRDA DMA Rx request if enabled */
ganlikun 0:13413ea9a877 1021 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
ganlikun 0:13413ea9a877 1022 {
ganlikun 0:13413ea9a877 1023 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1024
ganlikun 0:13413ea9a877 1025 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
ganlikun 0:13413ea9a877 1026 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 1027 {
ganlikun 0:13413ea9a877 1028 /* Set the IRDA DMA Abort callback to Null.
ganlikun 0:13413ea9a877 1029 No call back execution at end of DMA abort procedure */
ganlikun 0:13413ea9a877 1030 hirda->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1031
ganlikun 0:13413ea9a877 1032 HAL_DMA_Abort(hirda->hdmarx);
ganlikun 0:13413ea9a877 1033 }
ganlikun 0:13413ea9a877 1034 }
ganlikun 0:13413ea9a877 1035
ganlikun 0:13413ea9a877 1036 /* Reset Rx transfer counter */
ganlikun 0:13413ea9a877 1037 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1038
ganlikun 0:13413ea9a877 1039 /* Restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1040 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1041
ganlikun 0:13413ea9a877 1042 return HAL_OK;
ganlikun 0:13413ea9a877 1043 }
ganlikun 0:13413ea9a877 1044
ganlikun 0:13413ea9a877 1045 /**
ganlikun 0:13413ea9a877 1046 * @brief Abort ongoing transfers (Interrupt mode).
ganlikun 0:13413ea9a877 1047 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1048 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
ganlikun 0:13413ea9a877 1049 * This procedure performs following operations :
ganlikun 0:13413ea9a877 1050 * - Disable PPP Interrupts
ganlikun 0:13413ea9a877 1051 * - Disable the DMA transfer in the peripheral register (if enabled)
ganlikun 0:13413ea9a877 1052 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
ganlikun 0:13413ea9a877 1053 * - Set handle State to READY
ganlikun 0:13413ea9a877 1054 * - At abort completion, call user abort complete callback
ganlikun 0:13413ea9a877 1055 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
ganlikun 0:13413ea9a877 1056 * considered as completed only when user abort complete callback is executed (not when exiting function).
ganlikun 0:13413ea9a877 1057 * @retval HAL status
ganlikun 0:13413ea9a877 1058 */
ganlikun 0:13413ea9a877 1059 HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1060 {
ganlikun 0:13413ea9a877 1061 uint32_t AbortCplt = 1U;
ganlikun 0:13413ea9a877 1062
ganlikun 0:13413ea9a877 1063 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 1064 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
ganlikun 0:13413ea9a877 1065 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1066
ganlikun 0:13413ea9a877 1067 /* If DMA Tx and/or DMA Rx Handles are associated to IRDA Handle, DMA Abort complete callbacks should be initialised
ganlikun 0:13413ea9a877 1068 before any call to DMA Abort functions */
ganlikun 0:13413ea9a877 1069 /* DMA Tx Handle is valid */
ganlikun 0:13413ea9a877 1070 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 1071 {
ganlikun 0:13413ea9a877 1072 /* Set DMA Abort Complete callback if IRDA DMA Tx request if enabled.
ganlikun 0:13413ea9a877 1073 Otherwise, set it to NULL */
ganlikun 0:13413ea9a877 1074 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
ganlikun 0:13413ea9a877 1075 {
ganlikun 0:13413ea9a877 1076 hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
ganlikun 0:13413ea9a877 1077 }
ganlikun 0:13413ea9a877 1078 else
ganlikun 0:13413ea9a877 1079 {
ganlikun 0:13413ea9a877 1080 hirda->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1081 }
ganlikun 0:13413ea9a877 1082 }
ganlikun 0:13413ea9a877 1083 /* DMA Rx Handle is valid */
ganlikun 0:13413ea9a877 1084 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 1085 {
ganlikun 0:13413ea9a877 1086 /* Set DMA Abort Complete callback if IRDA DMA Rx request if enabled.
ganlikun 0:13413ea9a877 1087 Otherwise, set it to NULL */
ganlikun 0:13413ea9a877 1088 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
ganlikun 0:13413ea9a877 1089 {
ganlikun 0:13413ea9a877 1090 hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
ganlikun 0:13413ea9a877 1091 }
ganlikun 0:13413ea9a877 1092 else
ganlikun 0:13413ea9a877 1093 {
ganlikun 0:13413ea9a877 1094 hirda->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1095 }
ganlikun 0:13413ea9a877 1096 }
ganlikun 0:13413ea9a877 1097
ganlikun 0:13413ea9a877 1098 /* Disable the IRDA DMA Tx request if enabled */
ganlikun 0:13413ea9a877 1099 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
ganlikun 0:13413ea9a877 1100 {
ganlikun 0:13413ea9a877 1101 /* Disable DMA Tx at IRDA level */
ganlikun 0:13413ea9a877 1102 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 1103
ganlikun 0:13413ea9a877 1104 /* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
ganlikun 0:13413ea9a877 1105 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 1106 {
ganlikun 0:13413ea9a877 1107 /* IRDA Tx DMA Abort callback has already been initialised :
ganlikun 0:13413ea9a877 1108 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 1109
ganlikun 0:13413ea9a877 1110 /* Abort DMA TX */
ganlikun 0:13413ea9a877 1111 if(HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
ganlikun 0:13413ea9a877 1112 {
ganlikun 0:13413ea9a877 1113 hirda->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1114 }
ganlikun 0:13413ea9a877 1115 else
ganlikun 0:13413ea9a877 1116 {
ganlikun 0:13413ea9a877 1117 AbortCplt = 0x00U;
ganlikun 0:13413ea9a877 1118 }
ganlikun 0:13413ea9a877 1119 }
ganlikun 0:13413ea9a877 1120 }
ganlikun 0:13413ea9a877 1121
ganlikun 0:13413ea9a877 1122 /* Disable the IRDA DMA Rx request if enabled */
ganlikun 0:13413ea9a877 1123 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
ganlikun 0:13413ea9a877 1124 {
ganlikun 0:13413ea9a877 1125 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1126
ganlikun 0:13413ea9a877 1127 /* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
ganlikun 0:13413ea9a877 1128 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 1129 {
ganlikun 0:13413ea9a877 1130 /* IRDA Rx DMA Abort callback has already been initialised :
ganlikun 0:13413ea9a877 1131 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 1132
ganlikun 0:13413ea9a877 1133 /* Abort DMA RX */
ganlikun 0:13413ea9a877 1134 if(HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
ganlikun 0:13413ea9a877 1135 {
ganlikun 0:13413ea9a877 1136 hirda->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1137 AbortCplt = 0x01U;
ganlikun 0:13413ea9a877 1138 }
ganlikun 0:13413ea9a877 1139 else
ganlikun 0:13413ea9a877 1140 {
ganlikun 0:13413ea9a877 1141 AbortCplt = 0x00U;
ganlikun 0:13413ea9a877 1142 }
ganlikun 0:13413ea9a877 1143 }
ganlikun 0:13413ea9a877 1144 }
ganlikun 0:13413ea9a877 1145
ganlikun 0:13413ea9a877 1146 /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
ganlikun 0:13413ea9a877 1147 if(AbortCplt == 0x01U)
ganlikun 0:13413ea9a877 1148 {
ganlikun 0:13413ea9a877 1149 /* Reset Tx and Rx transfer counters */
ganlikun 0:13413ea9a877 1150 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1151 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1152
ganlikun 0:13413ea9a877 1153 /* Reset ErrorCode */
ganlikun 0:13413ea9a877 1154 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 1155
ganlikun 0:13413ea9a877 1156 /* Restore hirda->gState and hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1157 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1158 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1159
ganlikun 0:13413ea9a877 1160 /* As no DMA to be aborted, call directly user Abort complete callback */
ganlikun 0:13413ea9a877 1161 HAL_IRDA_AbortCpltCallback(hirda);
ganlikun 0:13413ea9a877 1162 }
ganlikun 0:13413ea9a877 1163
ganlikun 0:13413ea9a877 1164 return HAL_OK;
ganlikun 0:13413ea9a877 1165 }
ganlikun 0:13413ea9a877 1166
ganlikun 0:13413ea9a877 1167 /**
ganlikun 0:13413ea9a877 1168 * @brief Abort ongoing Transmit transfer (Interrupt mode).
ganlikun 0:13413ea9a877 1169 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1170 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
ganlikun 0:13413ea9a877 1171 * This procedure performs following operations :
ganlikun 0:13413ea9a877 1172 * - Disable PPP Interrupts
ganlikun 0:13413ea9a877 1173 * - Disable the DMA transfer in the peripheral register (if enabled)
ganlikun 0:13413ea9a877 1174 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
ganlikun 0:13413ea9a877 1175 * - Set handle State to READY
ganlikun 0:13413ea9a877 1176 * - At abort completion, call user abort complete callback
ganlikun 0:13413ea9a877 1177 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
ganlikun 0:13413ea9a877 1178 * considered as completed only when user abort complete callback is executed (not when exiting function).
ganlikun 0:13413ea9a877 1179 * @retval HAL status
ganlikun 0:13413ea9a877 1180 */
ganlikun 0:13413ea9a877 1181 HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1182 {
ganlikun 0:13413ea9a877 1183 /* Disable TXEIE and TCIE interrupts */
ganlikun 0:13413ea9a877 1184 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
ganlikun 0:13413ea9a877 1185
ganlikun 0:13413ea9a877 1186 /* Disable the IRDA DMA Tx request if enabled */
ganlikun 0:13413ea9a877 1187 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
ganlikun 0:13413ea9a877 1188 {
ganlikun 0:13413ea9a877 1189 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 1190
ganlikun 0:13413ea9a877 1191 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
ganlikun 0:13413ea9a877 1192 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 1193 {
ganlikun 0:13413ea9a877 1194 /* Set the IRDA DMA Abort callback :
ganlikun 0:13413ea9a877 1195 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 1196 hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;
ganlikun 0:13413ea9a877 1197
ganlikun 0:13413ea9a877 1198 /* Abort DMA TX */
ganlikun 0:13413ea9a877 1199 if(HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
ganlikun 0:13413ea9a877 1200 {
ganlikun 0:13413ea9a877 1201 /* Call Directly hirda->hdmatx->XferAbortCallback function in case of error */
ganlikun 0:13413ea9a877 1202 hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
ganlikun 0:13413ea9a877 1203 }
ganlikun 0:13413ea9a877 1204 }
ganlikun 0:13413ea9a877 1205 else
ganlikun 0:13413ea9a877 1206 {
ganlikun 0:13413ea9a877 1207 /* Reset Tx transfer counter */
ganlikun 0:13413ea9a877 1208 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1209
ganlikun 0:13413ea9a877 1210 /* Restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 1211 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1212
ganlikun 0:13413ea9a877 1213 /* As no DMA to be aborted, call directly user Abort complete callback */
ganlikun 0:13413ea9a877 1214 HAL_IRDA_AbortTransmitCpltCallback(hirda);
ganlikun 0:13413ea9a877 1215 }
ganlikun 0:13413ea9a877 1216 }
ganlikun 0:13413ea9a877 1217 else
ganlikun 0:13413ea9a877 1218 {
ganlikun 0:13413ea9a877 1219 /* Reset Tx transfer counter */
ganlikun 0:13413ea9a877 1220 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1221
ganlikun 0:13413ea9a877 1222 /* Restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 1223 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1224
ganlikun 0:13413ea9a877 1225 /* As no DMA to be aborted, call directly user Abort complete callback */
ganlikun 0:13413ea9a877 1226 HAL_IRDA_AbortTransmitCpltCallback(hirda);
ganlikun 0:13413ea9a877 1227 }
ganlikun 0:13413ea9a877 1228
ganlikun 0:13413ea9a877 1229 return HAL_OK;
ganlikun 0:13413ea9a877 1230 }
ganlikun 0:13413ea9a877 1231
ganlikun 0:13413ea9a877 1232 /**
ganlikun 0:13413ea9a877 1233 * @brief Abort ongoing Receive transfer (Interrupt mode).
ganlikun 0:13413ea9a877 1234 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1235 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
ganlikun 0:13413ea9a877 1236 * This procedure performs following operations :
ganlikun 0:13413ea9a877 1237 * - Disable PPP Interrupts
ganlikun 0:13413ea9a877 1238 * - Disable the DMA transfer in the peripheral register (if enabled)
ganlikun 0:13413ea9a877 1239 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
ganlikun 0:13413ea9a877 1240 * - Set handle State to READY
ganlikun 0:13413ea9a877 1241 * - At abort completion, call user abort complete callback
ganlikun 0:13413ea9a877 1242 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
ganlikun 0:13413ea9a877 1243 * considered as completed only when user abort complete callback is executed (not when exiting function).
ganlikun 0:13413ea9a877 1244 * @retval HAL status
ganlikun 0:13413ea9a877 1245 */
ganlikun 0:13413ea9a877 1246 HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1247 {
ganlikun 0:13413ea9a877 1248 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 1249 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ganlikun 0:13413ea9a877 1250 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1251
ganlikun 0:13413ea9a877 1252 /* Disable the IRDA DMA Rx request if enabled */
ganlikun 0:13413ea9a877 1253 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
ganlikun 0:13413ea9a877 1254 {
ganlikun 0:13413ea9a877 1255 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1256
ganlikun 0:13413ea9a877 1257 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
ganlikun 0:13413ea9a877 1258 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 1259 {
ganlikun 0:13413ea9a877 1260 /* Set the IRDA DMA Abort callback :
ganlikun 0:13413ea9a877 1261 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 1262 hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;
ganlikun 0:13413ea9a877 1263
ganlikun 0:13413ea9a877 1264 /* Abort DMA RX */
ganlikun 0:13413ea9a877 1265 if(HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
ganlikun 0:13413ea9a877 1266 {
ganlikun 0:13413ea9a877 1267 /* Call Directly hirda->hdmarx->XferAbortCallback function in case of error */
ganlikun 0:13413ea9a877 1268 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
ganlikun 0:13413ea9a877 1269 }
ganlikun 0:13413ea9a877 1270 }
ganlikun 0:13413ea9a877 1271 else
ganlikun 0:13413ea9a877 1272 {
ganlikun 0:13413ea9a877 1273 /* Reset Rx transfer counter */
ganlikun 0:13413ea9a877 1274 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1275
ganlikun 0:13413ea9a877 1276 /* Restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1277 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1278
ganlikun 0:13413ea9a877 1279 /* As no DMA to be aborted, call directly user Abort complete callback */
ganlikun 0:13413ea9a877 1280 HAL_IRDA_AbortReceiveCpltCallback(hirda);
ganlikun 0:13413ea9a877 1281 }
ganlikun 0:13413ea9a877 1282 }
ganlikun 0:13413ea9a877 1283 else
ganlikun 0:13413ea9a877 1284 {
ganlikun 0:13413ea9a877 1285 /* Reset Rx transfer counter */
ganlikun 0:13413ea9a877 1286 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1287
ganlikun 0:13413ea9a877 1288 /* Restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1289 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1290
ganlikun 0:13413ea9a877 1291 /* As no DMA to be aborted, call directly user Abort complete callback */
ganlikun 0:13413ea9a877 1292 HAL_IRDA_AbortReceiveCpltCallback(hirda);
ganlikun 0:13413ea9a877 1293 }
ganlikun 0:13413ea9a877 1294
ganlikun 0:13413ea9a877 1295 return HAL_OK;
ganlikun 0:13413ea9a877 1296 }
ganlikun 0:13413ea9a877 1297
ganlikun 0:13413ea9a877 1298 /**
ganlikun 0:13413ea9a877 1299 * @brief This function handles IRDA interrupt request.
ganlikun 0:13413ea9a877 1300 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1301 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1302 * @retval None
ganlikun 0:13413ea9a877 1303 */
ganlikun 0:13413ea9a877 1304 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1305 {
ganlikun 0:13413ea9a877 1306 uint32_t isrflags = READ_REG(hirda->Instance->SR);
ganlikun 0:13413ea9a877 1307 uint32_t cr1its = READ_REG(hirda->Instance->CR1);
ganlikun 0:13413ea9a877 1308 uint32_t cr3its = READ_REG(hirda->Instance->CR3);
ganlikun 0:13413ea9a877 1309 uint32_t errorflags = 0x00U;
ganlikun 0:13413ea9a877 1310 uint32_t dmarequest = 0x00U;
ganlikun 0:13413ea9a877 1311
ganlikun 0:13413ea9a877 1312 /* If no error occurs */
ganlikun 0:13413ea9a877 1313 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
ganlikun 0:13413ea9a877 1314 if(errorflags == RESET)
ganlikun 0:13413ea9a877 1315 {
ganlikun 0:13413ea9a877 1316 /* IRDA in mode Receiver -----------------------------------------------*/
ganlikun 0:13413ea9a877 1317 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
ganlikun 0:13413ea9a877 1318 {
ganlikun 0:13413ea9a877 1319 IRDA_Receive_IT(hirda);
ganlikun 0:13413ea9a877 1320 return;
ganlikun 0:13413ea9a877 1321 }
ganlikun 0:13413ea9a877 1322 }
ganlikun 0:13413ea9a877 1323
ganlikun 0:13413ea9a877 1324 /* If some errors occur */
ganlikun 0:13413ea9a877 1325 if((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
ganlikun 0:13413ea9a877 1326 {
ganlikun 0:13413ea9a877 1327 /* IRDA parity error interrupt occurred -------------------------------*/
ganlikun 0:13413ea9a877 1328 if(((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
ganlikun 0:13413ea9a877 1329 {
ganlikun 0:13413ea9a877 1330 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
ganlikun 0:13413ea9a877 1331 }
ganlikun 0:13413ea9a877 1332
ganlikun 0:13413ea9a877 1333 /* IRDA noise error interrupt occurred --------------------------------*/
ganlikun 0:13413ea9a877 1334 if(((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
ganlikun 0:13413ea9a877 1335 {
ganlikun 0:13413ea9a877 1336 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
ganlikun 0:13413ea9a877 1337 }
ganlikun 0:13413ea9a877 1338
ganlikun 0:13413ea9a877 1339 /* IRDA frame error interrupt occurred --------------------------------*/
ganlikun 0:13413ea9a877 1340 if(((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
ganlikun 0:13413ea9a877 1341 {
ganlikun 0:13413ea9a877 1342 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
ganlikun 0:13413ea9a877 1343 }
ganlikun 0:13413ea9a877 1344
ganlikun 0:13413ea9a877 1345 /* IRDA Over-Run interrupt occurred -----------------------------------*/
ganlikun 0:13413ea9a877 1346 if(((isrflags & USART_SR_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
ganlikun 0:13413ea9a877 1347 {
ganlikun 0:13413ea9a877 1348 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
ganlikun 0:13413ea9a877 1349 }
ganlikun 0:13413ea9a877 1350 /* Call IRDA Error Call back function if need be -----------------------*/
ganlikun 0:13413ea9a877 1351 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
ganlikun 0:13413ea9a877 1352 {
ganlikun 0:13413ea9a877 1353 /* IRDA in mode Receiver ---------------------------------------------*/
ganlikun 0:13413ea9a877 1354 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
ganlikun 0:13413ea9a877 1355 {
ganlikun 0:13413ea9a877 1356 IRDA_Receive_IT(hirda);
ganlikun 0:13413ea9a877 1357 }
ganlikun 0:13413ea9a877 1358
ganlikun 0:13413ea9a877 1359 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1360 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
ganlikun 0:13413ea9a877 1361 consider error as blocking */
ganlikun 0:13413ea9a877 1362 if(((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest)
ganlikun 0:13413ea9a877 1363 {
ganlikun 0:13413ea9a877 1364 /* Blocking error : transfer is aborted
ganlikun 0:13413ea9a877 1365 Set the IRDA state ready to be able to start again the process,
ganlikun 0:13413ea9a877 1366 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
ganlikun 0:13413ea9a877 1367 IRDA_EndRxTransfer(hirda);
ganlikun 0:13413ea9a877 1368
ganlikun 0:13413ea9a877 1369 /* Disable the IRDA DMA Rx request if enabled */
ganlikun 0:13413ea9a877 1370 if(HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
ganlikun 0:13413ea9a877 1371 {
ganlikun 0:13413ea9a877 1372 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1373
ganlikun 0:13413ea9a877 1374 /* Abort the IRDA DMA Rx channel */
ganlikun 0:13413ea9a877 1375 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 1376 {
ganlikun 0:13413ea9a877 1377 /* Set the IRDA DMA Abort callback :
ganlikun 0:13413ea9a877 1378 will lead to call HAL_IRDA_ErrorCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 1379 hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;
ganlikun 0:13413ea9a877 1380
ganlikun 0:13413ea9a877 1381 if(HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
ganlikun 0:13413ea9a877 1382 {
ganlikun 0:13413ea9a877 1383 /* Call Directly XferAbortCallback function in case of error */
ganlikun 0:13413ea9a877 1384 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
ganlikun 0:13413ea9a877 1385 }
ganlikun 0:13413ea9a877 1386 }
ganlikun 0:13413ea9a877 1387 else
ganlikun 0:13413ea9a877 1388 {
ganlikun 0:13413ea9a877 1389 /* Call user error callback */
ganlikun 0:13413ea9a877 1390 HAL_IRDA_ErrorCallback(hirda);
ganlikun 0:13413ea9a877 1391 }
ganlikun 0:13413ea9a877 1392 }
ganlikun 0:13413ea9a877 1393 else
ganlikun 0:13413ea9a877 1394 {
ganlikun 0:13413ea9a877 1395 /* Call user error callback */
ganlikun 0:13413ea9a877 1396 HAL_IRDA_ErrorCallback(hirda);
ganlikun 0:13413ea9a877 1397 }
ganlikun 0:13413ea9a877 1398 }
ganlikun 0:13413ea9a877 1399 else
ganlikun 0:13413ea9a877 1400 {
ganlikun 0:13413ea9a877 1401 /* Non Blocking error : transfer could go on.
ganlikun 0:13413ea9a877 1402 Error is notified to user through user error callback */
ganlikun 0:13413ea9a877 1403 HAL_IRDA_ErrorCallback(hirda);
ganlikun 0:13413ea9a877 1404 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 1405 }
ganlikun 0:13413ea9a877 1406 }
ganlikun 0:13413ea9a877 1407 return;
ganlikun 0:13413ea9a877 1408 } /* End if some error occurs */
ganlikun 0:13413ea9a877 1409
ganlikun 0:13413ea9a877 1410 /* IRDA in mode Transmitter ------------------------------------------------*/
ganlikun 0:13413ea9a877 1411 if(((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
ganlikun 0:13413ea9a877 1412 {
ganlikun 0:13413ea9a877 1413 IRDA_Transmit_IT(hirda);
ganlikun 0:13413ea9a877 1414 return;
ganlikun 0:13413ea9a877 1415 }
ganlikun 0:13413ea9a877 1416
ganlikun 0:13413ea9a877 1417 /* IRDA in mode Transmitter end --------------------------------------------*/
ganlikun 0:13413ea9a877 1418 if(((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
ganlikun 0:13413ea9a877 1419 {
ganlikun 0:13413ea9a877 1420 IRDA_EndTransmit_IT(hirda);
ganlikun 0:13413ea9a877 1421 return;
ganlikun 0:13413ea9a877 1422 }
ganlikun 0:13413ea9a877 1423 }
ganlikun 0:13413ea9a877 1424
ganlikun 0:13413ea9a877 1425 /**
ganlikun 0:13413ea9a877 1426 * @brief End ongoing Tx transfer on IRDA peripheral (following error detection or Transmit completion).
ganlikun 0:13413ea9a877 1427 * @param hirda: IRDA handle.
ganlikun 0:13413ea9a877 1428 * @retval None
ganlikun 0:13413ea9a877 1429 */
ganlikun 0:13413ea9a877 1430 static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1431 {
ganlikun 0:13413ea9a877 1432 /* Disable TXEIE and TCIE interrupts */
ganlikun 0:13413ea9a877 1433 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
ganlikun 0:13413ea9a877 1434
ganlikun 0:13413ea9a877 1435 /* At end of Tx process, restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 1436 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1437 }
ganlikun 0:13413ea9a877 1438
ganlikun 0:13413ea9a877 1439 /**
ganlikun 0:13413ea9a877 1440 * @brief End ongoing Rx transfer on IRDA peripheral (following error detection or Reception completion).
ganlikun 0:13413ea9a877 1441 * @param hirda: IRDA handle.
ganlikun 0:13413ea9a877 1442 * @retval None
ganlikun 0:13413ea9a877 1443 */
ganlikun 0:13413ea9a877 1444 static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1445 {
ganlikun 0:13413ea9a877 1446 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 1447 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ganlikun 0:13413ea9a877 1448 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1449
ganlikun 0:13413ea9a877 1450 /* At end of Rx process, restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1451 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1452 }
ganlikun 0:13413ea9a877 1453
ganlikun 0:13413ea9a877 1454 /**
ganlikun 0:13413ea9a877 1455 * @brief DMA IRDA communication abort callback, when initiated by HAL services on Error
ganlikun 0:13413ea9a877 1456 * (To be called at end of DMA Abort procedure following error occurrence).
ganlikun 0:13413ea9a877 1457 * @param hdma DMA handle.
ganlikun 0:13413ea9a877 1458 * @retval None
ganlikun 0:13413ea9a877 1459 */
ganlikun 0:13413ea9a877 1460 static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1461 {
ganlikun 0:13413ea9a877 1462 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1463 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1464 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1465
ganlikun 0:13413ea9a877 1466 HAL_IRDA_ErrorCallback(hirda);
ganlikun 0:13413ea9a877 1467 }
ganlikun 0:13413ea9a877 1468
ganlikun 0:13413ea9a877 1469 /**
ganlikun 0:13413ea9a877 1470 * @brief DMA IRDA Tx communication abort callback, when initiated by user
ganlikun 0:13413ea9a877 1471 * (To be called at end of DMA Tx Abort procedure following user abort request).
ganlikun 0:13413ea9a877 1472 * @note When this callback is executed, User Abort complete call back is called only if no
ganlikun 0:13413ea9a877 1473 * Abort still ongoing for Rx DMA Handle.
ganlikun 0:13413ea9a877 1474 * @param hdma DMA handle.
ganlikun 0:13413ea9a877 1475 * @retval None
ganlikun 0:13413ea9a877 1476 */
ganlikun 0:13413ea9a877 1477 static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1478 {
ganlikun 0:13413ea9a877 1479 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1480
ganlikun 0:13413ea9a877 1481 hirda->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1482
ganlikun 0:13413ea9a877 1483 /* Check if an Abort process is still ongoing */
ganlikun 0:13413ea9a877 1484 if(hirda->hdmarx != NULL)
ganlikun 0:13413ea9a877 1485 {
ganlikun 0:13413ea9a877 1486 if(hirda->hdmarx->XferAbortCallback != NULL)
ganlikun 0:13413ea9a877 1487 {
ganlikun 0:13413ea9a877 1488 return;
ganlikun 0:13413ea9a877 1489 }
ganlikun 0:13413ea9a877 1490 }
ganlikun 0:13413ea9a877 1491
ganlikun 0:13413ea9a877 1492 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
ganlikun 0:13413ea9a877 1493 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1494 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1495
ganlikun 0:13413ea9a877 1496 /* Reset ErrorCode */
ganlikun 0:13413ea9a877 1497 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 1498
ganlikun 0:13413ea9a877 1499 /* Restore hirda->gState and hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1500 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1501 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1502
ganlikun 0:13413ea9a877 1503 /* Call user Abort complete callback */
ganlikun 0:13413ea9a877 1504 HAL_IRDA_AbortCpltCallback(hirda);
ganlikun 0:13413ea9a877 1505 }
ganlikun 0:13413ea9a877 1506
ganlikun 0:13413ea9a877 1507 /**
ganlikun 0:13413ea9a877 1508 * @brief DMA IRDA Rx communication abort callback, when initiated by user
ganlikun 0:13413ea9a877 1509 * (To be called at end of DMA Rx Abort procedure following user abort request).
ganlikun 0:13413ea9a877 1510 * @note When this callback is executed, User Abort complete call back is called only if no
ganlikun 0:13413ea9a877 1511 * Abort still ongoing for Tx DMA Handle.
ganlikun 0:13413ea9a877 1512 * @param hdma DMA handle.
ganlikun 0:13413ea9a877 1513 * @retval None
ganlikun 0:13413ea9a877 1514 */
ganlikun 0:13413ea9a877 1515 static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1516 {
ganlikun 0:13413ea9a877 1517 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1518
ganlikun 0:13413ea9a877 1519 hirda->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1520
ganlikun 0:13413ea9a877 1521 /* Check if an Abort process is still ongoing */
ganlikun 0:13413ea9a877 1522 if(hirda->hdmatx != NULL)
ganlikun 0:13413ea9a877 1523 {
ganlikun 0:13413ea9a877 1524 if(hirda->hdmatx->XferAbortCallback != NULL)
ganlikun 0:13413ea9a877 1525 {
ganlikun 0:13413ea9a877 1526 return;
ganlikun 0:13413ea9a877 1527 }
ganlikun 0:13413ea9a877 1528 }
ganlikun 0:13413ea9a877 1529
ganlikun 0:13413ea9a877 1530 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
ganlikun 0:13413ea9a877 1531 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1532 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1533
ganlikun 0:13413ea9a877 1534 /* Reset ErrorCode */
ganlikun 0:13413ea9a877 1535 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
ganlikun 0:13413ea9a877 1536
ganlikun 0:13413ea9a877 1537 /* Restore hirda->gState and hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1538 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1539 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1540
ganlikun 0:13413ea9a877 1541 /* Call user Abort complete callback */
ganlikun 0:13413ea9a877 1542 HAL_IRDA_AbortCpltCallback(hirda);
ganlikun 0:13413ea9a877 1543 }
ganlikun 0:13413ea9a877 1544
ganlikun 0:13413ea9a877 1545 /**
ganlikun 0:13413ea9a877 1546 * @brief DMA IRDA Tx communication abort callback, when initiated by user by a call to
ganlikun 0:13413ea9a877 1547 * HAL_IRDA_AbortTransmit_IT API (Abort only Tx transfer)
ganlikun 0:13413ea9a877 1548 * (This callback is executed at end of DMA Tx Abort procedure following user abort request,
ganlikun 0:13413ea9a877 1549 * and leads to user Tx Abort Complete callback execution).
ganlikun 0:13413ea9a877 1550 * @param hdma DMA handle.
ganlikun 0:13413ea9a877 1551 * @retval None
ganlikun 0:13413ea9a877 1552 */
ganlikun 0:13413ea9a877 1553 static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1554 {
ganlikun 0:13413ea9a877 1555 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1556
ganlikun 0:13413ea9a877 1557 hirda->TxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1558
ganlikun 0:13413ea9a877 1559 /* Restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 1560 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1561
ganlikun 0:13413ea9a877 1562 /* Call user Abort complete callback */
ganlikun 0:13413ea9a877 1563 HAL_IRDA_AbortTransmitCpltCallback(hirda);
ganlikun 0:13413ea9a877 1564 }
ganlikun 0:13413ea9a877 1565
ganlikun 0:13413ea9a877 1566 /**
ganlikun 0:13413ea9a877 1567 * @brief DMA IRDA Rx communication abort callback, when initiated by user by a call to
ganlikun 0:13413ea9a877 1568 * HAL_IRDA_AbortReceive_IT API (Abort only Rx transfer)
ganlikun 0:13413ea9a877 1569 * (This callback is executed at end of DMA Rx Abort procedure following user abort request,
ganlikun 0:13413ea9a877 1570 * and leads to user Rx Abort Complete callback execution).
ganlikun 0:13413ea9a877 1571 * @param hdma DMA handle.
ganlikun 0:13413ea9a877 1572 * @retval None
ganlikun 0:13413ea9a877 1573 */
ganlikun 0:13413ea9a877 1574 static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1575 {
ganlikun 0:13413ea9a877 1576 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1577
ganlikun 0:13413ea9a877 1578 hirda->RxXferCount = 0x00U;
ganlikun 0:13413ea9a877 1579
ganlikun 0:13413ea9a877 1580 /* Restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1581 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1582
ganlikun 0:13413ea9a877 1583 /* Call user Abort complete callback */
ganlikun 0:13413ea9a877 1584 HAL_IRDA_AbortReceiveCpltCallback(hirda);
ganlikun 0:13413ea9a877 1585 }
ganlikun 0:13413ea9a877 1586
ganlikun 0:13413ea9a877 1587 /**
ganlikun 0:13413ea9a877 1588 * @brief Tx Transfer complete callbacks.
ganlikun 0:13413ea9a877 1589 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1590 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1591 * @retval None
ganlikun 0:13413ea9a877 1592 */
ganlikun 0:13413ea9a877 1593 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1594 {
ganlikun 0:13413ea9a877 1595 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1596 UNUSED(hirda);
ganlikun 0:13413ea9a877 1597 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1598 the HAL_IRDA_TxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1599 */
ganlikun 0:13413ea9a877 1600 }
ganlikun 0:13413ea9a877 1601
ganlikun 0:13413ea9a877 1602 /**
ganlikun 0:13413ea9a877 1603 * @brief Tx Half Transfer completed callbacks.
ganlikun 0:13413ea9a877 1604 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1605 * the configuration information for the specified USART module.
ganlikun 0:13413ea9a877 1606 * @retval None
ganlikun 0:13413ea9a877 1607 */
ganlikun 0:13413ea9a877 1608 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1609 {
ganlikun 0:13413ea9a877 1610 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1611 UNUSED(hirda);
ganlikun 0:13413ea9a877 1612 /* NOTE: This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1613 the HAL_IRDA_TxHalfCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1614 */
ganlikun 0:13413ea9a877 1615 }
ganlikun 0:13413ea9a877 1616
ganlikun 0:13413ea9a877 1617 /**
ganlikun 0:13413ea9a877 1618 * @brief Rx Transfer complete callbacks.
ganlikun 0:13413ea9a877 1619 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1620 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1621 * @retval None
ganlikun 0:13413ea9a877 1622 */
ganlikun 0:13413ea9a877 1623 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1624 {
ganlikun 0:13413ea9a877 1625 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1626 UNUSED(hirda);
ganlikun 0:13413ea9a877 1627 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1628 the HAL_IRDA_RxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1629 */
ganlikun 0:13413ea9a877 1630 }
ganlikun 0:13413ea9a877 1631
ganlikun 0:13413ea9a877 1632 /**
ganlikun 0:13413ea9a877 1633 * @brief Rx Half Transfer complete callbacks.
ganlikun 0:13413ea9a877 1634 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1635 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1636 * @retval None
ganlikun 0:13413ea9a877 1637 */
ganlikun 0:13413ea9a877 1638 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1639 {
ganlikun 0:13413ea9a877 1640 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1641 UNUSED(hirda);
ganlikun 0:13413ea9a877 1642 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1643 the HAL_IRDA_RxHalfCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1644 */
ganlikun 0:13413ea9a877 1645 }
ganlikun 0:13413ea9a877 1646
ganlikun 0:13413ea9a877 1647 /**
ganlikun 0:13413ea9a877 1648 * @brief IRDA error callbacks.
ganlikun 0:13413ea9a877 1649 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1650 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1651 * @retval None
ganlikun 0:13413ea9a877 1652 */
ganlikun 0:13413ea9a877 1653 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1654 {
ganlikun 0:13413ea9a877 1655 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1656 UNUSED(hirda);
ganlikun 0:13413ea9a877 1657 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1658 the HAL_IRDA_ErrorCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1659 */
ganlikun 0:13413ea9a877 1660 }
ganlikun 0:13413ea9a877 1661
ganlikun 0:13413ea9a877 1662 /**
ganlikun 0:13413ea9a877 1663 * @brief IRDA Abort Complete callback.
ganlikun 0:13413ea9a877 1664 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1665 * @retval None
ganlikun 0:13413ea9a877 1666 */
ganlikun 0:13413ea9a877 1667 __weak void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1668 {
ganlikun 0:13413ea9a877 1669 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1670 UNUSED(hirda);
ganlikun 0:13413ea9a877 1671
ganlikun 0:13413ea9a877 1672 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1673 the HAL_IRDA_AbortCpltCallback can be implemented in the user file.
ganlikun 0:13413ea9a877 1674 */
ganlikun 0:13413ea9a877 1675 }
ganlikun 0:13413ea9a877 1676
ganlikun 0:13413ea9a877 1677 /**
ganlikun 0:13413ea9a877 1678 * @brief IRDA Abort Transmit Complete callback.
ganlikun 0:13413ea9a877 1679 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1680 * @retval None
ganlikun 0:13413ea9a877 1681 */
ganlikun 0:13413ea9a877 1682 __weak void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1683 {
ganlikun 0:13413ea9a877 1684 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1685 UNUSED(hirda);
ganlikun 0:13413ea9a877 1686
ganlikun 0:13413ea9a877 1687 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1688 the HAL_IRDA_AbortTransmitCpltCallback can be implemented in the user file.
ganlikun 0:13413ea9a877 1689 */
ganlikun 0:13413ea9a877 1690 }
ganlikun 0:13413ea9a877 1691
ganlikun 0:13413ea9a877 1692 /**
ganlikun 0:13413ea9a877 1693 * @brief IRDA Abort ReceiveComplete callback.
ganlikun 0:13413ea9a877 1694 * @param hirda IRDA handle.
ganlikun 0:13413ea9a877 1695 * @retval None
ganlikun 0:13413ea9a877 1696 */
ganlikun 0:13413ea9a877 1697 __weak void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1698 {
ganlikun 0:13413ea9a877 1699 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1700 UNUSED(hirda);
ganlikun 0:13413ea9a877 1701
ganlikun 0:13413ea9a877 1702 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1703 the HAL_IRDA_AbortReceiveCpltCallback can be implemented in the user file.
ganlikun 0:13413ea9a877 1704 */
ganlikun 0:13413ea9a877 1705 }
ganlikun 0:13413ea9a877 1706
ganlikun 0:13413ea9a877 1707 /**
ganlikun 0:13413ea9a877 1708 * @}
ganlikun 0:13413ea9a877 1709 */
ganlikun 0:13413ea9a877 1710
ganlikun 0:13413ea9a877 1711 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions
ganlikun 0:13413ea9a877 1712 * @brief IRDA State and Errors functions
ganlikun 0:13413ea9a877 1713 *
ganlikun 0:13413ea9a877 1714 @verbatim
ganlikun 0:13413ea9a877 1715 ==============================================================================
ganlikun 0:13413ea9a877 1716 ##### Peripheral State and Errors functions #####
ganlikun 0:13413ea9a877 1717 ==============================================================================
ganlikun 0:13413ea9a877 1718 [..]
ganlikun 0:13413ea9a877 1719 This subsection provides a set of functions allowing to return the State of IrDA
ganlikun 0:13413ea9a877 1720 communication process and also return Peripheral Errors occurred during communication process
ganlikun 0:13413ea9a877 1721 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IrDA peripheral.
ganlikun 0:13413ea9a877 1722 (+) HAL_IRDA_GetError() check in run-time errors that could be occurred during communication.
ganlikun 0:13413ea9a877 1723
ganlikun 0:13413ea9a877 1724 @endverbatim
ganlikun 0:13413ea9a877 1725 * @{
ganlikun 0:13413ea9a877 1726 */
ganlikun 0:13413ea9a877 1727
ganlikun 0:13413ea9a877 1728 /**
ganlikun 0:13413ea9a877 1729 * @brief Returns the IRDA state.
ganlikun 0:13413ea9a877 1730 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1731 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1732 * @retval HAL state
ganlikun 0:13413ea9a877 1733 */
ganlikun 0:13413ea9a877 1734 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1735 {
ganlikun 0:13413ea9a877 1736 uint32_t temp1 = 0x00U, temp2 = 0x00U;
ganlikun 0:13413ea9a877 1737 temp1 = hirda->gState;
ganlikun 0:13413ea9a877 1738 temp2 = hirda->RxState;
ganlikun 0:13413ea9a877 1739
ganlikun 0:13413ea9a877 1740 return (HAL_IRDA_StateTypeDef)(temp1 | temp2);
ganlikun 0:13413ea9a877 1741 }
ganlikun 0:13413ea9a877 1742
ganlikun 0:13413ea9a877 1743 /**
ganlikun 0:13413ea9a877 1744 * @brief Return the IARDA error code
ganlikun 0:13413ea9a877 1745 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1746 * the configuration information for the specified IRDA.
ganlikun 0:13413ea9a877 1747 * @retval IRDA Error Code
ganlikun 0:13413ea9a877 1748 */
ganlikun 0:13413ea9a877 1749 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1750 {
ganlikun 0:13413ea9a877 1751 return hirda->ErrorCode;
ganlikun 0:13413ea9a877 1752 }
ganlikun 0:13413ea9a877 1753
ganlikun 0:13413ea9a877 1754 /**
ganlikun 0:13413ea9a877 1755 * @}
ganlikun 0:13413ea9a877 1756 */
ganlikun 0:13413ea9a877 1757
ganlikun 0:13413ea9a877 1758 /**
ganlikun 0:13413ea9a877 1759 * @brief DMA IRDA transmit process complete callback.
ganlikun 0:13413ea9a877 1760 * @param hdma : DMA handle
ganlikun 0:13413ea9a877 1761 * @retval None
ganlikun 0:13413ea9a877 1762 */
ganlikun 0:13413ea9a877 1763 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1764 {
ganlikun 0:13413ea9a877 1765 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1766 /* DMA Normal mode */
ganlikun 0:13413ea9a877 1767 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
ganlikun 0:13413ea9a877 1768 {
ganlikun 0:13413ea9a877 1769 hirda->TxXferCount = 0U;
ganlikun 0:13413ea9a877 1770
ganlikun 0:13413ea9a877 1771 /* Disable the DMA transfer for transmit request by setting the DMAT bit
ganlikun 0:13413ea9a877 1772 in the IRDA CR3 register */
ganlikun 0:13413ea9a877 1773 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 1774
ganlikun 0:13413ea9a877 1775 /* Enable the IRDA Transmit Complete Interrupt */
ganlikun 0:13413ea9a877 1776 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
ganlikun 0:13413ea9a877 1777 }
ganlikun 0:13413ea9a877 1778 /* DMA Circular mode */
ganlikun 0:13413ea9a877 1779 else
ganlikun 0:13413ea9a877 1780 {
ganlikun 0:13413ea9a877 1781 HAL_IRDA_TxCpltCallback(hirda);
ganlikun 0:13413ea9a877 1782 }
ganlikun 0:13413ea9a877 1783 }
ganlikun 0:13413ea9a877 1784
ganlikun 0:13413ea9a877 1785 /**
ganlikun 0:13413ea9a877 1786 * @brief DMA IRDA receive process half complete callback
ganlikun 0:13413ea9a877 1787 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1788 * the configuration information for the specified DMA module.
ganlikun 0:13413ea9a877 1789 * @retval None
ganlikun 0:13413ea9a877 1790 */
ganlikun 0:13413ea9a877 1791 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1792 {
ganlikun 0:13413ea9a877 1793 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1794
ganlikun 0:13413ea9a877 1795 HAL_IRDA_TxHalfCpltCallback(hirda);
ganlikun 0:13413ea9a877 1796 }
ganlikun 0:13413ea9a877 1797
ganlikun 0:13413ea9a877 1798 /**
ganlikun 0:13413ea9a877 1799 * @brief DMA IRDA receive process complete callback.
ganlikun 0:13413ea9a877 1800 * @param hdma: DMA handle
ganlikun 0:13413ea9a877 1801 * @retval None
ganlikun 0:13413ea9a877 1802 */
ganlikun 0:13413ea9a877 1803 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1804 {
ganlikun 0:13413ea9a877 1805 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1806 /* DMA Normal mode */
ganlikun 0:13413ea9a877 1807 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
ganlikun 0:13413ea9a877 1808 {
ganlikun 0:13413ea9a877 1809 hirda->RxXferCount = 0U;
ganlikun 0:13413ea9a877 1810
ganlikun 0:13413ea9a877 1811 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
ganlikun 0:13413ea9a877 1812 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
ganlikun 0:13413ea9a877 1813 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1814
ganlikun 0:13413ea9a877 1815 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
ganlikun 0:13413ea9a877 1816 in the IRDA CR3 register */
ganlikun 0:13413ea9a877 1817 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1818
ganlikun 0:13413ea9a877 1819 /* At end of Rx process, restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 1820 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1821 }
ganlikun 0:13413ea9a877 1822
ganlikun 0:13413ea9a877 1823 HAL_IRDA_RxCpltCallback(hirda);
ganlikun 0:13413ea9a877 1824 }
ganlikun 0:13413ea9a877 1825
ganlikun 0:13413ea9a877 1826 /**
ganlikun 0:13413ea9a877 1827 * @brief DMA IRDA receive process half complete callback
ganlikun 0:13413ea9a877 1828 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1829 * the configuration information for the specified DMA module.
ganlikun 0:13413ea9a877 1830 * @retval None
ganlikun 0:13413ea9a877 1831 */
ganlikun 0:13413ea9a877 1832 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1833 {
ganlikun 0:13413ea9a877 1834 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1835 HAL_IRDA_RxHalfCpltCallback(hirda);
ganlikun 0:13413ea9a877 1836 }
ganlikun 0:13413ea9a877 1837
ganlikun 0:13413ea9a877 1838 /**
ganlikun 0:13413ea9a877 1839 * @brief DMA IRDA communication error callback.
ganlikun 0:13413ea9a877 1840 * @param hdma: DMA handle
ganlikun 0:13413ea9a877 1841 * @retval None
ganlikun 0:13413ea9a877 1842 */
ganlikun 0:13413ea9a877 1843 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1844 {
ganlikun 0:13413ea9a877 1845 uint32_t dmarequest = 0x00U;
ganlikun 0:13413ea9a877 1846 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1847
ganlikun 0:13413ea9a877 1848 /* Stop IRDA DMA Tx request if ongoing */
ganlikun 0:13413ea9a877 1849 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
ganlikun 0:13413ea9a877 1850 if((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
ganlikun 0:13413ea9a877 1851 {
ganlikun 0:13413ea9a877 1852 hirda->TxXferCount = 0U;
ganlikun 0:13413ea9a877 1853 IRDA_EndTxTransfer(hirda);
ganlikun 0:13413ea9a877 1854 }
ganlikun 0:13413ea9a877 1855
ganlikun 0:13413ea9a877 1856 /* Stop IRDA DMA Rx request if ongoing */
ganlikun 0:13413ea9a877 1857 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
ganlikun 0:13413ea9a877 1858 if((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
ganlikun 0:13413ea9a877 1859 {
ganlikun 0:13413ea9a877 1860 hirda->RxXferCount = 0U;
ganlikun 0:13413ea9a877 1861 IRDA_EndRxTransfer(hirda);
ganlikun 0:13413ea9a877 1862 }
ganlikun 0:13413ea9a877 1863
ganlikun 0:13413ea9a877 1864 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
ganlikun 0:13413ea9a877 1865
ganlikun 0:13413ea9a877 1866 HAL_IRDA_ErrorCallback(hirda);
ganlikun 0:13413ea9a877 1867 }
ganlikun 0:13413ea9a877 1868
ganlikun 0:13413ea9a877 1869 /**
ganlikun 0:13413ea9a877 1870 * @brief This function handles IRDA Communication Timeout.
ganlikun 0:13413ea9a877 1871 * @param hirda pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1872 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1873 * @param Flag specifies the IRDA flag to check.
ganlikun 0:13413ea9a877 1874 * @param Status The new Flag status (SET or RESET).
ganlikun 0:13413ea9a877 1875 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 1876 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 1877 * @retval HAL status
ganlikun 0:13413ea9a877 1878 */
ganlikun 0:13413ea9a877 1879 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
ganlikun 0:13413ea9a877 1880 {
ganlikun 0:13413ea9a877 1881 /* Wait until flag is set */
ganlikun 0:13413ea9a877 1882 while((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
ganlikun 0:13413ea9a877 1883 {
ganlikun 0:13413ea9a877 1884 /* Check for the Timeout */
ganlikun 0:13413ea9a877 1885 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 1886 {
ganlikun 0:13413ea9a877 1887 if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))
ganlikun 0:13413ea9a877 1888 {
ganlikun 0:13413ea9a877 1889 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 1890 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
ganlikun 0:13413ea9a877 1891 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1892
ganlikun 0:13413ea9a877 1893 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1894 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1895
ganlikun 0:13413ea9a877 1896 /* Process Unlocked */
ganlikun 0:13413ea9a877 1897 __HAL_UNLOCK(hirda);
ganlikun 0:13413ea9a877 1898
ganlikun 0:13413ea9a877 1899 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1900 }
ganlikun 0:13413ea9a877 1901 }
ganlikun 0:13413ea9a877 1902 }
ganlikun 0:13413ea9a877 1903 return HAL_OK;
ganlikun 0:13413ea9a877 1904 }
ganlikun 0:13413ea9a877 1905
ganlikun 0:13413ea9a877 1906 /**
ganlikun 0:13413ea9a877 1907 * @brief Send an amount of data in non blocking mode.
ganlikun 0:13413ea9a877 1908 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1909 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1910 * @retval HAL status
ganlikun 0:13413ea9a877 1911 */
ganlikun 0:13413ea9a877 1912 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1913 {
ganlikun 0:13413ea9a877 1914 uint16_t* tmp;
ganlikun 0:13413ea9a877 1915
ganlikun 0:13413ea9a877 1916 /* Check that a Tx process is ongoing */
ganlikun 0:13413ea9a877 1917 if(hirda->gState == HAL_IRDA_STATE_BUSY_TX)
ganlikun 0:13413ea9a877 1918 {
ganlikun 0:13413ea9a877 1919 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
ganlikun 0:13413ea9a877 1920 {
ganlikun 0:13413ea9a877 1921 tmp = (uint16_t*) hirda->pTxBuffPtr;
ganlikun 0:13413ea9a877 1922 hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
ganlikun 0:13413ea9a877 1923 if(hirda->Init.Parity == IRDA_PARITY_NONE)
ganlikun 0:13413ea9a877 1924 {
ganlikun 0:13413ea9a877 1925 hirda->pTxBuffPtr += 2U;
ganlikun 0:13413ea9a877 1926 }
ganlikun 0:13413ea9a877 1927 else
ganlikun 0:13413ea9a877 1928 {
ganlikun 0:13413ea9a877 1929 hirda->pTxBuffPtr += 1U;
ganlikun 0:13413ea9a877 1930 }
ganlikun 0:13413ea9a877 1931 }
ganlikun 0:13413ea9a877 1932 else
ganlikun 0:13413ea9a877 1933 {
ganlikun 0:13413ea9a877 1934 hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
ganlikun 0:13413ea9a877 1935 }
ganlikun 0:13413ea9a877 1936
ganlikun 0:13413ea9a877 1937 if(--hirda->TxXferCount == 0U)
ganlikun 0:13413ea9a877 1938 {
ganlikun 0:13413ea9a877 1939 /* Disable the IRDA Transmit Data Register Empty Interrupt */
ganlikun 0:13413ea9a877 1940 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
ganlikun 0:13413ea9a877 1941
ganlikun 0:13413ea9a877 1942 /* Enable the IRDA Transmit Complete Interrupt */
ganlikun 0:13413ea9a877 1943 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
ganlikun 0:13413ea9a877 1944 }
ganlikun 0:13413ea9a877 1945
ganlikun 0:13413ea9a877 1946 return HAL_OK;
ganlikun 0:13413ea9a877 1947 }
ganlikun 0:13413ea9a877 1948 else
ganlikun 0:13413ea9a877 1949 {
ganlikun 0:13413ea9a877 1950 return HAL_BUSY;
ganlikun 0:13413ea9a877 1951 }
ganlikun 0:13413ea9a877 1952 }
ganlikun 0:13413ea9a877 1953
ganlikun 0:13413ea9a877 1954 /**
ganlikun 0:13413ea9a877 1955 * @brief Wraps up transmission in non blocking mode.
ganlikun 0:13413ea9a877 1956 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1957 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1958 * @retval HAL status
ganlikun 0:13413ea9a877 1959 */
ganlikun 0:13413ea9a877 1960 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1961 {
ganlikun 0:13413ea9a877 1962 /* Disable the IRDA Transmit Complete Interrupt */
ganlikun 0:13413ea9a877 1963 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
ganlikun 0:13413ea9a877 1964
ganlikun 0:13413ea9a877 1965 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
ganlikun 0:13413ea9a877 1966 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 1967
ganlikun 0:13413ea9a877 1968 /* Tx process is ended, restore hirda->gState to Ready */
ganlikun 0:13413ea9a877 1969 hirda->gState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 1970
ganlikun 0:13413ea9a877 1971 HAL_IRDA_TxCpltCallback(hirda);
ganlikun 0:13413ea9a877 1972
ganlikun 0:13413ea9a877 1973 return HAL_OK;
ganlikun 0:13413ea9a877 1974 }
ganlikun 0:13413ea9a877 1975
ganlikun 0:13413ea9a877 1976 /**
ganlikun 0:13413ea9a877 1977 * @brief Receives an amount of data in non blocking mode.
ganlikun 0:13413ea9a877 1978 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1979 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 1980 * @retval HAL status
ganlikun 0:13413ea9a877 1981 */
ganlikun 0:13413ea9a877 1982 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 1983 {
ganlikun 0:13413ea9a877 1984 uint16_t* tmp;
ganlikun 0:13413ea9a877 1985 uint16_t uhdata;
ganlikun 0:13413ea9a877 1986
ganlikun 0:13413ea9a877 1987 /* Check that a Rx process is ongoing */
ganlikun 0:13413ea9a877 1988 if(hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
ganlikun 0:13413ea9a877 1989 {
ganlikun 0:13413ea9a877 1990 uhdata = (uint16_t) READ_REG(hirda->Instance->DR);
ganlikun 0:13413ea9a877 1991 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
ganlikun 0:13413ea9a877 1992 {
ganlikun 0:13413ea9a877 1993 tmp = (uint16_t*) hirda->pRxBuffPtr;
ganlikun 0:13413ea9a877 1994 if(hirda->Init.Parity == IRDA_PARITY_NONE)
ganlikun 0:13413ea9a877 1995 {
ganlikun 0:13413ea9a877 1996 *tmp = (uint16_t)(uhdata & (uint16_t)0x01FF);
ganlikun 0:13413ea9a877 1997 hirda->pRxBuffPtr += 2U;
ganlikun 0:13413ea9a877 1998 }
ganlikun 0:13413ea9a877 1999 else
ganlikun 0:13413ea9a877 2000 {
ganlikun 0:13413ea9a877 2001 *tmp = (uint16_t)(uhdata & (uint16_t)0x00FF);
ganlikun 0:13413ea9a877 2002 hirda->pRxBuffPtr += 1U;
ganlikun 0:13413ea9a877 2003 }
ganlikun 0:13413ea9a877 2004 }
ganlikun 0:13413ea9a877 2005 else
ganlikun 0:13413ea9a877 2006 {
ganlikun 0:13413ea9a877 2007 if(hirda->Init.Parity == IRDA_PARITY_NONE)
ganlikun 0:13413ea9a877 2008 {
ganlikun 0:13413ea9a877 2009 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x00FF);
ganlikun 0:13413ea9a877 2010 }
ganlikun 0:13413ea9a877 2011 else
ganlikun 0:13413ea9a877 2012 {
ganlikun 0:13413ea9a877 2013 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x007F);
ganlikun 0:13413ea9a877 2014 }
ganlikun 0:13413ea9a877 2015 }
ganlikun 0:13413ea9a877 2016
ganlikun 0:13413ea9a877 2017 if(--hirda->RxXferCount == 0U)
ganlikun 0:13413ea9a877 2018 {
ganlikun 0:13413ea9a877 2019 /* Disable the IRDA Data Register not empty Interrupt */
ganlikun 0:13413ea9a877 2020 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
ganlikun 0:13413ea9a877 2021
ganlikun 0:13413ea9a877 2022 /* Disable the IRDA Parity Error Interrupt */
ganlikun 0:13413ea9a877 2023 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
ganlikun 0:13413ea9a877 2024
ganlikun 0:13413ea9a877 2025 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
ganlikun 0:13413ea9a877 2026 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
ganlikun 0:13413ea9a877 2027
ganlikun 0:13413ea9a877 2028 /* Rx process is completed, restore hirda->RxState to Ready */
ganlikun 0:13413ea9a877 2029 hirda->RxState = HAL_IRDA_STATE_READY;
ganlikun 0:13413ea9a877 2030
ganlikun 0:13413ea9a877 2031 HAL_IRDA_RxCpltCallback(hirda);
ganlikun 0:13413ea9a877 2032
ganlikun 0:13413ea9a877 2033 return HAL_OK;
ganlikun 0:13413ea9a877 2034 }
ganlikun 0:13413ea9a877 2035 return HAL_OK;
ganlikun 0:13413ea9a877 2036 }
ganlikun 0:13413ea9a877 2037 else
ganlikun 0:13413ea9a877 2038 {
ganlikun 0:13413ea9a877 2039 return HAL_BUSY;
ganlikun 0:13413ea9a877 2040 }
ganlikun 0:13413ea9a877 2041 }
ganlikun 0:13413ea9a877 2042
ganlikun 0:13413ea9a877 2043 /**
ganlikun 0:13413ea9a877 2044 * @brief Configures the IRDA peripheral.
ganlikun 0:13413ea9a877 2045 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2046 * the configuration information for the specified IRDA module.
ganlikun 0:13413ea9a877 2047 * @retval None
ganlikun 0:13413ea9a877 2048 */
ganlikun 0:13413ea9a877 2049 static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
ganlikun 0:13413ea9a877 2050 {
ganlikun 0:13413ea9a877 2051 /* Check the parameters */
ganlikun 0:13413ea9a877 2052 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
ganlikun 0:13413ea9a877 2053 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
ganlikun 0:13413ea9a877 2054 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
ganlikun 0:13413ea9a877 2055 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
ganlikun 0:13413ea9a877 2056 assert_param(IS_IRDA_MODE(hirda->Init.Mode));
ganlikun 0:13413ea9a877 2057
ganlikun 0:13413ea9a877 2058 /*-------------------------- IRDA CR2 Configuration ------------------------*/
ganlikun 0:13413ea9a877 2059 /* Clear STOP[13:12] bits */
ganlikun 0:13413ea9a877 2060 CLEAR_BIT(hirda->Instance->CR2, USART_CR2_STOP);
ganlikun 0:13413ea9a877 2061
ganlikun 0:13413ea9a877 2062 /*-------------------------- USART CR1 Configuration -----------------------*/
ganlikun 0:13413ea9a877 2063 /* Clear M, PCE, PS, TE and RE bits */
ganlikun 0:13413ea9a877 2064 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE);
ganlikun 0:13413ea9a877 2065
ganlikun 0:13413ea9a877 2066 /* Configure the USART Word Length, Parity and mode:
ganlikun 0:13413ea9a877 2067 Set the M bits according to hirda->Init.WordLength value
ganlikun 0:13413ea9a877 2068 Set PCE and PS bits according to hirda->Init.Parity value
ganlikun 0:13413ea9a877 2069 Set TE and RE bits according to hirda->Init.Mode value */
ganlikun 0:13413ea9a877 2070 /* Write to USART CR1 */
ganlikun 0:13413ea9a877 2071 SET_BIT(hirda->Instance->CR1, (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode);
ganlikun 0:13413ea9a877 2072
ganlikun 0:13413ea9a877 2073 /*-------------------------- USART CR3 Configuration -----------------------*/
ganlikun 0:13413ea9a877 2074 /* Clear CTSE and RTSE bits */
ganlikun 0:13413ea9a877 2075 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_RTSE | USART_CR3_CTSE);
ganlikun 0:13413ea9a877 2076
ganlikun 0:13413ea9a877 2077 /*-------------------------- USART BRR Configuration -----------------------*/
ganlikun 0:13413ea9a877 2078 #if defined(USART6)
ganlikun 0:13413ea9a877 2079 if((hirda->Instance == USART1) || (hirda->Instance == USART6))
ganlikun 0:13413ea9a877 2080 {
ganlikun 0:13413ea9a877 2081 SET_BIT(hirda->Instance->BRR, IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate));
ganlikun 0:13413ea9a877 2082 }
ganlikun 0:13413ea9a877 2083 #else
ganlikun 0:13413ea9a877 2084 if(hirda->Instance == USART1)
ganlikun 0:13413ea9a877 2085 {
ganlikun 0:13413ea9a877 2086 SET_BIT(hirda->Instance->BRR, IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate));
ganlikun 0:13413ea9a877 2087 }
ganlikun 0:13413ea9a877 2088 #endif /* USART6 */
ganlikun 0:13413ea9a877 2089 else
ganlikun 0:13413ea9a877 2090 {
ganlikun 0:13413ea9a877 2091 SET_BIT(hirda->Instance->BRR, IRDA_BRR(HAL_RCC_GetPCLK1Freq(), hirda->Init.BaudRate));
ganlikun 0:13413ea9a877 2092 }
ganlikun 0:13413ea9a877 2093 }
ganlikun 0:13413ea9a877 2094
ganlikun 0:13413ea9a877 2095 /**
ganlikun 0:13413ea9a877 2096 * @}
ganlikun 0:13413ea9a877 2097 */
ganlikun 0:13413ea9a877 2098
ganlikun 0:13413ea9a877 2099 #endif /* HAL_IRDA_MODULE_ENABLED */
ganlikun 0:13413ea9a877 2100 /**
ganlikun 0:13413ea9a877 2101 * @}
ganlikun 0:13413ea9a877 2102 */
ganlikun 0:13413ea9a877 2103
ganlikun 0:13413ea9a877 2104 /**
ganlikun 0:13413ea9a877 2105 * @}
ganlikun 0:13413ea9a877 2106 */
ganlikun 0:13413ea9a877 2107
ganlikun 0:13413ea9a877 2108 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 2109