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