mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
jaerts
Date:
Tue Dec 22 13:22:16 2015 +0000
Revision:
637:ed69428d4850
Parent:
610:813dcc80987e
Add very shady LPC1768 CAN Filter implementation

Who changed what in which revision?

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