Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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