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