2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_irda.c
\r
4 * @author MCD Application Team
\r
7 * @brief IRDA HAL module driver.
\r
8 * This file provides firmware functions to manage the following
\r
9 * functionalities of the IrDA SIR ENDEC block (IrDA):
\r
10 * + Initialization and de-initialization methods
\r
11 * + IO operation methods
\r
12 * + Peripheral Control methods
\r
15 ==============================================================================
\r
16 ##### How to use this driver #####
\r
17 ==============================================================================
\r
19 The IRDA HAL driver can be used as follows:
\r
21 (#) Declare a IRDA_HandleTypeDef handle structure.
\r
22 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API:
\r
23 (##) Enable the USARTx interface clock.
\r
24 (##) IRDA pins configuration:
\r
25 (+++) Enable the clock for the IRDA GPIOs.
\r
26 (+++) Configure these IRDA pins as alternate function pull-up.
\r
27 (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
\r
28 and HAL_IRDA_Receive_IT() APIs):
\r
29 (+++) Configure the USARTx interrupt priority.
\r
30 (+++) Enable the NVIC USART IRQ handle.
\r
31 (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
\r
32 and HAL_IRDA_Receive_DMA() APIs):
\r
33 (+++) Declare a DMA handle structure for the Tx/Rx stream.
\r
34 (+++) Enable the DMAx interface clock.
\r
35 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
\r
36 (+++) Configure the DMA Tx/Rx Stream.
\r
37 (+++) Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle.
\r
38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
\r
40 (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler
\r
41 and Mode(Receiver/Transmitter) in the hirda Init structure.
\r
43 (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
\r
44 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
\r
45 by calling the customized HAL_IRDA_MspInit() API.
\r
46 -@@- The specific IRDA interrupts (Transmission complete interrupt,
\r
47 RXNE interrupt and Error Interrupts) will be managed using the macros
\r
48 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
\r
50 (#) Three operation modes are available within this driver :
\r
52 *** Polling mode IO operation ***
\r
53 =================================
\r
55 (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
\r
56 (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
\r
58 *** Interrupt mode IO operation ***
\r
59 ===================================
\r
61 (+) Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT()
\r
62 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
\r
63 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
\r
64 (+) Receive an amount of data in non blocking mode using HAL_IRDA_Receive_IT()
\r
65 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
\r
66 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
\r
67 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
\r
68 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
\r
70 *** DMA mode IO operation ***
\r
71 =============================
\r
73 (+) Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
\r
74 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
\r
75 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
\r
76 (+) Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA()
\r
77 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
\r
78 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
\r
79 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
\r
80 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
\r
82 *** IRDA HAL driver macros list ***
\r
83 ===================================
\r
85 Below the list of most used macros in IRDA HAL driver.
\r
87 (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
\r
88 (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
\r
89 (+) __HAL_IRDA_GET_FLAG : Checks whether the specified IRDA flag is set or not
\r
90 (+) __HAL_IRDA_CLEAR_FLAG : Clears the specified IRDA pending flag
\r
91 (+) __HAL_IRDA_ENABLE_IT: Enables the specified IRDA interrupt
\r
92 (+) __HAL_IRDA_DISABLE_IT: Disables the specified IRDA interrupt
\r
94 (@) You can refer to the IRDA HAL driver header file for more useful macros
\r
97 ******************************************************************************
\r
100 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
102 * Redistribution and use in source and binary forms, with or without modification,
\r
103 * are permitted provided that the following conditions are met:
\r
104 * 1. Redistributions of source code must retain the above copyright notice,
\r
105 * this list of conditions and the following disclaimer.
\r
106 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
107 * this list of conditions and the following disclaimer in the documentation
\r
108 * and/or other materials provided with the distribution.
\r
109 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
110 * may be used to endorse or promote products derived from this software
\r
111 * without specific prior written permission.
\r
113 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
114 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
115 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
116 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
117 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
119 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
120 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
121 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
122 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
124 ******************************************************************************
\r
127 /* Includes ------------------------------------------------------------------*/
\r
128 #include "stm32f7xx_hal.h"
\r
130 /** @addtogroup STM32F7xx_HAL_Driver
\r
134 /** @defgroup IRDA IRDA
\r
135 * @brief HAL IRDA module driver
\r
138 #ifdef HAL_IRDA_MODULE_ENABLED
\r
140 /* Private typedef -----------------------------------------------------------*/
\r
141 /* Private define ------------------------------------------------------------*/
\r
142 /** @addtogroup IRDA_Private_Constants
\r
145 #define TEACK_REACK_TIMEOUT 1000
\r
146 #define HAL_IRDA_TXDMA_TIMEOUTVALUE 22000
\r
147 #define IRDA_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE \
\r
148 | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE))
\r
152 /* Private macro -------------------------------------------------------------*/
\r
153 /* Private variables ---------------------------------------------------------*/
\r
154 /* Private function prototypes -----------------------------------------------*/
\r
155 /** @addtogroup IRDA_Private_Functions
\r
158 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
\r
159 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
\r
160 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
\r
161 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
\r
162 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
\r
163 static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda);
\r
164 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda);
\r
165 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
\r
166 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
\r
167 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
\r
168 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
\r
172 /* Exported functions --------------------------------------------------------*/
\r
173 /** @defgroup IRDA_Exported_Functions IrDA Exported Functions
\r
177 /** @defgroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
\r
178 * @brief Initialization and Configuration functions
\r
182 ===============================================================================
\r
183 ##### Initialization and Configuration functions #####
\r
184 ===============================================================================
\r
186 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
\r
188 (+) For the asynchronous mode only these parameters can be configured:
\r
191 (++) Parity: If the parity is enabled, then the MSB bit of the data written
\r
192 in the data register is transmitted but is changed by the parity bit.
\r
193 Depending on the frame length defined by the M bit (8-bits or 9-bits),
\r
194 please refer to Reference manual for possible IRDA frame formats.
\r
195 (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
\r
196 not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
\r
197 specification specifies a minimum of 10 ms delay between transmission and
\r
198 reception (IrDA is a half duplex protocol).
\r
199 (++) Mode: Receiver/transmitter modes
\r
200 (++) IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.
\r
202 The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures
\r
203 are available in reference manual).
\r
210 * @brief Initializes the IRDA mode according to the specified
\r
211 * parameters in the IRDA_InitTypeDef and create the associated handle.
\r
212 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
213 * the configuration information for the specified IRDA module.
\r
214 * @retval HAL status
\r
216 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
\r
218 /* Check the IRDA handle allocation */
\r
224 /* Check the USART/UART associated to the IRDA handle */
\r
225 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
\r
227 if(hirda->State == HAL_IRDA_STATE_RESET)
\r
229 /* Allocate lock resource and initialize it */
\r
230 hirda->Lock = HAL_UNLOCKED;
\r
231 /* Init the low level hardware : GPIO, CLOCK, CORTEX */
\r
232 HAL_IRDA_MspInit(hirda);
\r
235 hirda->State = HAL_IRDA_STATE_BUSY;
\r
237 /* Disable the Peripheral to update the configuration registers */
\r
238 __HAL_IRDA_DISABLE(hirda);
\r
240 /* Set the IRDA Communication parameters */
\r
241 IRDA_SetConfig(hirda);
\r
243 /* In IRDA mode, the following bits must be kept cleared:
\r
244 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
\r
245 - SCEN and HDSEL bits in the USART_CR3 register.*/
\r
246 hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP);
\r
247 hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL);
\r
249 /* set the UART/USART in IRDA mode */
\r
250 hirda->Instance->CR3 |= USART_CR3_IREN;
\r
252 /* Enable the Peripheral */
\r
253 __HAL_IRDA_ENABLE(hirda);
\r
255 /* TEACK and/or REACK to check before moving hirda->State to Ready */
\r
256 return (IRDA_CheckIdleState(hirda));
\r
260 * @brief DeInitializes the IRDA peripheral
\r
261 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
262 * the configuration information for the specified IRDA module.
\r
263 * @retval HAL status
\r
265 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
\r
267 /* Check the IRDA handle allocation */
\r
273 /* Check the parameters */
\r
274 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
\r
276 hirda->State = HAL_IRDA_STATE_BUSY;
\r
278 /* DeInit the low level hardware */
\r
279 HAL_IRDA_MspDeInit(hirda);
\r
280 /* Disable the Peripheral */
\r
281 __HAL_IRDA_DISABLE(hirda);
\r
283 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
284 hirda->State = HAL_IRDA_STATE_RESET;
\r
287 __HAL_UNLOCK(hirda);
\r
293 * @brief IRDA MSP Init.
\r
294 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
295 * the configuration information for the specified IRDA module.
\r
298 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
\r
300 /* NOTE : This function Should not be modified, when the callback is needed,
\r
301 the HAL_IRDA_MspInit could be implemented in the user file
\r
306 * @brief IRDA MSP DeInit.
\r
307 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
308 * the configuration information for the specified IRDA module.
\r
311 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
\r
313 /* NOTE : This function Should not be modified, when the callback is needed,
\r
314 the HAL_IRDA_MspDeInit could be implemented in the user file
\r
322 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
\r
323 * @brief IRDA Transmit/Receive functions
\r
326 ===============================================================================
\r
327 ##### IO operation functions #####
\r
328 ===============================================================================
\r
329 This subsection provides a set of functions allowing to manage the IRDA data transfers.
\r
331 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
\r
332 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
\r
333 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
\r
334 While receiving data, transmission should be avoided as the data to be transmitted
\r
335 could be corrupted.
\r
337 (#) There are two modes of transfer:
\r
338 (++) Blocking mode: the communication is performed in polling mode.
\r
339 The HAL status of all data processing is returned by the same function
\r
340 after finishing transfer.
\r
341 (++) No-Blocking mode: the communication is performed using Interrupts
\r
342 or DMA, these API's return the HAL status.
\r
343 The end of the data processing will be indicated through the
\r
344 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
\r
346 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
\r
347 will be executed respectively at the end of the Transmit or Receive process
\r
348 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
\r
350 (#) Blocking mode API's are :
\r
351 (++) HAL_IRDA_Transmit()
\r
352 (++) HAL_IRDA_Receive()
\r
354 (#) Non-Blocking mode API's with Interrupt are :
\r
355 (++) HAL_IRDA_Transmit_IT()
\r
356 (++) HAL_IRDA_Receive_IT()
\r
357 (++) HAL_IRDA_IRQHandler()
\r
358 (++) IRDA_Transmit_IT()
\r
359 (++) IRDA_Receive_IT()
\r
361 (#) Non-Blocking mode functions with DMA are :
\r
362 (++) HAL_IRDA_Transmit_DMA()
\r
363 (++) HAL_IRDA_Receive_DMA()
\r
365 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
\r
366 (++) HAL_IRDA_TxCpltCallback()
\r
367 (++) HAL_IRDA_RxCpltCallback()
\r
368 (++) HAL_IRDA_ErrorCallback()
\r
375 * @brief Sends an amount of data in blocking mode.
\r
376 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
377 * the configuration information for the specified IRDA module.
\r
378 * @param pData: Pointer to data buffer
\r
379 * @param Size: Amount of data to be sent
\r
380 * @param Timeout: Specify timeout value
\r
381 * @retval HAL status
\r
383 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
\r
387 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
\r
389 if((pData == NULL) || (Size == 0))
\r
394 /* Process Locked */
\r
396 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
398 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
400 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
404 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
407 hirda->TxXferSize = Size;
\r
408 hirda->TxXferCount = Size;
\r
409 while(hirda->TxXferCount > 0)
\r
411 hirda->TxXferCount--;
\r
413 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
\r
415 return HAL_TIMEOUT;
\r
417 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
419 tmp = (uint16_t*) pData;
\r
420 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
\r
425 hirda->Instance->TDR = (*pData++ & (uint8_t)0xFF);
\r
429 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK)
\r
431 return HAL_TIMEOUT;
\r
434 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
436 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
440 hirda->State = HAL_IRDA_STATE_READY;
\r
443 /* Process Unlocked */
\r
444 __HAL_UNLOCK(hirda);
\r
455 * @brief Receive an amount of data in blocking mode.
\r
456 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
457 * the configuration information for the specified IRDA module.
\r
458 * @param pData: Pointer to data buffer
\r
459 * @param Size: Amount of data to be received
\r
460 * @param Timeout: Specify timeout value
\r
461 * @retval HAL status
\r
463 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
\r
468 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
\r
470 if((pData == NULL) || (Size == 0))
\r
475 /* Process Locked */
\r
477 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
479 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
481 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
485 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
488 hirda->RxXferSize = Size;
\r
489 hirda->RxXferCount = Size;
\r
491 /* Computation of the mask to apply to the RDR register
\r
492 of the UART associated to the IRDA */
\r
493 IRDA_MASK_COMPUTATION(hirda);
\r
494 uhMask = hirda->Mask;
\r
496 /* Check data remaining to be received */
\r
497 while(hirda->RxXferCount > 0)
\r
499 hirda->RxXferCount--;
\r
501 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
\r
503 return HAL_TIMEOUT;
\r
505 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
507 tmp = (uint16_t*) pData ;
\r
508 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
\r
513 *pData++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
\r
517 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
519 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
523 hirda->State = HAL_IRDA_STATE_READY;
\r
526 /* Process Unlocked */
\r
527 __HAL_UNLOCK(hirda);
\r
538 * @brief Send an amount of data in non blocking mode.
\r
539 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
540 * the configuration information for the specified IRDA module.
\r
541 * @param pData: Pointer to data buffer
\r
542 * @param Size: Amount of data to be sent
\r
543 * @retval HAL status
\r
545 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
547 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
\r
549 if((pData == NULL) || (Size == 0))
\r
554 /* Process Locked */
\r
557 hirda->pTxBuffPtr = pData;
\r
558 hirda->TxXferSize = Size;
\r
559 hirda->TxXferCount = Size;
\r
561 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
562 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
564 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
568 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
571 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
572 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
\r
574 /* Process Unlocked */
\r
575 __HAL_UNLOCK(hirda);
\r
577 /* Enable the IRDA Transmit Complete Interrupt */
\r
578 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
\r
589 * @brief Receives an amount of data in non blocking mode.
\r
590 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
591 * the configuration information for the specified IRDA module.
\r
592 * @param pData: Pointer to data buffer
\r
593 * @param Size: Amount of data to be received
\r
594 * @retval HAL status
\r
596 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
598 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
\r
600 if((pData == NULL) || (Size == 0))
\r
605 /* Process Locked */
\r
608 hirda->pRxBuffPtr = pData;
\r
609 hirda->RxXferSize = Size;
\r
610 hirda->RxXferCount = Size;
\r
612 /* Computation of the mask to apply to the RDR register
\r
613 of the UART associated to the IRDA */
\r
614 IRDA_MASK_COMPUTATION(hirda);
\r
616 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
617 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
619 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
623 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
626 /* Enable the IRDA Parity Error Interrupt */
\r
627 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
\r
629 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
630 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
\r
632 /* Process Unlocked */
\r
633 __HAL_UNLOCK(hirda);
\r
635 /* Enable the IRDA Data Register not empty Interrupt */
\r
636 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE);
\r
647 * @brief Sends an amount of data in non blocking mode.
\r
648 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
649 * the configuration information for the specified IRDA module.
\r
650 * @param pData: Pointer to data buffer
\r
651 * @param Size: Amount of data to be sent
\r
652 * @retval HAL status
\r
654 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
658 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
\r
660 if((pData == NULL) || (Size == 0))
\r
665 /* Process Locked */
\r
668 hirda->pTxBuffPtr = pData;
\r
669 hirda->TxXferSize = Size;
\r
670 hirda->TxXferCount = Size;
\r
672 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
674 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
676 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
680 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
683 /* Set the IRDA DMA transfer complete callback */
\r
684 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
\r
686 /* Set the IRDA DMA half transfer complete callback */
\r
687 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
\r
689 /* Set the DMA error callback */
\r
690 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
\r
692 /* Enable the IRDA transmit DMA channel */
\r
693 tmp = (uint32_t*)&pData;
\r
694 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->TDR, Size);
\r
696 /* Clear the TC flag in the SR register by writing 0 to it */
\r
697 __HAL_IRDA_CLEAR_IT(hirda, IRDA_FLAG_TC);
\r
699 /* Enable the DMA transfer for transmit request by setting the DMAT bit
\r
700 in the IRDA CR3 register */
\r
701 hirda->Instance->CR3 |= USART_CR3_DMAT;
\r
703 /* Process Unlocked */
\r
704 __HAL_UNLOCK(hirda);
\r
715 * @brief Receives an amount of data in non blocking mode.
\r
716 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
717 * the configuration information for the specified IRDA module.
\r
718 * @param pData: Pointer to data buffer
\r
719 * @param Size: Amount of data to be received
\r
720 * @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
\r
721 * @retval HAL status
\r
723 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
727 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
\r
729 if((pData == NULL) || (Size == 0))
\r
734 /* Process Locked */
\r
737 hirda->pRxBuffPtr = pData;
\r
738 hirda->RxXferSize = Size;
\r
740 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
741 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
743 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
747 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
750 /* Set the IRDA DMA transfer complete callback */
\r
751 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
\r
753 /* Set the IRDA DMA half transfer complete callback */
\r
754 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
\r
756 /* Set the DMA error callback */
\r
757 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
\r
759 /* Enable the DMA channel */
\r
760 tmp = (uint32_t*)&pData;
\r
761 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->RDR, *(uint32_t*)tmp, Size);
\r
763 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
\r
764 in the IRDA CR3 register */
\r
765 hirda->Instance->CR3 |= USART_CR3_DMAR;
\r
767 /* Process Unlocked */
\r
768 __HAL_UNLOCK(hirda);
\r
779 * @brief Pauses the DMA Transfer.
\r
780 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
781 * the configuration information for the specified IRDA module.
\r
782 * @retval HAL status
\r
784 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
\r
786 /* Process Locked */
\r
789 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
791 /* Disable the UART DMA Tx request */
\r
792 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
\r
794 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
796 /* Disable the UART DMA Rx request */
\r
797 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
\r
799 else if (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
801 /* Disable the UART DMA Tx & Rx requests */
\r
802 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
\r
803 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
\r
806 /* Process Unlocked */
\r
807 __HAL_UNLOCK(hirda);
\r
813 * @brief Resumes the DMA Transfer.
\r
814 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
815 * the configuration information for the specified UART module.
\r
816 * @retval HAL status
\r
818 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
\r
820 /* Process Locked */
\r
823 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
825 /* Enable the UART DMA Tx request */
\r
826 hirda->Instance->CR3 |= USART_CR3_DMAT;
\r
828 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
830 /* Clear the Overrun flag before resuming the Rx transfer*/
\r
831 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
\r
833 /* Enable the UART DMA Rx request */
\r
834 hirda->Instance->CR3 |= USART_CR3_DMAR;
\r
836 else if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
838 /* Clear the Overrun flag before resuming the Rx transfer*/
\r
839 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
\r
841 /* Enable the UART DMA Tx & Rx request */
\r
842 hirda->Instance->CR3 |= USART_CR3_DMAT;
\r
843 hirda->Instance->CR3 |= USART_CR3_DMAR;
\r
846 /* Process Unlocked */
\r
847 __HAL_UNLOCK(hirda);
\r
853 * @brief Stops the DMA Transfer.
\r
854 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
855 * the configuration information for the specified UART module.
\r
856 * @retval HAL status
\r
858 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
\r
860 /* The Lock is not implemented on this API to allow the user application
\r
861 to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback():
\r
862 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
\r
863 and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback()
\r
866 /* Disable the UART Tx/Rx DMA requests */
\r
867 hirda->Instance->CR3 &= ~USART_CR3_DMAT;
\r
868 hirda->Instance->CR3 &= ~USART_CR3_DMAR;
\r
870 /* Abort the UART DMA tx channel */
\r
871 if(hirda->hdmatx != NULL)
\r
873 HAL_DMA_Abort(hirda->hdmatx);
\r
875 /* Abort the UART DMA rx channel */
\r
876 if(hirda->hdmarx != NULL)
\r
878 HAL_DMA_Abort(hirda->hdmarx);
\r
881 hirda->State = HAL_IRDA_STATE_READY;
\r
887 * @brief This function handles IRDA interrupt request.
\r
888 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
889 * the configuration information for the specified IRDA module.
\r
892 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
\r
894 /* IRDA parity error interrupt occurred -------------------------------------*/
\r
895 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_PE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE) != RESET))
\r
897 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_PEF);
\r
899 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
\r
900 /* Set the IRDA state ready to be able to start again the process */
\r
901 hirda->State = HAL_IRDA_STATE_READY;
\r
904 /* IRDA frame error interrupt occurred --------------------------------------*/
\r
905 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_FE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
\r
907 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_FEF);
\r
909 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
\r
910 /* Set the IRDA state ready to be able to start again the process */
\r
911 hirda->State = HAL_IRDA_STATE_READY;
\r
914 /* IRDA noise error interrupt occurred --------------------------------------*/
\r
915 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_NE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
\r
917 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_NEF);
\r
919 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
\r
920 /* Set the IRDA state ready to be able to start again the process */
\r
921 hirda->State = HAL_IRDA_STATE_READY;
\r
924 /* IRDA Over-Run interrupt occurred -----------------------------------------*/
\r
925 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_ORE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
\r
927 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
\r
929 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
\r
930 /* Set the IRDA state ready to be able to start again the process */
\r
931 hirda->State = HAL_IRDA_STATE_READY;
\r
934 /* Call IRDA Error Call back function if need be --------------------------*/
\r
935 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
\r
937 HAL_IRDA_ErrorCallback(hirda);
\r
940 /* IRDA in mode Receiver ---------------------------------------------------*/
\r
941 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_RXNE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE) != RESET))
\r
943 IRDA_Receive_IT(hirda);
\r
944 /* Clear RXNE interrupt flag */
\r
945 __HAL_IRDA_SEND_REQ(hirda, IRDA_RXDATA_FLUSH_REQUEST);
\r
948 /* IRDA in mode Transmitter ------------------------------------------------*/
\r
949 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TXE) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE) != RESET))
\r
951 IRDA_Transmit_IT(hirda);
\r
954 /* IRDA in mode Transmitter (transmission end) -----------------------------*/
\r
955 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TC) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TC) != RESET))
\r
957 IRDA_EndTransmit_IT(hirda);
\r
962 * @brief Tx Transfer complete callbacks.
\r
963 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
964 * the configuration information for the specified IRDA module.
\r
967 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
\r
969 /* NOTE : This function should not be modified, when the callback is needed,
\r
970 the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file
\r
975 * @brief Tx Half Transfer completed callbacks.
\r
976 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
977 * the configuration information for the specified USART module.
\r
980 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
\r
982 /* NOTE : This function should not be modified, when the callback is needed,
\r
983 the HAL_IRDA_TxCpltCallback can be implemented in the user file
\r
988 * @brief Rx Transfer complete callbacks.
\r
989 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
990 * the configuration information for the specified IRDA module.
\r
993 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
\r
995 /* NOTE : This function should not be modified, when the callback is needed,
\r
996 the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file
\r
1001 * @brief Rx Half Transfer complete callbacks.
\r
1002 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1003 * the configuration information for the specified IRDA module.
\r
1006 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
\r
1008 /* NOTE : This function should not be modified, when the callback is needed,
\r
1009 the HAL_IRDA_RxCpltCallback can be implemented in the user file
\r
1014 * @brief IRDA error callbacks.
\r
1015 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1016 * the configuration information for the specified IRDA module.
\r
1019 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
\r
1021 /* NOTE : This function should not be modified, when the callback is needed,
\r
1022 the HAL_IRDA_ErrorCallback can be implemented in the user file
\r
1030 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral Control functions
\r
1031 * @brief IRDA control functions
\r
1034 ===============================================================================
\r
1035 ##### Peripheral Control functions #####
\r
1036 ===============================================================================
\r
1038 This subsection provides a set of functions allowing to control the IRDA.
\r
1039 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IRDA peripheral.
\r
1040 (+) IRDA_SetConfig() API is used to configure the IRDA communications parameters.
\r
1046 * @brief Returns the IRDA state.
\r
1047 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1048 * the configuration information for the specified IRDA module.
\r
1049 * @retval HAL state
\r
1051 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
\r
1053 return hirda->State;
\r
1057 * @brief Return the IRDA error code
\r
1058 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
\r
1059 * the configuration information for the specified IRDA.
\r
1060 * @retval IRDA Error Code
\r
1062 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
\r
1064 return hirda->ErrorCode;
\r
1072 * @brief Configure the IRDA peripheral
\r
1073 * @param hirda: irda handle
\r
1076 static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
\r
1078 uint32_t tmpreg = 0x00000000;
\r
1079 uint32_t clocksource = 0x00000000;
\r
1081 /* Check the communication parameters */
\r
1082 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
\r
1083 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
\r
1084 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
\r
1085 assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode));
\r
1086 assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler));
\r
1087 assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode));
\r
1088 /*-------------------------- USART CR1 Configuration -----------------------*/
\r
1089 /* Configure the IRDA Word Length, Parity and transfer Mode:
\r
1090 Set the M bits according to hirda->Init.WordLength value
\r
1091 Set PCE and PS bits according to hirda->Init.Parity value
\r
1092 Set TE and RE bits according to hirda->Init.Mode value */
\r
1093 tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ;
\r
1095 MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg);
\r
1097 /*-------------------------- USART CR3 Configuration -----------------------*/
\r
1098 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode);
\r
1100 /*-------------------------- USART GTPR Configuration ----------------------*/
\r
1101 MODIFY_REG(hirda->Instance->GTPR, (uint32_t)USART_GTPR_PSC, hirda->Init.Prescaler);
\r
1103 /*-------------------------- USART BRR Configuration -----------------------*/
\r
1104 IRDA_GETCLOCKSOURCE(hirda, clocksource);
\r
1105 switch (clocksource)
\r
1107 case IRDA_CLOCKSOURCE_PCLK1:
\r
1108 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hirda->Init.BaudRate);
\r
1110 case IRDA_CLOCKSOURCE_PCLK2:
\r
1111 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK2Freq() / hirda->Init.BaudRate);
\r
1113 case IRDA_CLOCKSOURCE_HSI:
\r
1114 hirda->Instance->BRR = (uint16_t)(HSI_VALUE / hirda->Init.BaudRate);
\r
1116 case IRDA_CLOCKSOURCE_SYSCLK:
\r
1117 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hirda->Init.BaudRate);
\r
1119 case IRDA_CLOCKSOURCE_LSE:
\r
1120 hirda->Instance->BRR = (uint16_t)(LSE_VALUE / hirda->Init.BaudRate);
\r
1128 * @brief Check the IRDA Idle State
\r
1129 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1130 * the configuration information for the specified IRDA module.
\r
1131 * @retval HAL status
\r
1133 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda)
\r
1135 /* Initialize the IRDA ErrorCode */
\r
1136 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
1138 /* Check if the Transmitter is enabled */
\r
1139 if((hirda->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
\r
1141 /* Wait until TEACK flag is set */
\r
1142 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_TEACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
\r
1144 hirda->State= HAL_IRDA_STATE_TIMEOUT;
\r
1145 return HAL_TIMEOUT;
\r
1148 /* Check if the Receiver is enabled */
\r
1149 if((hirda->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
\r
1151 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_REACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
\r
1153 hirda->State= HAL_IRDA_STATE_TIMEOUT;
\r
1154 return HAL_TIMEOUT;
\r
1157 /* Process Unlocked */
\r
1158 __HAL_UNLOCK(hirda);
\r
1160 /* Initialize the IRDA state*/
\r
1161 hirda->State= HAL_IRDA_STATE_READY;
\r
1167 * @brief This function handles IRDA Communication Timeout.
\r
1168 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1169 * the configuration information for the specified IRDA module.
\r
1170 * @param Flag: specifies the IRDA flag to check.
\r
1171 * @param Status: The new Flag status (SET or RESET).
\r
1172 * @param Timeout: Timeout duration
\r
1173 * @retval HAL status
\r
1175 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
\r
1177 uint32_t tickstart = 0x00;
\r
1178 tickstart = HAL_GetTick();
\r
1180 /* Wait until flag is set */
\r
1181 if(Status == RESET)
\r
1183 while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
\r
1185 /* Check for the Timeout */
\r
1186 if(Timeout != HAL_MAX_DELAY)
\r
1188 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1190 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1191 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
\r
1192 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
\r
1193 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
\r
1194 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1196 hirda->State= HAL_IRDA_STATE_READY;
\r
1198 /* Process Unlocked */
\r
1199 __HAL_UNLOCK(hirda);
\r
1201 return HAL_TIMEOUT;
\r
1208 while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
\r
1210 /* Check for the Timeout */
\r
1211 if(Timeout != HAL_MAX_DELAY)
\r
1213 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1215 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1216 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
\r
1217 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
\r
1218 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
\r
1219 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1221 hirda->State= HAL_IRDA_STATE_READY;
\r
1223 /* Process Unlocked */
\r
1224 __HAL_UNLOCK(hirda);
\r
1226 return HAL_TIMEOUT;
\r
1235 * @brief Send an amount of data in non blocking mode.
\r
1236 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1237 * the configuration information for the specified IRDA module.
\r
1238 * @retval HAL status
\r
1240 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
\r
1244 if((hirda->State == HAL_IRDA_STATE_BUSY_TX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
\r
1246 if(hirda->TxXferCount == 0)
\r
1248 /* Disable the IRDA Transmit Complete Interrupt */
\r
1249 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
\r
1251 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1253 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
1257 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
1258 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1260 hirda->State = HAL_IRDA_STATE_READY;
\r
1263 HAL_IRDA_TxCpltCallback(hirda);
\r
1269 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
1271 tmp = (uint16_t*) hirda->pTxBuffPtr;
\r
1272 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
\r
1273 hirda->pTxBuffPtr += 2;
\r
1277 hirda->Instance->TDR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0xFF);
\r
1279 hirda->TxXferCount--;
\r
1290 * @brief Wraps up transmission in non blocking mode.
\r
1291 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1292 * the configuration information for the specified IRDA module.
\r
1293 * @retval HAL status
\r
1295 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
\r
1297 /* Disable the IRDA Transmit Complete Interrupt */
\r
1298 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TC);
\r
1300 /* Check if a receive process is ongoing or not */
\r
1301 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1303 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
1307 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
1308 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1310 hirda->State = HAL_IRDA_STATE_READY;
\r
1313 HAL_IRDA_TxCpltCallback(hirda);
\r
1319 * @brief Receive an amount of data in non blocking mode.
\r
1320 * Function called under interruption only, once
\r
1321 * interruptions have been enabled by HAL_IRDA_Receive_IT()
\r
1322 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1323 * the configuration information for the specified IRDA module.
\r
1324 * @retval HAL status
\r
1326 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
\r
1329 uint16_t uhMask = hirda->Mask;
\r
1331 if ((hirda->State == HAL_IRDA_STATE_BUSY_RX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
\r
1333 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
1335 tmp = (uint16_t*) hirda->pRxBuffPtr ;
\r
1336 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
\r
1337 hirda->pRxBuffPtr +=2;
\r
1341 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
\r
1344 if(--hirda->RxXferCount == 0)
\r
1346 while(HAL_IS_BIT_SET(hirda->Instance->ISR, IRDA_FLAG_RXNE))
\r
1349 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
\r
1351 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1353 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
1357 /* Disable the IRDA Parity Error Interrupt */
\r
1358 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
\r
1360 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
1361 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1363 hirda->State = HAL_IRDA_STATE_READY;
\r
1366 HAL_IRDA_RxCpltCallback(hirda);
\r
1380 * @brief DMA IRDA Tx transfer completed callback
\r
1381 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
1382 * the configuration information for the specified DMA module.
\r
1385 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
\r
1387 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1389 /* DMA Normal mode*/
\r
1390 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
\r
1392 hirda->TxXferCount = 0;
\r
1394 /* Disable the DMA transfer for transmit request by setting the DMAT bit
\r
1395 in the IRDA CR3 register */
\r
1396 hirda->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAT);
\r
1398 /* Enable the IRDA Transmit Complete Interrupt */
\r
1399 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
\r
1401 /* DMA Circular mode */
\r
1404 HAL_IRDA_TxCpltCallback(hirda);
\r
1409 * @brief DMA IRDA receive process half complete callback
\r
1410 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
1411 * the configuration information for the specified DMA module.
\r
1414 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
\r
1416 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1418 HAL_IRDA_TxHalfCpltCallback(hirda);
\r
1422 * @brief DMA IRDA Rx Transfer completed callback
\r
1423 * @param hdma: DMA handle
\r
1426 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
\r
1428 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1430 /* DMA Normal mode */
\r
1431 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
\r
1433 hirda->RxXferCount = 0;
\r
1435 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
\r
1436 in the IRDA CR3 register */
\r
1437 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR);
\r
1439 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1441 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
1445 hirda->State = HAL_IRDA_STATE_READY;
\r
1449 HAL_IRDA_RxCpltCallback(hirda);
\r
1453 * @brief DMA IRDA receive process half complete callback
\r
1454 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
1455 * the configuration information for the specified DMA module.
\r
1458 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
\r
1460 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1462 HAL_IRDA_RxHalfCpltCallback(hirda);
\r
1466 * @brief DMA IRDA communication error callback
\r
1467 * @param hdma: DMA handle
\r
1470 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
\r
1472 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1473 hirda->RxXferCount = 0;
\r
1474 hirda->TxXferCount = 0;
\r
1475 hirda->State= HAL_IRDA_STATE_READY;
\r
1476 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
\r
1477 HAL_IRDA_ErrorCallback(hirda);
\r
1488 #endif /* HAL_IRDA_MODULE_ENABLED */
\r
1494 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r