Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 14:00:11 2015 +0100
Revision:
632:7687fb9c4f91
Parent:
385:be64abf45658
Child:
634:ac7d6880524d
Synchronized with git revision f7ce4ed029cc611121464252ff28d5e8beb895b0

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

NUCLEO_F303K8 - add support of the STM32F303K8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_irda.c
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 632:7687fb9c4f91 5 * @version V1.1.1
mbed_official 632:7687fb9c4f91 6 * @date 19-June-2015
mbed_official 237:f3da66175598 7 * @brief IRDA HAL module driver.
mbed_official 237:f3da66175598 8 *
mbed_official 237:f3da66175598 9 * This file provides firmware functions to manage the following
mbed_official 237:f3da66175598 10 * functionalities of the IrDA (Infrared Data Association) Peripheral
mbed_official 237:f3da66175598 11 * (IRDA)
mbed_official 237:f3da66175598 12 * + Initialization and de-initialization functions
mbed_official 237:f3da66175598 13 * + IO operation functions
mbed_official 237:f3da66175598 14 * + Peripheral Control functions
mbed_official 237:f3da66175598 15 *
mbed_official 237:f3da66175598 16 *
mbed_official 237:f3da66175598 17 @verbatim
mbed_official 237:f3da66175598 18 ===============================================================================
mbed_official 237:f3da66175598 19 ##### How to use this driver #####
mbed_official 237:f3da66175598 20 ===============================================================================
mbed_official 237:f3da66175598 21 [..]
mbed_official 237:f3da66175598 22 The IRDA HAL driver can be used as follows:
mbed_official 237:f3da66175598 23
mbed_official 237:f3da66175598 24 (#) Declare a IRDA_HandleTypeDef handle structure.
mbed_official 237:f3da66175598 25 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API
mbed_official 237:f3da66175598 26 in setting the associated USART or UART in IRDA mode:
mbed_official 237:f3da66175598 27 (##) Enable the USARTx/UARTx interface clock.
mbed_official 237:f3da66175598 28 (##) USARTx/UARTx pins configuration:
mbed_official 237:f3da66175598 29 (+) Enable the clock for the USARTx/UARTx GPIOs.
mbed_official 237:f3da66175598 30 (+) Configure these USARTx/UARTx pins as alternate function pull-up.
mbed_official 237:f3da66175598 31 (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
mbed_official 237:f3da66175598 32 and HAL_IRDA_Receive_IT() APIs):
mbed_official 237:f3da66175598 33 (+) Configure the USARTx/UARTx interrupt priority.
mbed_official 237:f3da66175598 34 (+) Enable the NVIC IRDA IRQ handle.
mbed_official 237:f3da66175598 35 (@) The specific IRDA interrupts (Transmission complete interrupt,
mbed_official 237:f3da66175598 36 RXNE interrupt and Error Interrupts) will be managed using the macros
mbed_official 237:f3da66175598 37 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
mbed_official 237:f3da66175598 38 (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
mbed_official 237:f3da66175598 39 and HAL_IRDA_Receive_DMA() APIs):
mbed_official 237:f3da66175598 40 (+) Declare a DMA handle structure for the Tx/Rx stream.
mbed_official 237:f3da66175598 41 (+) Enable the DMAx interface clock.
mbed_official 237:f3da66175598 42 (+) Configure the declared DMA handle structure with the required Tx/Rx parameters.
mbed_official 237:f3da66175598 43 (+) Configure the DMA Tx/Rx Stream.
mbed_official 237:f3da66175598 44 (+) Associate the initilalized DMA handle to the IRDA DMA Tx/Rx handle.
mbed_official 237:f3da66175598 45 (+) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
mbed_official 237:f3da66175598 46
mbed_official 237:f3da66175598 47 (#) Program the Baud Rate, Word Length and Parity and Mode(Receiver/Transmitter),
mbed_official 237:f3da66175598 48 the normal or low power mode and the clock prescaler in the hirda Init structure.
mbed_official 237:f3da66175598 49
mbed_official 237:f3da66175598 50 (#) Initialize the IRDA registers by calling
mbed_official 237:f3da66175598 51 the HAL_IRDA_Init() API.
mbed_official 237:f3da66175598 52
mbed_official 237:f3da66175598 53 (@) This API (HAL_IRDA_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc)
mbed_official 237:f3da66175598 54 by calling the customized HAL_IRDA_MspInit() API.
mbed_official 237:f3da66175598 55
mbed_official 237:f3da66175598 56 @endverbatim
mbed_official 237:f3da66175598 57 ******************************************************************************
mbed_official 237:f3da66175598 58 * @attention
mbed_official 237:f3da66175598 59 *
mbed_official 632:7687fb9c4f91 60 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 61 *
mbed_official 237:f3da66175598 62 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 63 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 64 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 65 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 66 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 67 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 68 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 69 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 70 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 71 * without specific prior written permission.
mbed_official 237:f3da66175598 72 *
mbed_official 237:f3da66175598 73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 76 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 77 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 78 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 79 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 80 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 81 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 82 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 83 *
mbed_official 237:f3da66175598 84 ******************************************************************************
mbed_official 237:f3da66175598 85 */
mbed_official 237:f3da66175598 86
mbed_official 237:f3da66175598 87 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 88 #include "stm32f3xx_hal.h"
mbed_official 237:f3da66175598 89
mbed_official 237:f3da66175598 90 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 91 * @{
mbed_official 237:f3da66175598 92 */
mbed_official 237:f3da66175598 93
mbed_official 375:3d36234a1087 94 /** @defgroup IRDA IRDA HAL module driver
mbed_official 237:f3da66175598 95 * @brief HAL IRDA module driver
mbed_official 237:f3da66175598 96 * @{
mbed_official 237:f3da66175598 97 */
mbed_official 237:f3da66175598 98 #ifdef HAL_IRDA_MODULE_ENABLED
mbed_official 237:f3da66175598 99
mbed_official 237:f3da66175598 100 /* Private typedef -----------------------------------------------------------*/
mbed_official 237:f3da66175598 101 /* Private define ------------------------------------------------------------*/
mbed_official 375:3d36234a1087 102 /** @defgroup IRDA_Private_Constants IRDA Private Constants
mbed_official 375:3d36234a1087 103 * @{
mbed_official 375:3d36234a1087 104 */
mbed_official 237:f3da66175598 105 #define TEACK_REACK_TIMEOUT 1000
mbed_official 237:f3da66175598 106 #define IRDA_TXDMA_TIMEOUTVALUE 22000
mbed_official 237:f3da66175598 107 #define IRDA_TIMEOUT_VALUE 22000
mbed_official 237:f3da66175598 108 #define IRDA_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE \
mbed_official 237:f3da66175598 109 | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE))
mbed_official 375:3d36234a1087 110 /**
mbed_official 375:3d36234a1087 111 * @}
mbed_official 375:3d36234a1087 112 */
mbed_official 375:3d36234a1087 113
mbed_official 237:f3da66175598 114 /* Private macro -------------------------------------------------------------*/
mbed_official 237:f3da66175598 115 /* Private variables ---------------------------------------------------------*/
mbed_official 237:f3da66175598 116 /* Private function prototypes -----------------------------------------------*/
mbed_official 375:3d36234a1087 117 /** @defgroup IRDA_Private_Functions IRDA Private Functions
mbed_official 375:3d36234a1087 118 * @{
mbed_official 375:3d36234a1087 119 */
mbed_official 237:f3da66175598 120 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
mbed_official 237:f3da66175598 121 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
mbed_official 237:f3da66175598 122 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
mbed_official 237:f3da66175598 123 static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda);
mbed_official 237:f3da66175598 124 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda);
mbed_official 237:f3da66175598 125 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
mbed_official 237:f3da66175598 126 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
mbed_official 375:3d36234a1087 127 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
mbed_official 237:f3da66175598 128 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
mbed_official 375:3d36234a1087 129 /**
mbed_official 375:3d36234a1087 130 * @}
mbed_official 375:3d36234a1087 131 */
mbed_official 375:3d36234a1087 132 /* Exported functions ---------------------------------------------------------*/
mbed_official 237:f3da66175598 133
mbed_official 375:3d36234a1087 134 /** @defgroup IRDA_Exported_Functions IRDA Exported Functions
mbed_official 237:f3da66175598 135 * @{
mbed_official 237:f3da66175598 136 */
mbed_official 237:f3da66175598 137
mbed_official 375:3d36234a1087 138 /** @defgroup IRDA_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 237:f3da66175598 139 * @brief Initialization and Configuration functions
mbed_official 237:f3da66175598 140 *
mbed_official 237:f3da66175598 141 @verbatim
mbed_official 375:3d36234a1087 142 ==============================================================================
mbed_official 237:f3da66175598 143 ##### Initialization and Configuration functions #####
mbed_official 375:3d36234a1087 144 ==============================================================================
mbed_official 237:f3da66175598 145 [..]
mbed_official 237:f3da66175598 146 This subsection provides a set of functions allowing to initialize the USARTx
mbed_official 237:f3da66175598 147 in asynchronous IRDA mode.
mbed_official 237:f3da66175598 148 (+) For the asynchronous mode only these parameters can be configured:
mbed_official 237:f3da66175598 149 (++) Baud Rate
mbed_official 237:f3da66175598 150 (++) Word Length
mbed_official 237:f3da66175598 151 (++) Parity: If the parity is enabled, then the MSB bit of the data written
mbed_official 237:f3da66175598 152 in the data register is transmitted but is changed by the parity bit.
mbed_official 237:f3da66175598 153 Depending on the frame length defined by the M bit (8-bits or 9-bits)
mbed_official 237:f3da66175598 154 or by the M1 and M0 bits (7-bit, 8-bit or 9-bit),
mbed_official 237:f3da66175598 155 the possible IRDA frame formats are as listed in the following table:
mbed_official 237:f3da66175598 156 +---------------------------------------------------------------+
mbed_official 237:f3da66175598 157 | M bit | PCE bit | IRDA frame |
mbed_official 237:f3da66175598 158 |-----------|-----------|---------------------------------------|
mbed_official 237:f3da66175598 159 | 0 | 0 | | SB | 8-bit data | STB | |
mbed_official 237:f3da66175598 160 |-----------|-----------|---------------------------------------|
mbed_official 237:f3da66175598 161 | 0 | 1 | | SB | 7-bit data | PB | STB | |
mbed_official 237:f3da66175598 162 |-----------|-----------|---------------------------------------|
mbed_official 237:f3da66175598 163 | 1 | 0 | | SB | 9-bit data | STB | |
mbed_official 237:f3da66175598 164 |-----------|-----------|---------------------------------------|
mbed_official 237:f3da66175598 165 | 1 | 1 | | SB | 8-bit data | PB | STB | |
mbed_official 237:f3da66175598 166 +---------------------------------------------------------------+
mbed_official 237:f3da66175598 167 | M1M0 bits | PCE bit | IRDA frame |
mbed_official 237:f3da66175598 168 |-----------------------|---------------------------------------|
mbed_official 237:f3da66175598 169 | 10 | 0 | | SB | 7-bit data | STB | |
mbed_official 237:f3da66175598 170 |-----------|-----------|---------------------------------------|
mbed_official 237:f3da66175598 171 | 10 | 1 | | SB | 6-bit data | PB | STB | |
mbed_official 237:f3da66175598 172 +---------------------------------------------------------------+
mbed_official 237:f3da66175598 173
mbed_official 237:f3da66175598 174 (++) Power mode
mbed_official 237:f3da66175598 175 (++) Prescaler setting
mbed_official 237:f3da66175598 176 (++) Receiver/transmitter modes
mbed_official 237:f3da66175598 177
mbed_official 237:f3da66175598 178 [..]
mbed_official 237:f3da66175598 179 The HAL_IRDA_Init() API follows the USART asynchronous configuration procedures
mbed_official 237:f3da66175598 180 (details for the procedures are available in reference manual).
mbed_official 237:f3da66175598 181
mbed_official 237:f3da66175598 182 @endverbatim
mbed_official 237:f3da66175598 183 * @{
mbed_official 237:f3da66175598 184 */
mbed_official 237:f3da66175598 185
mbed_official 237:f3da66175598 186 /**
mbed_official 237:f3da66175598 187 * @brief Initializes the IRDA mode according to the specified
mbed_official 237:f3da66175598 188 * parameters in the IRDA_InitTypeDef and creates the associated handle .
mbed_official 237:f3da66175598 189 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 190 * @retval HAL status
mbed_official 237:f3da66175598 191 */
mbed_official 237:f3da66175598 192 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 193 {
mbed_official 237:f3da66175598 194 /* Check the IRDA handle allocation */
mbed_official 632:7687fb9c4f91 195 if(hirda == NULL)
mbed_official 237:f3da66175598 196 {
mbed_official 237:f3da66175598 197 return HAL_ERROR;
mbed_official 237:f3da66175598 198 }
mbed_official 237:f3da66175598 199
mbed_official 237:f3da66175598 200 /* Check the USART/UART associated to the IRDA handle */
mbed_official 237:f3da66175598 201 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
mbed_official 237:f3da66175598 202
mbed_official 237:f3da66175598 203 if(hirda->State == HAL_IRDA_STATE_RESET)
mbed_official 237:f3da66175598 204 {
mbed_official 237:f3da66175598 205 /* Init the low level hardware : GPIO, CLOCK */
mbed_official 237:f3da66175598 206 HAL_IRDA_MspInit(hirda);
mbed_official 237:f3da66175598 207 }
mbed_official 237:f3da66175598 208
mbed_official 237:f3da66175598 209 hirda->State = HAL_IRDA_STATE_BUSY;
mbed_official 237:f3da66175598 210
mbed_official 237:f3da66175598 211 /* Disable the Peripheral to update the configuration registers */
mbed_official 237:f3da66175598 212 __HAL_IRDA_DISABLE(hirda);
mbed_official 237:f3da66175598 213
mbed_official 237:f3da66175598 214 /* Set the IRDA Communication parameters */
mbed_official 237:f3da66175598 215 if (IRDA_SetConfig(hirda) == HAL_ERROR)
mbed_official 237:f3da66175598 216 {
mbed_official 237:f3da66175598 217 return HAL_ERROR;
mbed_official 237:f3da66175598 218 }
mbed_official 237:f3da66175598 219
mbed_official 237:f3da66175598 220 /* In IRDA mode, the following bits must be kept cleared:
mbed_official 237:f3da66175598 221 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
mbed_official 237:f3da66175598 222 - SCEN and HDSEL bits in the USART_CR3 register.*/
mbed_official 237:f3da66175598 223 hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP);
mbed_official 237:f3da66175598 224 hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL);
mbed_official 237:f3da66175598 225
mbed_official 237:f3da66175598 226 /* set the UART/USART in IRDA mode */
mbed_official 237:f3da66175598 227 hirda->Instance->CR3 |= USART_CR3_IREN;
mbed_official 237:f3da66175598 228
mbed_official 237:f3da66175598 229 /* Enable the Peripheral */
mbed_official 237:f3da66175598 230 __HAL_IRDA_ENABLE(hirda);
mbed_official 237:f3da66175598 231
mbed_official 237:f3da66175598 232 /* TEACK and/or REACK to check before moving hirda->State to Ready */
mbed_official 237:f3da66175598 233 return (IRDA_CheckIdleState(hirda));
mbed_official 237:f3da66175598 234 }
mbed_official 237:f3da66175598 235
mbed_official 237:f3da66175598 236 /**
mbed_official 237:f3da66175598 237 * @brief DeInitializes the IRDA peripheral
mbed_official 237:f3da66175598 238 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 239 * @retval HAL status
mbed_official 237:f3da66175598 240 */
mbed_official 237:f3da66175598 241 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 242 {
mbed_official 237:f3da66175598 243 /* Check the IRDA handle allocation */
mbed_official 632:7687fb9c4f91 244 if(hirda == NULL)
mbed_official 237:f3da66175598 245 {
mbed_official 237:f3da66175598 246 return HAL_ERROR;
mbed_official 237:f3da66175598 247 }
mbed_official 237:f3da66175598 248
mbed_official 237:f3da66175598 249 /* Check the USART/UART associated to the IRDA handle */
mbed_official 237:f3da66175598 250 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
mbed_official 237:f3da66175598 251
mbed_official 237:f3da66175598 252 hirda->State = HAL_IRDA_STATE_BUSY;
mbed_official 237:f3da66175598 253
mbed_official 237:f3da66175598 254 /* DeInit the low level hardware */
mbed_official 237:f3da66175598 255 HAL_IRDA_MspDeInit(hirda);
mbed_official 237:f3da66175598 256 /* Disable the Peripheral */
mbed_official 237:f3da66175598 257 __HAL_IRDA_DISABLE(hirda);
mbed_official 237:f3da66175598 258
mbed_official 237:f3da66175598 259 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 260 hirda->State = HAL_IRDA_STATE_RESET;
mbed_official 237:f3da66175598 261
mbed_official 237:f3da66175598 262 /* Process Unlock */
mbed_official 237:f3da66175598 263 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 264
mbed_official 237:f3da66175598 265 return HAL_OK;
mbed_official 237:f3da66175598 266 }
mbed_official 237:f3da66175598 267
mbed_official 237:f3da66175598 268 /**
mbed_official 237:f3da66175598 269 * @brief IRDA MSP Init
mbed_official 237:f3da66175598 270 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 271 * @retval None
mbed_official 237:f3da66175598 272 */
mbed_official 237:f3da66175598 273 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 274 {
mbed_official 237:f3da66175598 275 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 276 the HAL_IRDA_MspInit can be implemented in the user file
mbed_official 237:f3da66175598 277 */
mbed_official 237:f3da66175598 278 }
mbed_official 237:f3da66175598 279
mbed_official 237:f3da66175598 280 /**
mbed_official 237:f3da66175598 281 * @brief IRDA MSP DeInit
mbed_official 237:f3da66175598 282 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 283 * @retval None
mbed_official 237:f3da66175598 284 */
mbed_official 237:f3da66175598 285 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 286 {
mbed_official 237:f3da66175598 287 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 288 the HAL_IRDA_MspDeInit can be implemented in the user file
mbed_official 237:f3da66175598 289 */
mbed_official 237:f3da66175598 290 }
mbed_official 237:f3da66175598 291
mbed_official 237:f3da66175598 292 /**
mbed_official 237:f3da66175598 293 * @}
mbed_official 237:f3da66175598 294 */
mbed_official 237:f3da66175598 295
mbed_official 375:3d36234a1087 296 /** @defgroup IRDA_Exported_Functions_Group2 Input and Output operation functions
mbed_official 375:3d36234a1087 297 * @brief IRDA Transmit and Receive functions
mbed_official 237:f3da66175598 298 *
mbed_official 237:f3da66175598 299 @verbatim
mbed_official 237:f3da66175598 300 ===============================================================================
mbed_official 237:f3da66175598 301 ##### I/O operation functions #####
mbed_official 237:f3da66175598 302 ===============================================================================
mbed_official 237:f3da66175598 303 This subsection provides a set of functions allowing to manage the IRDA asynchronous
mbed_official 237:f3da66175598 304 data transfers.
mbed_official 237:f3da66175598 305
mbed_official 237:f3da66175598 306 (#) There are two modes of transfer:
mbed_official 237:f3da66175598 307 (+) Blocking mode: the communication is performed in polling mode.
mbed_official 237:f3da66175598 308 The HAL status of all data processing is returned by the same function
mbed_official 237:f3da66175598 309 after finishing transfer.
mbed_official 237:f3da66175598 310 (+) No-Blocking mode: the communication is performed using Interrupts
mbed_official 237:f3da66175598 311 or DMA, these API's return the HAL status.
mbed_official 237:f3da66175598 312 The end of the data processing will be indicated through the
mbed_official 237:f3da66175598 313 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
mbed_official 237:f3da66175598 314 using DMA mode.
mbed_official 237:f3da66175598 315 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
mbed_official 237:f3da66175598 316 will be executed respectivelly at the end of the Transmit or Receive process
mbed_official 237:f3da66175598 317 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
mbed_official 237:f3da66175598 318
mbed_official 237:f3da66175598 319 (#) Blocking mode API's are :
mbed_official 237:f3da66175598 320 (+) HAL_IRDA_Transmit()
mbed_official 237:f3da66175598 321 (+) HAL_IRDA_Receive()
mbed_official 237:f3da66175598 322
mbed_official 237:f3da66175598 323 (#) Non-Blocking mode API's with Interrupt are :
mbed_official 237:f3da66175598 324 (+) HAL_IRDA_Transmit_IT()
mbed_official 237:f3da66175598 325 (+) HAL_IRDA_Receive_IT()
mbed_official 237:f3da66175598 326 (+) HAL_IRDA_IRQHandler()
mbed_official 237:f3da66175598 327 (+) IRDA_Transmit_IT()
mbed_official 237:f3da66175598 328 (+) IRDA_Receive_IT()
mbed_official 237:f3da66175598 329
mbed_official 237:f3da66175598 330 (#) Non-Blocking mode functions with DMA are :
mbed_official 237:f3da66175598 331 (+) HAL_IRDA_Transmit_DMA()
mbed_official 237:f3da66175598 332 (+) HAL_IRDA_Receive_DMA()
mbed_official 237:f3da66175598 333
mbed_official 237:f3da66175598 334 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
mbed_official 237:f3da66175598 335 (+) HAL_IRDA_TxCpltCallback()
mbed_official 237:f3da66175598 336 (+) HAL_IRDA_RxCpltCallback()
mbed_official 237:f3da66175598 337 (+) HAL_IRDA_ErrorCallback()
mbed_official 237:f3da66175598 338
mbed_official 237:f3da66175598 339 @endverbatim
mbed_official 237:f3da66175598 340 * @{
mbed_official 237:f3da66175598 341 */
mbed_official 237:f3da66175598 342
mbed_official 237:f3da66175598 343 /**
mbed_official 237:f3da66175598 344 * @brief Send an amount of data in blocking mode
mbed_official 237:f3da66175598 345 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 346 * @param pData: pointer to data buffer
mbed_official 237:f3da66175598 347 * @param Size: amount of data to be sent
mbed_official 237:f3da66175598 348 * @param Timeout: Duration of the timeout
mbed_official 237:f3da66175598 349 * @retval HAL status
mbed_official 237:f3da66175598 350 */
mbed_official 237:f3da66175598 351 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
mbed_official 237:f3da66175598 352 {
mbed_official 237:f3da66175598 353 uint16_t* tmp;
mbed_official 237:f3da66175598 354
mbed_official 237:f3da66175598 355 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
mbed_official 237:f3da66175598 356 {
mbed_official 632:7687fb9c4f91 357 if((pData == NULL) || (Size == 0))
mbed_official 237:f3da66175598 358 {
mbed_official 237:f3da66175598 359 return HAL_ERROR;
mbed_official 237:f3da66175598 360 }
mbed_official 237:f3da66175598 361
mbed_official 237:f3da66175598 362 /* Process Locked */
mbed_official 237:f3da66175598 363 __HAL_LOCK(hirda);
mbed_official 237:f3da66175598 364 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 365
mbed_official 237:f3da66175598 366 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 237:f3da66175598 367 {
mbed_official 237:f3da66175598 368 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 237:f3da66175598 369 }
mbed_official 237:f3da66175598 370 else
mbed_official 237:f3da66175598 371 {
mbed_official 237:f3da66175598 372 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 237:f3da66175598 373 }
mbed_official 237:f3da66175598 374
mbed_official 237:f3da66175598 375 hirda->TxXferSize = Size;
mbed_official 237:f3da66175598 376 hirda->TxXferCount = Size;
mbed_official 237:f3da66175598 377 while(hirda->TxXferCount > 0)
mbed_official 237:f3da66175598 378 {
mbed_official 237:f3da66175598 379 hirda->TxXferCount--;
mbed_official 237:f3da66175598 380
mbed_official 237:f3da66175598 381 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
mbed_official 237:f3da66175598 382 {
mbed_official 237:f3da66175598 383 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 384 }
mbed_official 237:f3da66175598 385 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 237:f3da66175598 386 {
mbed_official 237:f3da66175598 387 tmp = (uint16_t*) pData;
mbed_official 237:f3da66175598 388 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
mbed_official 237:f3da66175598 389 pData +=2;
mbed_official 237:f3da66175598 390 }
mbed_official 237:f3da66175598 391 else
mbed_official 237:f3da66175598 392 {
mbed_official 237:f3da66175598 393 hirda->Instance->TDR = (*pData++ & (uint8_t)0xFF);
mbed_official 237:f3da66175598 394 }
mbed_official 237:f3da66175598 395 }
mbed_official 237:f3da66175598 396
mbed_official 237:f3da66175598 397 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK)
mbed_official 237:f3da66175598 398 {
mbed_official 237:f3da66175598 399 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 400 }
mbed_official 237:f3da66175598 401
mbed_official 237:f3da66175598 402 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 237:f3da66175598 403 {
mbed_official 237:f3da66175598 404 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 237:f3da66175598 405 }
mbed_official 237:f3da66175598 406 else
mbed_official 237:f3da66175598 407 {
mbed_official 237:f3da66175598 408 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 409 }
mbed_official 237:f3da66175598 410
mbed_official 237:f3da66175598 411 /* Process Unlocked */
mbed_official 237:f3da66175598 412 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 413
mbed_official 237:f3da66175598 414 return HAL_OK;
mbed_official 237:f3da66175598 415 }
mbed_official 237:f3da66175598 416 else
mbed_official 237:f3da66175598 417 {
mbed_official 237:f3da66175598 418 return HAL_BUSY;
mbed_official 237:f3da66175598 419 }
mbed_official 237:f3da66175598 420 }
mbed_official 237:f3da66175598 421
mbed_official 237:f3da66175598 422 /**
mbed_official 237:f3da66175598 423 * @brief Receive an amount of data in blocking mode
mbed_official 237:f3da66175598 424 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 425 * @param pData: pointer to data buffer
mbed_official 237:f3da66175598 426 * @param Size: amount of data to be received
mbed_official 237:f3da66175598 427 * @param Timeout: Duration of the timeout
mbed_official 237:f3da66175598 428 * @retval HAL status
mbed_official 237:f3da66175598 429 */
mbed_official 237:f3da66175598 430 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
mbed_official 237:f3da66175598 431 {
mbed_official 237:f3da66175598 432 uint16_t* tmp;
mbed_official 237:f3da66175598 433 uint16_t uhMask;
mbed_official 237:f3da66175598 434
mbed_official 237:f3da66175598 435 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
mbed_official 237:f3da66175598 436 {
mbed_official 632:7687fb9c4f91 437 if((pData == NULL) || (Size == 0))
mbed_official 237:f3da66175598 438 {
mbed_official 237:f3da66175598 439 return HAL_ERROR;
mbed_official 237:f3da66175598 440 }
mbed_official 237:f3da66175598 441
mbed_official 237:f3da66175598 442 /* Process Locked */
mbed_official 237:f3da66175598 443 __HAL_LOCK(hirda);
mbed_official 237:f3da66175598 444 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 445
mbed_official 237:f3da66175598 446 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 237:f3da66175598 447 {
mbed_official 237:f3da66175598 448 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 237:f3da66175598 449 }
mbed_official 237:f3da66175598 450 else
mbed_official 237:f3da66175598 451 {
mbed_official 237:f3da66175598 452 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 237:f3da66175598 453 }
mbed_official 237:f3da66175598 454
mbed_official 237:f3da66175598 455 hirda->RxXferSize = Size;
mbed_official 237:f3da66175598 456 hirda->RxXferCount = Size;
mbed_official 237:f3da66175598 457
mbed_official 237:f3da66175598 458 /* Computation of the mask to apply to the RDR register
mbed_official 237:f3da66175598 459 of the UART associated to the IRDA */
mbed_official 237:f3da66175598 460 __HAL_IRDA_MASK_COMPUTATION(hirda);
mbed_official 237:f3da66175598 461 uhMask = hirda->Mask;
mbed_official 237:f3da66175598 462
mbed_official 237:f3da66175598 463 /* Check data remaining to be received */
mbed_official 237:f3da66175598 464 while(hirda->RxXferCount > 0)
mbed_official 237:f3da66175598 465 {
mbed_official 237:f3da66175598 466 hirda->RxXferCount--;
mbed_official 237:f3da66175598 467
mbed_official 237:f3da66175598 468 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
mbed_official 237:f3da66175598 469 {
mbed_official 237:f3da66175598 470 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 471 }
mbed_official 237:f3da66175598 472 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 237:f3da66175598 473 {
mbed_official 237:f3da66175598 474 tmp = (uint16_t*) pData ;
mbed_official 237:f3da66175598 475 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
mbed_official 237:f3da66175598 476 pData +=2;
mbed_official 237:f3da66175598 477 }
mbed_official 237:f3da66175598 478 else
mbed_official 237:f3da66175598 479 {
mbed_official 237:f3da66175598 480 *pData++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
mbed_official 237:f3da66175598 481 }
mbed_official 237:f3da66175598 482 }
mbed_official 237:f3da66175598 483
mbed_official 237:f3da66175598 484 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 237:f3da66175598 485 {
mbed_official 237:f3da66175598 486 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 237:f3da66175598 487 }
mbed_official 237:f3da66175598 488 else
mbed_official 237:f3da66175598 489 {
mbed_official 237:f3da66175598 490 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 491 }
mbed_official 237:f3da66175598 492
mbed_official 237:f3da66175598 493 /* Process Unlocked */
mbed_official 237:f3da66175598 494 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 495
mbed_official 237:f3da66175598 496 return HAL_OK;
mbed_official 237:f3da66175598 497 }
mbed_official 237:f3da66175598 498 else
mbed_official 237:f3da66175598 499 {
mbed_official 237:f3da66175598 500 return HAL_BUSY;
mbed_official 237:f3da66175598 501 }
mbed_official 237:f3da66175598 502 }
mbed_official 237:f3da66175598 503
mbed_official 237:f3da66175598 504 /**
mbed_official 237:f3da66175598 505 * @brief Send an amount of data in interrupt mode
mbed_official 237:f3da66175598 506 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 507 * @param pData: pointer to data buffer
mbed_official 237:f3da66175598 508 * @param Size: amount of data to be sent
mbed_official 237:f3da66175598 509 * @retval HAL status
mbed_official 237:f3da66175598 510 */
mbed_official 237:f3da66175598 511 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 237:f3da66175598 512 {
mbed_official 237:f3da66175598 513 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
mbed_official 237:f3da66175598 514 {
mbed_official 632:7687fb9c4f91 515 if((pData == NULL) || (Size == 0))
mbed_official 237:f3da66175598 516 {
mbed_official 237:f3da66175598 517 return HAL_ERROR;
mbed_official 237:f3da66175598 518 }
mbed_official 237:f3da66175598 519
mbed_official 237:f3da66175598 520 /* Process Locked */
mbed_official 237:f3da66175598 521 __HAL_LOCK(hirda);
mbed_official 237:f3da66175598 522
mbed_official 237:f3da66175598 523 hirda->pTxBuffPtr = pData;
mbed_official 237:f3da66175598 524 hirda->TxXferSize = Size;
mbed_official 237:f3da66175598 525 hirda->TxXferCount = Size;
mbed_official 237:f3da66175598 526
mbed_official 237:f3da66175598 527 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 528 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 237:f3da66175598 529 {
mbed_official 237:f3da66175598 530 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 237:f3da66175598 531 }
mbed_official 237:f3da66175598 532 else
mbed_official 237:f3da66175598 533 {
mbed_official 237:f3da66175598 534 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 237:f3da66175598 535 }
mbed_official 237:f3da66175598 536
mbed_official 237:f3da66175598 537 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 237:f3da66175598 538 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 237:f3da66175598 539
mbed_official 237:f3da66175598 540 /* Process Unlocked */
mbed_official 237:f3da66175598 541 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 542
mbed_official 237:f3da66175598 543 /* Enable the IRDA Transmit Data Register Empty Interrupt */
mbed_official 237:f3da66175598 544 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 237:f3da66175598 545
mbed_official 237:f3da66175598 546 return HAL_OK;
mbed_official 237:f3da66175598 547 }
mbed_official 237:f3da66175598 548 else
mbed_official 237:f3da66175598 549 {
mbed_official 237:f3da66175598 550 return HAL_BUSY;
mbed_official 237:f3da66175598 551 }
mbed_official 237:f3da66175598 552 }
mbed_official 237:f3da66175598 553
mbed_official 237:f3da66175598 554 /**
mbed_official 237:f3da66175598 555 * @brief Receive an amount of data in interrupt mode
mbed_official 237:f3da66175598 556 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 557 * @param pData: pointer to data buffer
mbed_official 237:f3da66175598 558 * @param Size: amount of data to be received
mbed_official 237:f3da66175598 559 * @retval HAL status
mbed_official 237:f3da66175598 560 */
mbed_official 237:f3da66175598 561 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 237:f3da66175598 562 {
mbed_official 237:f3da66175598 563 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
mbed_official 237:f3da66175598 564 {
mbed_official 632:7687fb9c4f91 565 if((pData == NULL) || (Size == 0))
mbed_official 237:f3da66175598 566 {
mbed_official 237:f3da66175598 567 return HAL_ERROR;
mbed_official 237:f3da66175598 568 }
mbed_official 237:f3da66175598 569
mbed_official 237:f3da66175598 570 /* Process Locked */
mbed_official 237:f3da66175598 571 __HAL_LOCK(hirda);
mbed_official 237:f3da66175598 572
mbed_official 237:f3da66175598 573 hirda->pRxBuffPtr = pData;
mbed_official 237:f3da66175598 574 hirda->RxXferSize = Size;
mbed_official 237:f3da66175598 575 hirda->RxXferCount = Size;
mbed_official 237:f3da66175598 576
mbed_official 237:f3da66175598 577 /* Computation of the mask to apply to the RDR register
mbed_official 237:f3da66175598 578 of the UART associated to the IRDA */
mbed_official 237:f3da66175598 579 __HAL_IRDA_MASK_COMPUTATION(hirda);
mbed_official 237:f3da66175598 580
mbed_official 237:f3da66175598 581 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 582 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 237:f3da66175598 583 {
mbed_official 237:f3da66175598 584 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 237:f3da66175598 585 }
mbed_official 237:f3da66175598 586 else
mbed_official 237:f3da66175598 587 {
mbed_official 237:f3da66175598 588 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 237:f3da66175598 589 }
mbed_official 237:f3da66175598 590
mbed_official 237:f3da66175598 591 /* Enable the IRDA Parity Error Interrupt */
mbed_official 237:f3da66175598 592 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
mbed_official 237:f3da66175598 593
mbed_official 237:f3da66175598 594 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 237:f3da66175598 595 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 237:f3da66175598 596
mbed_official 237:f3da66175598 597 /* Process Unlocked */
mbed_official 237:f3da66175598 598 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 599
mbed_official 237:f3da66175598 600 /* Enable the IRDA Data Register not empty Interrupt */
mbed_official 237:f3da66175598 601 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 237:f3da66175598 602
mbed_official 237:f3da66175598 603 return HAL_OK;
mbed_official 237:f3da66175598 604 }
mbed_official 237:f3da66175598 605 else
mbed_official 237:f3da66175598 606 {
mbed_official 237:f3da66175598 607 return HAL_BUSY;
mbed_official 237:f3da66175598 608 }
mbed_official 237:f3da66175598 609 }
mbed_official 237:f3da66175598 610
mbed_official 237:f3da66175598 611 /**
mbed_official 237:f3da66175598 612 * @brief Send an amount of data in DMA mode
mbed_official 237:f3da66175598 613 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 614 * @param pData: pointer to data buffer
mbed_official 237:f3da66175598 615 * @param Size: amount of data to be sent
mbed_official 237:f3da66175598 616 * @retval HAL status
mbed_official 237:f3da66175598 617 */
mbed_official 237:f3da66175598 618 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 237:f3da66175598 619 {
mbed_official 237:f3da66175598 620 uint32_t *tmp;
mbed_official 237:f3da66175598 621
mbed_official 237:f3da66175598 622 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
mbed_official 237:f3da66175598 623 {
mbed_official 632:7687fb9c4f91 624 if((pData == NULL) || (Size == 0))
mbed_official 237:f3da66175598 625 {
mbed_official 237:f3da66175598 626 return HAL_ERROR;
mbed_official 237:f3da66175598 627 }
mbed_official 237:f3da66175598 628
mbed_official 237:f3da66175598 629 /* Process Locked */
mbed_official 237:f3da66175598 630 __HAL_LOCK(hirda);
mbed_official 237:f3da66175598 631
mbed_official 237:f3da66175598 632 hirda->pTxBuffPtr = pData;
mbed_official 237:f3da66175598 633 hirda->TxXferSize = Size;
mbed_official 237:f3da66175598 634 hirda->TxXferCount = Size;
mbed_official 237:f3da66175598 635
mbed_official 237:f3da66175598 636 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 637
mbed_official 237:f3da66175598 638 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 237:f3da66175598 639 {
mbed_official 237:f3da66175598 640 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 237:f3da66175598 641 }
mbed_official 237:f3da66175598 642 else
mbed_official 237:f3da66175598 643 {
mbed_official 237:f3da66175598 644 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 237:f3da66175598 645 }
mbed_official 237:f3da66175598 646
mbed_official 237:f3da66175598 647 /* Set the IRDA DMA transfer complete callback */
mbed_official 237:f3da66175598 648 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
mbed_official 237:f3da66175598 649
mbed_official 237:f3da66175598 650 /* Set the DMA error callback */
mbed_official 237:f3da66175598 651 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
mbed_official 237:f3da66175598 652
mbed_official 237:f3da66175598 653 /* Enable the IRDA transmit DMA channel */
mbed_official 237:f3da66175598 654 tmp = (uint32_t*)&pData;
mbed_official 237:f3da66175598 655 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->TDR, Size);
mbed_official 237:f3da66175598 656
mbed_official 237:f3da66175598 657 /* Enable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 237:f3da66175598 658 in the IRDA CR3 register */
mbed_official 237:f3da66175598 659 hirda->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 237:f3da66175598 660
mbed_official 237:f3da66175598 661 /* Process Unlocked */
mbed_official 237:f3da66175598 662 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 663
mbed_official 237:f3da66175598 664 return HAL_OK;
mbed_official 237:f3da66175598 665 }
mbed_official 237:f3da66175598 666 else
mbed_official 237:f3da66175598 667 {
mbed_official 237:f3da66175598 668 return HAL_BUSY;
mbed_official 237:f3da66175598 669 }
mbed_official 237:f3da66175598 670 }
mbed_official 237:f3da66175598 671
mbed_official 237:f3da66175598 672 /**
mbed_official 237:f3da66175598 673 * @brief Receive an amount of data in DMA mode
mbed_official 237:f3da66175598 674 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 675 * @param pData: pointer to data buffer
mbed_official 237:f3da66175598 676 * @param Size: amount of data to be received
mbed_official 237:f3da66175598 677 * @note When the IRDA parity is enabled (PCE = 1), the received data contain
mbed_official 237:f3da66175598 678 * the parity bit (MSB position)
mbed_official 237:f3da66175598 679 * @retval HAL status
mbed_official 237:f3da66175598 680 */
mbed_official 237:f3da66175598 681 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 237:f3da66175598 682 {
mbed_official 237:f3da66175598 683 uint32_t *tmp;
mbed_official 237:f3da66175598 684
mbed_official 237:f3da66175598 685 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
mbed_official 237:f3da66175598 686 {
mbed_official 632:7687fb9c4f91 687 if((pData == NULL) || (Size == 0))
mbed_official 237:f3da66175598 688 {
mbed_official 237:f3da66175598 689 return HAL_ERROR;
mbed_official 237:f3da66175598 690 }
mbed_official 237:f3da66175598 691
mbed_official 237:f3da66175598 692 /* Process Locked */
mbed_official 237:f3da66175598 693 __HAL_LOCK(hirda);
mbed_official 237:f3da66175598 694
mbed_official 237:f3da66175598 695 hirda->pRxBuffPtr = pData;
mbed_official 237:f3da66175598 696 hirda->RxXferSize = Size;
mbed_official 237:f3da66175598 697
mbed_official 237:f3da66175598 698 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 699 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 237:f3da66175598 700 {
mbed_official 237:f3da66175598 701 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 237:f3da66175598 702 }
mbed_official 237:f3da66175598 703 else
mbed_official 237:f3da66175598 704 {
mbed_official 237:f3da66175598 705 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 237:f3da66175598 706 }
mbed_official 237:f3da66175598 707
mbed_official 237:f3da66175598 708 /* Set the IRDA DMA transfer complete callback */
mbed_official 237:f3da66175598 709 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
mbed_official 237:f3da66175598 710
mbed_official 237:f3da66175598 711 /* Set the DMA error callback */
mbed_official 237:f3da66175598 712 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
mbed_official 237:f3da66175598 713
mbed_official 237:f3da66175598 714 /* Enable the DMA channel */
mbed_official 237:f3da66175598 715 tmp = (uint32_t*)&pData;
mbed_official 237:f3da66175598 716 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->RDR, *(uint32_t*)tmp, Size);
mbed_official 237:f3da66175598 717
mbed_official 237:f3da66175598 718 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
mbed_official 237:f3da66175598 719 in the IRDA CR3 register */
mbed_official 237:f3da66175598 720 hirda->Instance->CR3 |= USART_CR3_DMAR;
mbed_official 237:f3da66175598 721
mbed_official 237:f3da66175598 722 /* Process Unlocked */
mbed_official 237:f3da66175598 723 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 724
mbed_official 237:f3da66175598 725 return HAL_OK;
mbed_official 237:f3da66175598 726 }
mbed_official 237:f3da66175598 727 else
mbed_official 237:f3da66175598 728 {
mbed_official 237:f3da66175598 729 return HAL_BUSY;
mbed_official 237:f3da66175598 730 }
mbed_official 237:f3da66175598 731 }
mbed_official 237:f3da66175598 732
mbed_official 237:f3da66175598 733 /**
mbed_official 237:f3da66175598 734 * @brief This function handles IRDA interrupt request.
mbed_official 237:f3da66175598 735 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 736 * @retval None
mbed_official 237:f3da66175598 737 */
mbed_official 237:f3da66175598 738 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 739 {
mbed_official 237:f3da66175598 740 /* IRDA parity error interrupt occurred -------------------------------------*/
mbed_official 237:f3da66175598 741 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_PE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE) != RESET))
mbed_official 237:f3da66175598 742 {
mbed_official 237:f3da66175598 743 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_PEF);
mbed_official 237:f3da66175598 744
mbed_official 237:f3da66175598 745 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
mbed_official 237:f3da66175598 746 /* Set the IRDA state ready to be able to start again the process */
mbed_official 237:f3da66175598 747 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 748 }
mbed_official 237:f3da66175598 749
mbed_official 237:f3da66175598 750 /* IRDA frame error interrupt occured --------------------------------------*/
mbed_official 237:f3da66175598 751 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_FE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
mbed_official 237:f3da66175598 752 {
mbed_official 237:f3da66175598 753 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_FEF);
mbed_official 237:f3da66175598 754
mbed_official 237:f3da66175598 755 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
mbed_official 237:f3da66175598 756 /* Set the IRDA state ready to be able to start again the process */
mbed_official 237:f3da66175598 757 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 758 }
mbed_official 237:f3da66175598 759
mbed_official 237:f3da66175598 760 /* IRDA noise error interrupt occured --------------------------------------*/
mbed_official 237:f3da66175598 761 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_NE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
mbed_official 237:f3da66175598 762 {
mbed_official 237:f3da66175598 763 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_NEF);
mbed_official 237:f3da66175598 764
mbed_official 237:f3da66175598 765 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
mbed_official 237:f3da66175598 766 /* Set the IRDA state ready to be able to start again the process */
mbed_official 237:f3da66175598 767 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 768 }
mbed_official 237:f3da66175598 769
mbed_official 237:f3da66175598 770 /* IRDA Over-Run interrupt occured -----------------------------------------*/
mbed_official 237:f3da66175598 771 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_ORE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
mbed_official 237:f3da66175598 772 {
mbed_official 237:f3da66175598 773 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
mbed_official 237:f3da66175598 774
mbed_official 237:f3da66175598 775 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
mbed_official 237:f3da66175598 776 /* Set the IRDA state ready to be able to start again the process */
mbed_official 237:f3da66175598 777 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 778 }
mbed_official 237:f3da66175598 779
mbed_official 237:f3da66175598 780 /* Call IRDA Error Call back function if need be --------------------------*/
mbed_official 237:f3da66175598 781 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
mbed_official 237:f3da66175598 782 {
mbed_official 237:f3da66175598 783 HAL_IRDA_ErrorCallback(hirda);
mbed_official 237:f3da66175598 784 }
mbed_official 237:f3da66175598 785
mbed_official 237:f3da66175598 786 /* IRDA in mode Receiver ---------------------------------------------------*/
mbed_official 237:f3da66175598 787 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_RXNE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE) != RESET))
mbed_official 237:f3da66175598 788 {
mbed_official 237:f3da66175598 789 IRDA_Receive_IT(hirda);
mbed_official 237:f3da66175598 790 /* Clear RXNE interrupt flag */
mbed_official 237:f3da66175598 791 __HAL_IRDA_SEND_REQ(hirda, IRDA_RXDATA_FLUSH_REQUEST);
mbed_official 237:f3da66175598 792 }
mbed_official 237:f3da66175598 793
mbed_official 237:f3da66175598 794
mbed_official 237:f3da66175598 795 /* IRDA in mode Transmitter ------------------------------------------------*/
mbed_official 237:f3da66175598 796 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TXE) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE) != RESET))
mbed_official 237:f3da66175598 797 {
mbed_official 237:f3da66175598 798 IRDA_Transmit_IT(hirda);
mbed_official 237:f3da66175598 799 }
mbed_official 237:f3da66175598 800
mbed_official 375:3d36234a1087 801 /* IRDA in mode Transmitter (transmission end) -----------------------------*/
mbed_official 375:3d36234a1087 802 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TC) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TC) != RESET))
mbed_official 375:3d36234a1087 803 {
mbed_official 375:3d36234a1087 804 IRDA_EndTransmit_IT(hirda);
mbed_official 375:3d36234a1087 805 }
mbed_official 375:3d36234a1087 806
mbed_official 237:f3da66175598 807 }
mbed_official 375:3d36234a1087 808 /**
mbed_official 375:3d36234a1087 809 * @}
mbed_official 375:3d36234a1087 810 */
mbed_official 375:3d36234a1087 811
mbed_official 375:3d36234a1087 812 /**
mbed_official 375:3d36234a1087 813 * @}
mbed_official 375:3d36234a1087 814 */
mbed_official 375:3d36234a1087 815
mbed_official 375:3d36234a1087 816 /** @addtogroup IRDA_Private_Functions IRDA Private Functions
mbed_official 375:3d36234a1087 817 * @{
mbed_official 375:3d36234a1087 818 */
mbed_official 237:f3da66175598 819
mbed_official 237:f3da66175598 820 /**
mbed_official 237:f3da66175598 821 * @brief DMA IRDA Tx transfer completed callback
mbed_official 237:f3da66175598 822 * @param hdma: DMA handle
mbed_official 237:f3da66175598 823 * @retval None
mbed_official 237:f3da66175598 824 */
mbed_official 237:f3da66175598 825 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
mbed_official 237:f3da66175598 826 {
mbed_official 237:f3da66175598 827 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 237:f3da66175598 828 hirda->TxXferCount = 0;
mbed_official 237:f3da66175598 829
mbed_official 237:f3da66175598 830 /* Disable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 237:f3da66175598 831 in the IRDA CR3 register */
mbed_official 237:f3da66175598 832 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT);
mbed_official 237:f3da66175598 833
mbed_official 237:f3da66175598 834 /* Wait for IRDA TC Flag */
mbed_official 237:f3da66175598 835 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, IRDA_TXDMA_TIMEOUTVALUE) != HAL_OK)
mbed_official 237:f3da66175598 836 {
mbed_official 237:f3da66175598 837 /* Timeout Occured */
mbed_official 237:f3da66175598 838 HAL_IRDA_ErrorCallback(hirda);
mbed_official 237:f3da66175598 839 }
mbed_official 237:f3da66175598 840 else
mbed_official 237:f3da66175598 841 {
mbed_official 237:f3da66175598 842 /* No Timeout */
mbed_official 237:f3da66175598 843 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 237:f3da66175598 844 {
mbed_official 237:f3da66175598 845 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 237:f3da66175598 846 }
mbed_official 237:f3da66175598 847 else
mbed_official 237:f3da66175598 848 {
mbed_official 237:f3da66175598 849 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 850 }
mbed_official 237:f3da66175598 851 HAL_IRDA_TxCpltCallback(hirda);
mbed_official 237:f3da66175598 852 }
mbed_official 237:f3da66175598 853 }
mbed_official 237:f3da66175598 854
mbed_official 237:f3da66175598 855 /**
mbed_official 237:f3da66175598 856 * @brief DMA IRDA Rx Transfer completed callback
mbed_official 237:f3da66175598 857 * @param hdma: DMA handle
mbed_official 237:f3da66175598 858 * @retval None
mbed_official 237:f3da66175598 859 */
mbed_official 237:f3da66175598 860 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
mbed_official 237:f3da66175598 861 {
mbed_official 237:f3da66175598 862 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 237:f3da66175598 863 hirda->RxXferCount = 0;
mbed_official 237:f3da66175598 864
mbed_official 237:f3da66175598 865 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
mbed_official 237:f3da66175598 866 in the IRDA CR3 register */
mbed_official 237:f3da66175598 867 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR);
mbed_official 237:f3da66175598 868
mbed_official 237:f3da66175598 869 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 237:f3da66175598 870 {
mbed_official 237:f3da66175598 871 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 237:f3da66175598 872 }
mbed_official 237:f3da66175598 873 else
mbed_official 237:f3da66175598 874 {
mbed_official 237:f3da66175598 875 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 876 }
mbed_official 237:f3da66175598 877
mbed_official 237:f3da66175598 878 HAL_IRDA_RxCpltCallback(hirda);
mbed_official 237:f3da66175598 879 }
mbed_official 237:f3da66175598 880
mbed_official 237:f3da66175598 881 /**
mbed_official 237:f3da66175598 882 * @brief DMA IRDA communication error callback
mbed_official 237:f3da66175598 883 * @param hdma: DMA handle
mbed_official 237:f3da66175598 884 * @retval None
mbed_official 237:f3da66175598 885 */
mbed_official 237:f3da66175598 886 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
mbed_official 237:f3da66175598 887 {
mbed_official 237:f3da66175598 888 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 237:f3da66175598 889 hirda->RxXferCount = 0;
mbed_official 237:f3da66175598 890 hirda->TxXferCount = 0;
mbed_official 237:f3da66175598 891 hirda->State= HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 892 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
mbed_official 237:f3da66175598 893 HAL_IRDA_ErrorCallback(hirda);
mbed_official 237:f3da66175598 894 }
mbed_official 375:3d36234a1087 895 /**
mbed_official 375:3d36234a1087 896 * @}
mbed_official 375:3d36234a1087 897 */
mbed_official 375:3d36234a1087 898
mbed_official 375:3d36234a1087 899 /** @addtogroup IRDA_Exported_Functions IRDA Exported Functions
mbed_official 375:3d36234a1087 900 * @{
mbed_official 375:3d36234a1087 901 */
mbed_official 375:3d36234a1087 902
mbed_official 375:3d36234a1087 903 /** @addtogroup IRDA_Exported_Functions_Group2 Input and Output operation functions
mbed_official 375:3d36234a1087 904 * @{
mbed_official 375:3d36234a1087 905 */
mbed_official 237:f3da66175598 906
mbed_official 237:f3da66175598 907 /**
mbed_official 237:f3da66175598 908 * @brief Tx Transfer completed callback
mbed_official 237:f3da66175598 909 * @param hirda: irda handle
mbed_official 237:f3da66175598 910 * @retval None
mbed_official 237:f3da66175598 911 */
mbed_official 237:f3da66175598 912 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 913 {
mbed_official 237:f3da66175598 914 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 915 the HAL_IRDA_TxCpltCallback can be implemented in the user file
mbed_official 237:f3da66175598 916 */
mbed_official 237:f3da66175598 917 }
mbed_official 237:f3da66175598 918
mbed_official 237:f3da66175598 919 /**
mbed_official 237:f3da66175598 920 * @brief Rx Transfer completed callback
mbed_official 237:f3da66175598 921 * @param hirda: irda handle
mbed_official 237:f3da66175598 922 * @retval None
mbed_official 237:f3da66175598 923 */
mbed_official 237:f3da66175598 924 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 925 {
mbed_official 237:f3da66175598 926 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 927 the HAL_IRDA_TxCpltCallback can be implemented in the user file
mbed_official 237:f3da66175598 928 */
mbed_official 237:f3da66175598 929 }
mbed_official 237:f3da66175598 930
mbed_official 237:f3da66175598 931 /**
mbed_official 237:f3da66175598 932 * @brief IRDA error callback
mbed_official 237:f3da66175598 933 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 934 * @retval None
mbed_official 237:f3da66175598 935 */
mbed_official 237:f3da66175598 936 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 937 {
mbed_official 237:f3da66175598 938 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 939 the HAL_IRDA_ErrorCallback can be implemented in the user file
mbed_official 237:f3da66175598 940 */
mbed_official 237:f3da66175598 941 }
mbed_official 237:f3da66175598 942
mbed_official 237:f3da66175598 943 /**
mbed_official 375:3d36234a1087 944 * @}
mbed_official 375:3d36234a1087 945 */
mbed_official 375:3d36234a1087 946
mbed_official 375:3d36234a1087 947 /**
mbed_official 375:3d36234a1087 948 * @}
mbed_official 375:3d36234a1087 949 */
mbed_official 375:3d36234a1087 950
mbed_official 375:3d36234a1087 951 /** @addtogroup IRDA_Private_Functions IRDA Private Functions
mbed_official 375:3d36234a1087 952 * @{
mbed_official 375:3d36234a1087 953 */
mbed_official 375:3d36234a1087 954
mbed_official 375:3d36234a1087 955 /**
mbed_official 237:f3da66175598 956 * @brief Receive an amount of data in non blocking mode.
mbed_official 237:f3da66175598 957 * Function called under interruption only, once
mbed_official 237:f3da66175598 958 * interruptions have been enabled by HAL_IRDA_Transmit_IT()
mbed_official 237:f3da66175598 959 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 960 * @retval HAL status
mbed_official 237:f3da66175598 961 */
mbed_official 237:f3da66175598 962 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 963 {
mbed_official 237:f3da66175598 964 uint16_t* tmp;
mbed_official 237:f3da66175598 965
mbed_official 237:f3da66175598 966 if((hirda->State == HAL_IRDA_STATE_BUSY_TX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
mbed_official 237:f3da66175598 967 {
mbed_official 237:f3da66175598 968
mbed_official 237:f3da66175598 969 if(hirda->TxXferCount == 0)
mbed_official 237:f3da66175598 970 {
mbed_official 237:f3da66175598 971 /* Disable the IRDA Transmit Data Register Empty Interrupt */
mbed_official 237:f3da66175598 972 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 237:f3da66175598 973
mbed_official 375:3d36234a1087 974 /* Enable the IRDA Transmit Complete Interrupt */
mbed_official 375:3d36234a1087 975 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
mbed_official 237:f3da66175598 976
mbed_official 237:f3da66175598 977 return HAL_OK;
mbed_official 237:f3da66175598 978 }
mbed_official 237:f3da66175598 979 else
mbed_official 237:f3da66175598 980 {
mbed_official 237:f3da66175598 981 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 375:3d36234a1087 982 {
mbed_official 375:3d36234a1087 983 tmp = (uint16_t*) hirda->pTxBuffPtr;
mbed_official 375:3d36234a1087 984 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
mbed_official 375:3d36234a1087 985 hirda->pTxBuffPtr += 2;
mbed_official 375:3d36234a1087 986 }
mbed_official 375:3d36234a1087 987 else
mbed_official 375:3d36234a1087 988 {
mbed_official 375:3d36234a1087 989 hirda->Instance->TDR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0xFF);
mbed_official 375:3d36234a1087 990 }
mbed_official 237:f3da66175598 991 hirda->TxXferCount--;
mbed_official 237:f3da66175598 992
mbed_official 237:f3da66175598 993 return HAL_OK;
mbed_official 237:f3da66175598 994 }
mbed_official 237:f3da66175598 995 }
mbed_official 237:f3da66175598 996 else
mbed_official 237:f3da66175598 997 {
mbed_official 237:f3da66175598 998 return HAL_BUSY;
mbed_official 237:f3da66175598 999 }
mbed_official 237:f3da66175598 1000 }
mbed_official 237:f3da66175598 1001
mbed_official 237:f3da66175598 1002 /**
mbed_official 375:3d36234a1087 1003 * @brief Wraps up transmission in non blocking mode.
mbed_official 375:3d36234a1087 1004 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 375:3d36234a1087 1005 * the configuration information for the specified IRDA module.
mbed_official 375:3d36234a1087 1006 * @retval HAL status
mbed_official 375:3d36234a1087 1007 */
mbed_official 375:3d36234a1087 1008 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
mbed_official 375:3d36234a1087 1009 {
mbed_official 375:3d36234a1087 1010 /* Disable the IRDA Transmit Complete Interrupt */
mbed_official 375:3d36234a1087 1011 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TC);
mbed_official 375:3d36234a1087 1012
mbed_official 375:3d36234a1087 1013 /* Check if a receive process is ongoing or not */
mbed_official 375:3d36234a1087 1014 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 375:3d36234a1087 1015 {
mbed_official 375:3d36234a1087 1016 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 375:3d36234a1087 1017 }
mbed_official 375:3d36234a1087 1018 else
mbed_official 375:3d36234a1087 1019 {
mbed_official 375:3d36234a1087 1020 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 375:3d36234a1087 1021 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 375:3d36234a1087 1022
mbed_official 375:3d36234a1087 1023 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 375:3d36234a1087 1024 }
mbed_official 375:3d36234a1087 1025
mbed_official 375:3d36234a1087 1026 HAL_IRDA_TxCpltCallback(hirda);
mbed_official 375:3d36234a1087 1027
mbed_official 375:3d36234a1087 1028 return HAL_OK;
mbed_official 375:3d36234a1087 1029 }
mbed_official 375:3d36234a1087 1030
mbed_official 375:3d36234a1087 1031
mbed_official 375:3d36234a1087 1032 /**
mbed_official 237:f3da66175598 1033 * @brief Receive an amount of data in non blocking mode.
mbed_official 237:f3da66175598 1034 * Function called under interruption only, once
mbed_official 237:f3da66175598 1035 * interruptions have been enabled by HAL_IRDA_Receive_IT()
mbed_official 237:f3da66175598 1036 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 1037 * @retval HAL status
mbed_official 237:f3da66175598 1038 */
mbed_official 237:f3da66175598 1039 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 1040 {
mbed_official 237:f3da66175598 1041 uint16_t* tmp;
mbed_official 237:f3da66175598 1042 uint16_t uhMask = hirda->Mask;
mbed_official 237:f3da66175598 1043
mbed_official 237:f3da66175598 1044 if ((hirda->State == HAL_IRDA_STATE_BUSY_RX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
mbed_official 237:f3da66175598 1045 {
mbed_official 237:f3da66175598 1046
mbed_official 237:f3da66175598 1047 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 237:f3da66175598 1048 {
mbed_official 237:f3da66175598 1049 tmp = (uint16_t*) hirda->pRxBuffPtr ;
mbed_official 237:f3da66175598 1050 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
mbed_official 237:f3da66175598 1051 hirda->pRxBuffPtr +=2;
mbed_official 237:f3da66175598 1052 }
mbed_official 237:f3da66175598 1053 else
mbed_official 237:f3da66175598 1054 {
mbed_official 237:f3da66175598 1055 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
mbed_official 237:f3da66175598 1056 }
mbed_official 237:f3da66175598 1057
mbed_official 237:f3da66175598 1058 if(--hirda->RxXferCount == 0)
mbed_official 237:f3da66175598 1059 {
mbed_official 237:f3da66175598 1060 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 237:f3da66175598 1061
mbed_official 237:f3da66175598 1062 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 237:f3da66175598 1063 {
mbed_official 237:f3da66175598 1064 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 237:f3da66175598 1065 }
mbed_official 237:f3da66175598 1066 else
mbed_official 237:f3da66175598 1067 {
mbed_official 237:f3da66175598 1068 /* Disable the IRDA Parity Error Interrupt */
mbed_official 237:f3da66175598 1069 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
mbed_official 237:f3da66175598 1070
mbed_official 237:f3da66175598 1071 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 237:f3da66175598 1072 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 237:f3da66175598 1073
mbed_official 237:f3da66175598 1074 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 1075 }
mbed_official 237:f3da66175598 1076
mbed_official 237:f3da66175598 1077 HAL_IRDA_RxCpltCallback(hirda);
mbed_official 237:f3da66175598 1078
mbed_official 237:f3da66175598 1079 return HAL_OK;
mbed_official 237:f3da66175598 1080 }
mbed_official 237:f3da66175598 1081
mbed_official 237:f3da66175598 1082 return HAL_OK;
mbed_official 237:f3da66175598 1083 }
mbed_official 237:f3da66175598 1084 else
mbed_official 237:f3da66175598 1085 {
mbed_official 237:f3da66175598 1086 return HAL_BUSY;
mbed_official 237:f3da66175598 1087 }
mbed_official 237:f3da66175598 1088 }
mbed_official 237:f3da66175598 1089
mbed_official 237:f3da66175598 1090 /**
mbed_official 237:f3da66175598 1091 * @}
mbed_official 237:f3da66175598 1092 */
mbed_official 237:f3da66175598 1093
mbed_official 375:3d36234a1087 1094 /** @addtogroup IRDA_Exported_Functions IRDA Exported Functions
mbed_official 375:3d36234a1087 1095 * @{
mbed_official 375:3d36234a1087 1096 */
mbed_official 375:3d36234a1087 1097
mbed_official 375:3d36234a1087 1098 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions
mbed_official 237:f3da66175598 1099 * @brief IRDA control functions
mbed_official 237:f3da66175598 1100 *
mbed_official 237:f3da66175598 1101 @verbatim
mbed_official 237:f3da66175598 1102 ===============================================================================
mbed_official 375:3d36234a1087 1103 ##### Peripheral State and Error functions #####
mbed_official 237:f3da66175598 1104 ===============================================================================
mbed_official 237:f3da66175598 1105 [..]
mbed_official 237:f3da66175598 1106 This subsection provides a set of functions allowing to control the IRDA.
mbed_official 237:f3da66175598 1107 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IRDA peripheral.
mbed_official 237:f3da66175598 1108 (+) IRDA_SetConfig() API is used to configure the IRDA communications parameters.
mbed_official 237:f3da66175598 1109 @endverbatim
mbed_official 237:f3da66175598 1110 * @{
mbed_official 237:f3da66175598 1111 */
mbed_official 237:f3da66175598 1112
mbed_official 237:f3da66175598 1113 /**
mbed_official 237:f3da66175598 1114 * @brief return the IRDA state
mbed_official 237:f3da66175598 1115 * @param hirda: irda handle
mbed_official 237:f3da66175598 1116 * @retval HAL state
mbed_official 237:f3da66175598 1117 */
mbed_official 237:f3da66175598 1118 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 1119 {
mbed_official 237:f3da66175598 1120 return hirda->State;
mbed_official 237:f3da66175598 1121 }
mbed_official 237:f3da66175598 1122
mbed_official 237:f3da66175598 1123 /**
mbed_official 237:f3da66175598 1124 * @brief Return the IRDA error code
mbed_official 237:f3da66175598 1125 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 1126 * the configuration information for the specified IRDA.
mbed_official 237:f3da66175598 1127 * @retval IRDA Error Code
mbed_official 237:f3da66175598 1128 */
mbed_official 237:f3da66175598 1129 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 1130 {
mbed_official 237:f3da66175598 1131 return hirda->ErrorCode;
mbed_official 237:f3da66175598 1132 }
mbed_official 237:f3da66175598 1133
mbed_official 237:f3da66175598 1134 /**
mbed_official 237:f3da66175598 1135 * @}
mbed_official 237:f3da66175598 1136 */
mbed_official 237:f3da66175598 1137
mbed_official 237:f3da66175598 1138 /**
mbed_official 375:3d36234a1087 1139 * @}
mbed_official 375:3d36234a1087 1140 */
mbed_official 375:3d36234a1087 1141
mbed_official 375:3d36234a1087 1142 /** @addtogroup IRDA_Private_Functions IRDA Private Functions
mbed_official 375:3d36234a1087 1143 * @{
mbed_official 375:3d36234a1087 1144 */
mbed_official 375:3d36234a1087 1145
mbed_official 375:3d36234a1087 1146 /**
mbed_official 237:f3da66175598 1147 * @brief Configure the IRDA peripheral
mbed_official 237:f3da66175598 1148 * @param hirda: irda handle
mbed_official 237:f3da66175598 1149 * @retval None
mbed_official 237:f3da66175598 1150 */
mbed_official 237:f3da66175598 1151 static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 1152 {
mbed_official 237:f3da66175598 1153 uint32_t tmpreg = 0x00000000;
mbed_official 237:f3da66175598 1154 IRDA_ClockSourceTypeDef clocksource = IRDA_CLOCKSOURCE_UNDEFINED;
mbed_official 237:f3da66175598 1155 HAL_StatusTypeDef ret = HAL_OK;
mbed_official 237:f3da66175598 1156
mbed_official 237:f3da66175598 1157 /* Check the communication parameters */
mbed_official 237:f3da66175598 1158 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
mbed_official 237:f3da66175598 1159 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
mbed_official 237:f3da66175598 1160 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
mbed_official 237:f3da66175598 1161 assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode));
mbed_official 237:f3da66175598 1162 assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler));
mbed_official 237:f3da66175598 1163 assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode));
mbed_official 237:f3da66175598 1164
mbed_official 237:f3da66175598 1165 /*-------------------------- USART CR1 Configuration -----------------------*/
mbed_official 237:f3da66175598 1166 /* Configure the IRDA Word Length, Parity and transfer Mode:
mbed_official 237:f3da66175598 1167 Set the M bits according to hirda->Init.WordLength value
mbed_official 237:f3da66175598 1168 Set PCE and PS bits according to hirda->Init.Parity value
mbed_official 237:f3da66175598 1169 Set TE and RE bits according to hirda->Init.Mode value */
mbed_official 237:f3da66175598 1170 tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ;
mbed_official 237:f3da66175598 1171
mbed_official 237:f3da66175598 1172 MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg);
mbed_official 237:f3da66175598 1173
mbed_official 237:f3da66175598 1174 /*-------------------------- USART CR3 Configuration -----------------------*/
mbed_official 237:f3da66175598 1175 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode);
mbed_official 237:f3da66175598 1176
mbed_official 237:f3da66175598 1177 /*-------------------------- USART GTPR Configuration ----------------------*/
mbed_official 237:f3da66175598 1178 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
mbed_official 237:f3da66175598 1179
mbed_official 237:f3da66175598 1180 /*-------------------------- USART BRR Configuration -----------------------*/
mbed_official 237:f3da66175598 1181 __HAL_IRDA_GETCLOCKSOURCE(hirda, clocksource);
mbed_official 237:f3da66175598 1182 switch (clocksource)
mbed_official 237:f3da66175598 1183 {
mbed_official 237:f3da66175598 1184 case IRDA_CLOCKSOURCE_PCLK1:
mbed_official 237:f3da66175598 1185 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hirda->Init.BaudRate);
mbed_official 237:f3da66175598 1186 break;
mbed_official 237:f3da66175598 1187 case IRDA_CLOCKSOURCE_PCLK2:
mbed_official 237:f3da66175598 1188 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK2Freq() / hirda->Init.BaudRate);
mbed_official 237:f3da66175598 1189 break;
mbed_official 237:f3da66175598 1190 case IRDA_CLOCKSOURCE_HSI:
mbed_official 237:f3da66175598 1191 hirda->Instance->BRR = (uint16_t)(HSI_VALUE / hirda->Init.BaudRate);
mbed_official 237:f3da66175598 1192 break;
mbed_official 237:f3da66175598 1193 case IRDA_CLOCKSOURCE_SYSCLK:
mbed_official 237:f3da66175598 1194 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hirda->Init.BaudRate);
mbed_official 237:f3da66175598 1195 break;
mbed_official 237:f3da66175598 1196 case IRDA_CLOCKSOURCE_LSE:
mbed_official 237:f3da66175598 1197 hirda->Instance->BRR = (uint16_t)(LSE_VALUE / hirda->Init.BaudRate);
mbed_official 237:f3da66175598 1198 break;
mbed_official 237:f3da66175598 1199 case IRDA_CLOCKSOURCE_UNDEFINED:
mbed_official 237:f3da66175598 1200 default:
mbed_official 237:f3da66175598 1201 ret = HAL_ERROR;
mbed_official 237:f3da66175598 1202 break;
mbed_official 237:f3da66175598 1203 }
mbed_official 237:f3da66175598 1204
mbed_official 237:f3da66175598 1205 return ret;
mbed_official 237:f3da66175598 1206 }
mbed_official 237:f3da66175598 1207
mbed_official 237:f3da66175598 1208 /**
mbed_official 237:f3da66175598 1209 * @brief Check the IRDA Idle State
mbed_official 237:f3da66175598 1210 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 1211 * @retval HAL status
mbed_official 237:f3da66175598 1212 */
mbed_official 237:f3da66175598 1213 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda)
mbed_official 237:f3da66175598 1214 {
mbed_official 237:f3da66175598 1215
mbed_official 237:f3da66175598 1216 /* Initialize the IRDA ErrorCode */
mbed_official 237:f3da66175598 1217 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 237:f3da66175598 1218
mbed_official 237:f3da66175598 1219 /* Check if the Transmitter is enabled */
mbed_official 237:f3da66175598 1220 if((hirda->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
mbed_official 237:f3da66175598 1221 {
mbed_official 237:f3da66175598 1222 /* Wait until TEACK flag is set */
mbed_official 237:f3da66175598 1223 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_TEACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
mbed_official 237:f3da66175598 1224 {
mbed_official 237:f3da66175598 1225 /* Timeout Occured */
mbed_official 237:f3da66175598 1226 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 1227 }
mbed_official 237:f3da66175598 1228 }
mbed_official 237:f3da66175598 1229 /* Check if the Receiver is enabled */
mbed_official 237:f3da66175598 1230 if((hirda->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
mbed_official 237:f3da66175598 1231 {
mbed_official 237:f3da66175598 1232 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_REACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
mbed_official 237:f3da66175598 1233 {
mbed_official 237:f3da66175598 1234 /* Timeout Occured */
mbed_official 237:f3da66175598 1235 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 1236 }
mbed_official 237:f3da66175598 1237 }
mbed_official 237:f3da66175598 1238
mbed_official 237:f3da66175598 1239 /* Initialize the IRDA state*/
mbed_official 237:f3da66175598 1240 hirda->State= HAL_IRDA_STATE_READY;
mbed_official 237:f3da66175598 1241 /* Process Unlocked */
mbed_official 237:f3da66175598 1242 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 1243
mbed_official 237:f3da66175598 1244 return HAL_OK;
mbed_official 237:f3da66175598 1245 }
mbed_official 237:f3da66175598 1246
mbed_official 237:f3da66175598 1247 /**
mbed_official 237:f3da66175598 1248 * @brief Handle IRDA Communication Timeout.
mbed_official 237:f3da66175598 1249 * @param hirda: IRDA handle
mbed_official 237:f3da66175598 1250 * @param Flag: specifies the IRDA flag to check.
mbed_official 237:f3da66175598 1251 * @param Status: the flag status (SET or RESET). The function is locked in a while loop as long as the flag remains set to Status.
mbed_official 237:f3da66175598 1252 * @param Timeout: Timeout duration
mbed_official 237:f3da66175598 1253 * @retval HAL status
mbed_official 237:f3da66175598 1254 */
mbed_official 237:f3da66175598 1255 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
mbed_official 237:f3da66175598 1256 {
mbed_official 237:f3da66175598 1257 uint32_t tickstart = HAL_GetTick();
mbed_official 237:f3da66175598 1258
mbed_official 237:f3da66175598 1259 /* Wait until flag is set */
mbed_official 237:f3da66175598 1260 if(Status == RESET)
mbed_official 237:f3da66175598 1261 {
mbed_official 237:f3da66175598 1262 while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
mbed_official 237:f3da66175598 1263 {
mbed_official 237:f3da66175598 1264 /* Check for the Timeout */
mbed_official 237:f3da66175598 1265 if(Timeout != HAL_MAX_DELAY)
mbed_official 237:f3da66175598 1266 {
mbed_official 237:f3da66175598 1267 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 237:f3da66175598 1268 {
mbed_official 237:f3da66175598 1269 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
mbed_official 237:f3da66175598 1270 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 237:f3da66175598 1271 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 237:f3da66175598 1272 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
mbed_official 237:f3da66175598 1273 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 237:f3da66175598 1274
mbed_official 237:f3da66175598 1275 hirda->State= HAL_IRDA_STATE_TIMEOUT;
mbed_official 237:f3da66175598 1276
mbed_official 237:f3da66175598 1277 /* Process Unlocked */
mbed_official 237:f3da66175598 1278 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 1279
mbed_official 237:f3da66175598 1280 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 1281 }
mbed_official 237:f3da66175598 1282 }
mbed_official 237:f3da66175598 1283 }
mbed_official 237:f3da66175598 1284 }
mbed_official 237:f3da66175598 1285 else
mbed_official 237:f3da66175598 1286 {
mbed_official 237:f3da66175598 1287 while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
mbed_official 237:f3da66175598 1288 {
mbed_official 237:f3da66175598 1289 /* Check for the Timeout */
mbed_official 237:f3da66175598 1290 if(Timeout != HAL_MAX_DELAY)
mbed_official 237:f3da66175598 1291 {
mbed_official 237:f3da66175598 1292 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 237:f3da66175598 1293 {
mbed_official 237:f3da66175598 1294 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
mbed_official 237:f3da66175598 1295 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 237:f3da66175598 1296 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 237:f3da66175598 1297 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
mbed_official 237:f3da66175598 1298 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 237:f3da66175598 1299
mbed_official 237:f3da66175598 1300 hirda->State= HAL_IRDA_STATE_TIMEOUT;
mbed_official 237:f3da66175598 1301
mbed_official 237:f3da66175598 1302 /* Process Unlocked */
mbed_official 237:f3da66175598 1303 __HAL_UNLOCK(hirda);
mbed_official 237:f3da66175598 1304
mbed_official 237:f3da66175598 1305 return HAL_TIMEOUT;
mbed_official 237:f3da66175598 1306 }
mbed_official 237:f3da66175598 1307 }
mbed_official 237:f3da66175598 1308 }
mbed_official 237:f3da66175598 1309 }
mbed_official 237:f3da66175598 1310 return HAL_OK;
mbed_official 237:f3da66175598 1311 }
mbed_official 237:f3da66175598 1312
mbed_official 237:f3da66175598 1313 /**
mbed_official 237:f3da66175598 1314 * @}
mbed_official 237:f3da66175598 1315 */
mbed_official 237:f3da66175598 1316
mbed_official 237:f3da66175598 1317 #endif /* HAL_IRDA_MODULE_ENABLED */
mbed_official 237:f3da66175598 1318 /**
mbed_official 237:f3da66175598 1319 * @}
mbed_official 237:f3da66175598 1320 */
mbed_official 237:f3da66175598 1321
mbed_official 237:f3da66175598 1322 /**
mbed_official 237:f3da66175598 1323 * @}
mbed_official 237:f3da66175598 1324 */
mbed_official 237:f3da66175598 1325
mbed_official 237:f3da66175598 1326 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/