mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Nov 03 10:30:07 2014 +0000
Revision:
381:5460fc57b6e4
Synchronized with git revision 02478cd1f27fc7b9643486472635eb515b2bca81

Full URL: https://github.com/mbedmicro/mbed/commit/02478cd1f27fc7b9643486472635eb515b2bca81/

Target: LPC1549 - Fix serial interrupt issues (issue report #616)

Who changed what in which revision?

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