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