TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

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