mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L053R8/stm32l0xx_hal_irda.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 181:a4cbdfbbd2f4
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 181:a4cbdfbbd2f4 | 1 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 2 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 3 | * @file stm32l0xx_hal_irda.c |
mbed_official | 181:a4cbdfbbd2f4 | 4 | * @author MCD Application Team |
mbed_official | 181:a4cbdfbbd2f4 | 5 | * @version V1.0.0 |
mbed_official | 181:a4cbdfbbd2f4 | 6 | * @date 22-April-2014 |
mbed_official | 181:a4cbdfbbd2f4 | 7 | * @brief IRDA HAL module driver. |
mbed_official | 181:a4cbdfbbd2f4 | 8 | * |
mbed_official | 181:a4cbdfbbd2f4 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 181:a4cbdfbbd2f4 | 10 | * functionalities of the IrDA (Infrared Data Association) Peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 11 | * (IRDA) |
mbed_official | 181:a4cbdfbbd2f4 | 12 | * + Initialization and de-initialization functions |
mbed_official | 181:a4cbdfbbd2f4 | 13 | * + IO operation functions |
mbed_official | 181:a4cbdfbbd2f4 | 14 | * + Peripheral Control functions |
mbed_official | 181:a4cbdfbbd2f4 | 15 | * |
mbed_official | 181:a4cbdfbbd2f4 | 16 | * |
mbed_official | 181:a4cbdfbbd2f4 | 17 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 18 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 19 | ##### How to use this driver ##### |
mbed_official | 181:a4cbdfbbd2f4 | 20 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 21 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 22 | The IRDA HAL driver can be used as follows: |
mbed_official | 181:a4cbdfbbd2f4 | 23 | |
mbed_official | 181:a4cbdfbbd2f4 | 24 | |
mbed_official | 181:a4cbdfbbd2f4 | 25 | (#) Declare a IRDA_HandleTypeDef handle structure. |
mbed_official | 181:a4cbdfbbd2f4 | 26 | (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API: |
mbed_official | 181:a4cbdfbbd2f4 | 27 | (##) Enable the USARTx interface clock. |
mbed_official | 181:a4cbdfbbd2f4 | 28 | (##) IRDA pins configuration: |
mbed_official | 181:a4cbdfbbd2f4 | 29 | (+) Enable the clock for the IRDA GPIOs. |
mbed_official | 181:a4cbdfbbd2f4 | 30 | (+) Configure these IRDA pins as alternate function pull-up. |
mbed_official | 181:a4cbdfbbd2f4 | 31 | (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 32 | and HAL_IRDA_Receive_IT() APIs): |
mbed_official | 181:a4cbdfbbd2f4 | 33 | (+) Configure the USARTx interrupt priority. |
mbed_official | 181:a4cbdfbbd2f4 | 34 | (+) Enable the NVIC USART IRQ handle. |
mbed_official | 181:a4cbdfbbd2f4 | 35 | (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 36 | and HAL_IRDA_Receive_DMA() APIs): |
mbed_official | 181:a4cbdfbbd2f4 | 37 | (+) Declare a DMA handle structure for the Tx/Rx stream. |
mbed_official | 181:a4cbdfbbd2f4 | 38 | (+) Enable the DMAx interface clock. |
mbed_official | 181:a4cbdfbbd2f4 | 39 | (+) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 181:a4cbdfbbd2f4 | 40 | (+) Configure the DMA Tx/Rx Stream. |
mbed_official | 181:a4cbdfbbd2f4 | 41 | (+) Associate the initilalized DMA handle to the IRDA DMA Tx/Rx handle. |
mbed_official | 181:a4cbdfbbd2f4 | 42 | (+) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream. |
mbed_official | 181:a4cbdfbbd2f4 | 43 | |
mbed_official | 181:a4cbdfbbd2f4 | 44 | (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler |
mbed_official | 181:a4cbdfbbd2f4 | 45 | and Mode(Receiver/Transmitter) in the hirda Init structure. |
mbed_official | 181:a4cbdfbbd2f4 | 46 | |
mbed_official | 181:a4cbdfbbd2f4 | 47 | (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API: |
mbed_official | 181:a4cbdfbbd2f4 | 48 | (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) |
mbed_official | 181:a4cbdfbbd2f4 | 49 | by calling the customed HAL_IRDA_MspInit() API. |
mbed_official | 181:a4cbdfbbd2f4 | 50 | -@@- The specific IRDA interrupts (Transmission complete interrupt, |
mbed_official | 181:a4cbdfbbd2f4 | 51 | RXNE interrupt and Error Interrupts) will be managed using the macros |
mbed_official | 181:a4cbdfbbd2f4 | 52 | __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process. |
mbed_official | 181:a4cbdfbbd2f4 | 53 | |
mbed_official | 181:a4cbdfbbd2f4 | 54 | (#) Three operation modes are available within this driver : |
mbed_official | 181:a4cbdfbbd2f4 | 55 | |
mbed_official | 181:a4cbdfbbd2f4 | 56 | *** Polling mode IO operation *** |
mbed_official | 181:a4cbdfbbd2f4 | 57 | ================================= |
mbed_official | 181:a4cbdfbbd2f4 | 58 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 59 | (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit() |
mbed_official | 181:a4cbdfbbd2f4 | 60 | (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive() |
mbed_official | 181:a4cbdfbbd2f4 | 61 | |
mbed_official | 181:a4cbdfbbd2f4 | 62 | *** Interrupt mode IO operation *** |
mbed_official | 181:a4cbdfbbd2f4 | 63 | =================================== |
mbed_official | 181:a4cbdfbbd2f4 | 64 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 65 | (+) Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 66 | (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can |
mbed_official | 181:a4cbdfbbd2f4 | 67 | add his own code by customization of function pointer HAL_IRDA_TxCpltCallback |
mbed_official | 181:a4cbdfbbd2f4 | 68 | (+) Receive an amount of data in non blocking mode using HAL_IRDA_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 69 | (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can |
mbed_official | 181:a4cbdfbbd2f4 | 70 | add his own code by customization of function pointer HAL_IRDA_RxCpltCallback |
mbed_official | 181:a4cbdfbbd2f4 | 71 | (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can |
mbed_official | 181:a4cbdfbbd2f4 | 72 | add his own code by customization of function pointer HAL_IRDA_ErrorCallback |
mbed_official | 181:a4cbdfbbd2f4 | 73 | |
mbed_official | 181:a4cbdfbbd2f4 | 74 | *** DMA mode IO operation *** |
mbed_official | 181:a4cbdfbbd2f4 | 75 | ============================= |
mbed_official | 181:a4cbdfbbd2f4 | 76 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 77 | (+) Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 78 | (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can |
mbed_official | 181:a4cbdfbbd2f4 | 79 | add his own code by customization of function pointer HAL_IRDA_TxCpltCallback |
mbed_official | 181:a4cbdfbbd2f4 | 80 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 81 | (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can |
mbed_official | 181:a4cbdfbbd2f4 | 82 | add his own code by customization of function pointer HAL_IRDA_RxCpltCallback |
mbed_official | 181:a4cbdfbbd2f4 | 83 | (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can |
mbed_official | 181:a4cbdfbbd2f4 | 84 | add his own code by customization of function pointer HAL_IRDA_ErrorCallback |
mbed_official | 181:a4cbdfbbd2f4 | 85 | |
mbed_official | 181:a4cbdfbbd2f4 | 86 | *** IRDA HAL driver macros list *** |
mbed_official | 181:a4cbdfbbd2f4 | 87 | =================================== |
mbed_official | 181:a4cbdfbbd2f4 | 88 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 89 | Below the list of most used macros in IRDA HAL driver. |
mbed_official | 181:a4cbdfbbd2f4 | 90 | |
mbed_official | 181:a4cbdfbbd2f4 | 91 | (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 92 | (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 93 | (+) __HAL_IRDA_GET_FLAG : Checks whether the specified IRDA flag is set or not |
mbed_official | 181:a4cbdfbbd2f4 | 94 | (+) __HAL_IRDA_CLEAR_FLAG : Clears the specified IRDA pending flag |
mbed_official | 181:a4cbdfbbd2f4 | 95 | (+) __HAL_IRDA_ENABLE_IT: Enables the specified IRDA interrupt |
mbed_official | 181:a4cbdfbbd2f4 | 96 | (+) __HAL_IRDA_DISABLE_IT: Disables the specified IRDA interrupt |
mbed_official | 181:a4cbdfbbd2f4 | 97 | |
mbed_official | 181:a4cbdfbbd2f4 | 98 | (@) You can refer to the IRDA HAL driver header file for more useful macros |
mbed_official | 181:a4cbdfbbd2f4 | 99 | |
mbed_official | 181:a4cbdfbbd2f4 | 100 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 101 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 102 | * @attention |
mbed_official | 181:a4cbdfbbd2f4 | 103 | * |
mbed_official | 181:a4cbdfbbd2f4 | 104 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 181:a4cbdfbbd2f4 | 105 | * |
mbed_official | 181:a4cbdfbbd2f4 | 106 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 181:a4cbdfbbd2f4 | 107 | * are permitted provided that the following conditions are met: |
mbed_official | 181:a4cbdfbbd2f4 | 108 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 109 | * this list of conditions and the following disclaimer. |
mbed_official | 181:a4cbdfbbd2f4 | 110 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 111 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 181:a4cbdfbbd2f4 | 112 | * and/or other materials provided with the distribution. |
mbed_official | 181:a4cbdfbbd2f4 | 113 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 181:a4cbdfbbd2f4 | 114 | * may be used to endorse or promote products derived from this software |
mbed_official | 181:a4cbdfbbd2f4 | 115 | * without specific prior written permission. |
mbed_official | 181:a4cbdfbbd2f4 | 116 | * |
mbed_official | 181:a4cbdfbbd2f4 | 117 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 181:a4cbdfbbd2f4 | 118 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 181:a4cbdfbbd2f4 | 119 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 181:a4cbdfbbd2f4 | 120 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 181:a4cbdfbbd2f4 | 121 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 181:a4cbdfbbd2f4 | 122 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 181:a4cbdfbbd2f4 | 123 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 181:a4cbdfbbd2f4 | 124 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 181:a4cbdfbbd2f4 | 125 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 181:a4cbdfbbd2f4 | 126 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 181:a4cbdfbbd2f4 | 127 | * |
mbed_official | 181:a4cbdfbbd2f4 | 128 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 129 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 130 | |
mbed_official | 181:a4cbdfbbd2f4 | 131 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 132 | #include "stm32l0xx_hal.h" |
mbed_official | 181:a4cbdfbbd2f4 | 133 | |
mbed_official | 181:a4cbdfbbd2f4 | 134 | /** @addtogroup STM32L0xx_HAL_Driver |
mbed_official | 181:a4cbdfbbd2f4 | 135 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 136 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 137 | |
mbed_official | 181:a4cbdfbbd2f4 | 138 | /** @defgroup IRDA |
mbed_official | 181:a4cbdfbbd2f4 | 139 | * @brief HAL IRDA module driver |
mbed_official | 181:a4cbdfbbd2f4 | 140 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 141 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 142 | #ifdef HAL_IRDA_MODULE_ENABLED |
mbed_official | 181:a4cbdfbbd2f4 | 143 | |
mbed_official | 181:a4cbdfbbd2f4 | 144 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 145 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 146 | #define TEACK_REACK_TIMEOUT 1000 |
mbed_official | 181:a4cbdfbbd2f4 | 147 | #define HAL_IRDA_TXDMA_TIMEOUTVALUE 22000 |
mbed_official | 181:a4cbdfbbd2f4 | 148 | #define IRDA_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE \ |
mbed_official | 181:a4cbdfbbd2f4 | 149 | | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE)) |
mbed_official | 181:a4cbdfbbd2f4 | 150 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 151 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 152 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 153 | static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 181:a4cbdfbbd2f4 | 154 | static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 181:a4cbdfbbd2f4 | 155 | static void IRDA_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 181:a4cbdfbbd2f4 | 156 | static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 157 | static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 158 | static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout); |
mbed_official | 181:a4cbdfbbd2f4 | 159 | static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 160 | static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 161 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 162 | |
mbed_official | 181:a4cbdfbbd2f4 | 163 | /** @defgroup IRDA_Private_Functions |
mbed_official | 181:a4cbdfbbd2f4 | 164 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 165 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 166 | |
mbed_official | 181:a4cbdfbbd2f4 | 167 | /** @defgroup HAL_IRDA_Group1 Initialization/de-initialization functions |
mbed_official | 181:a4cbdfbbd2f4 | 168 | * @brief Initialization and Configuration functions |
mbed_official | 181:a4cbdfbbd2f4 | 169 | * |
mbed_official | 181:a4cbdfbbd2f4 | 170 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 171 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 172 | ##### Initialization and Configuration functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 173 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 174 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 175 | This subsection provides a set of functions allowing to initialize the USARTx |
mbed_official | 181:a4cbdfbbd2f4 | 176 | in asynchronous IRDA mode. |
mbed_official | 181:a4cbdfbbd2f4 | 177 | (+) For the asynchronous mode only these parameters can be configured: |
mbed_official | 181:a4cbdfbbd2f4 | 178 | (++) Baud Rate |
mbed_official | 181:a4cbdfbbd2f4 | 179 | (++) Word Length |
mbed_official | 181:a4cbdfbbd2f4 | 180 | (++) Parity: If the parity is enabled, then the MSB bit of the data written |
mbed_official | 181:a4cbdfbbd2f4 | 181 | in the data register is transmitted but is changed by the parity bit. |
mbed_official | 181:a4cbdfbbd2f4 | 182 | Depending on the frame length defined by the M bit (8-bits or 9-bits) |
mbed_official | 181:a4cbdfbbd2f4 | 183 | or by the M1 and M0 bits (7-bit, 8-bit or 9-bit), |
mbed_official | 181:a4cbdfbbd2f4 | 184 | the possible IRDA frame formats are as listed in the following table: |
mbed_official | 181:a4cbdfbbd2f4 | 185 | +---------------------------------------------------------------+ |
mbed_official | 181:a4cbdfbbd2f4 | 186 | | M1M0 bits | PCE bit | IRDA frame | |
mbed_official | 181:a4cbdfbbd2f4 | 187 | |-----------|-----------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 188 | | 00 | 0 | | SB | 8-bit data | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 189 | |-----------|-----------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 190 | | 00 | 1 | | SB | 7-bit data | PB | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 191 | |-----------|-----------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 192 | | 01 | 0 | | SB | 9-bit data | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 193 | |-----------|-----------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 194 | | 01 | 1 | | SB | 8-bit data | PB | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 195 | |-----------------------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 196 | | 10 | 0 | | SB | 7-bit data | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 197 | |-----------|-----------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 198 | | 10 | 1 | | SB | 6-bit data | PB | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 199 | +---------------------------------------------------------------+ |
mbed_official | 181:a4cbdfbbd2f4 | 200 | |
mbed_official | 181:a4cbdfbbd2f4 | 201 | (++) Power mode |
mbed_official | 181:a4cbdfbbd2f4 | 202 | (++) Prescaler setting |
mbed_official | 181:a4cbdfbbd2f4 | 203 | (++) Receiver/transmitter modes |
mbed_official | 181:a4cbdfbbd2f4 | 204 | |
mbed_official | 181:a4cbdfbbd2f4 | 205 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 206 | The HAL_IRDA_Init() API follows the USART asynchronous configuration procedures |
mbed_official | 181:a4cbdfbbd2f4 | 207 | (details for the procedures are available in reference manual). |
mbed_official | 181:a4cbdfbbd2f4 | 208 | |
mbed_official | 181:a4cbdfbbd2f4 | 209 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 210 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 211 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 212 | |
mbed_official | 181:a4cbdfbbd2f4 | 213 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 214 | * @brief Initializes the IRDA mode according to the specified |
mbed_official | 181:a4cbdfbbd2f4 | 215 | * parameters in the IRDA_InitTypeDef and creates the associated handle . |
mbed_official | 181:a4cbdfbbd2f4 | 216 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 217 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 218 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 219 | HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 220 | { |
mbed_official | 181:a4cbdfbbd2f4 | 221 | /* Check the IRDA handle allocation */ |
mbed_official | 181:a4cbdfbbd2f4 | 222 | if(hirda == NULL) |
mbed_official | 181:a4cbdfbbd2f4 | 223 | { |
mbed_official | 181:a4cbdfbbd2f4 | 224 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 225 | } |
mbed_official | 181:a4cbdfbbd2f4 | 226 | |
mbed_official | 181:a4cbdfbbd2f4 | 227 | /* Check the USART/UART associated to the IRDA handle */ |
mbed_official | 181:a4cbdfbbd2f4 | 228 | assert_param(IS_IRDA_INSTANCE(hirda->Instance)); |
mbed_official | 181:a4cbdfbbd2f4 | 229 | |
mbed_official | 181:a4cbdfbbd2f4 | 230 | if(hirda->State == HAL_IRDA_STATE_RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 231 | { |
mbed_official | 181:a4cbdfbbd2f4 | 232 | /* Init the low level hardware : GPIO, CLOCK, CORTEX */ |
mbed_official | 181:a4cbdfbbd2f4 | 233 | HAL_IRDA_MspInit(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 234 | } |
mbed_official | 181:a4cbdfbbd2f4 | 235 | |
mbed_official | 181:a4cbdfbbd2f4 | 236 | hirda->State = HAL_IRDA_STATE_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 237 | |
mbed_official | 181:a4cbdfbbd2f4 | 238 | /* Disable the Peripheral to update the configuration registers */ |
mbed_official | 181:a4cbdfbbd2f4 | 239 | __HAL_IRDA_DISABLE(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 240 | |
mbed_official | 181:a4cbdfbbd2f4 | 241 | /* Set the IRDA Communication parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 242 | IRDA_SetConfig(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 243 | |
mbed_official | 181:a4cbdfbbd2f4 | 244 | /* In IRDA mode, the following bits must be kept cleared: |
mbed_official | 181:a4cbdfbbd2f4 | 245 | - LINEN, STOP and CLKEN bits in the USART_CR2 register, |
mbed_official | 181:a4cbdfbbd2f4 | 246 | - SCEN and HDSEL bits in the USART_CR3 register.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 247 | hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP); |
mbed_official | 181:a4cbdfbbd2f4 | 248 | hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL); |
mbed_official | 181:a4cbdfbbd2f4 | 249 | |
mbed_official | 181:a4cbdfbbd2f4 | 250 | /* set the UART/USART in IRDA mode */ |
mbed_official | 181:a4cbdfbbd2f4 | 251 | hirda->Instance->CR3 |= USART_CR3_IREN; |
mbed_official | 181:a4cbdfbbd2f4 | 252 | |
mbed_official | 181:a4cbdfbbd2f4 | 253 | /* Enable the Peripheral */ |
mbed_official | 181:a4cbdfbbd2f4 | 254 | __HAL_IRDA_ENABLE(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 255 | |
mbed_official | 181:a4cbdfbbd2f4 | 256 | /* TEACK and/or REACK to check before moving hirda->State to Ready */ |
mbed_official | 181:a4cbdfbbd2f4 | 257 | return (IRDA_CheckIdleState(hirda)); |
mbed_official | 181:a4cbdfbbd2f4 | 258 | } |
mbed_official | 181:a4cbdfbbd2f4 | 259 | |
mbed_official | 181:a4cbdfbbd2f4 | 260 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 261 | * @brief DeInitializes the IRDA peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 262 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 263 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 264 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 265 | HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 266 | { |
mbed_official | 181:a4cbdfbbd2f4 | 267 | /* Check the IRDA handle allocation */ |
mbed_official | 181:a4cbdfbbd2f4 | 268 | if(hirda == NULL) |
mbed_official | 181:a4cbdfbbd2f4 | 269 | { |
mbed_official | 181:a4cbdfbbd2f4 | 270 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 271 | } |
mbed_official | 181:a4cbdfbbd2f4 | 272 | |
mbed_official | 181:a4cbdfbbd2f4 | 273 | /* Check the USART/UART associated to the IRDA handle */ |
mbed_official | 181:a4cbdfbbd2f4 | 274 | assert_param(IS_IRDA_INSTANCE(hirda->Instance)); |
mbed_official | 181:a4cbdfbbd2f4 | 275 | |
mbed_official | 181:a4cbdfbbd2f4 | 276 | hirda->State = HAL_IRDA_STATE_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 277 | |
mbed_official | 181:a4cbdfbbd2f4 | 278 | /* DeInit the low level hardware */ |
mbed_official | 181:a4cbdfbbd2f4 | 279 | HAL_IRDA_MspDeInit(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 280 | /* Disable the Peripheral */ |
mbed_official | 181:a4cbdfbbd2f4 | 281 | __HAL_IRDA_DISABLE(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 282 | |
mbed_official | 181:a4cbdfbbd2f4 | 283 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 284 | hirda->State = HAL_IRDA_STATE_RESET; |
mbed_official | 181:a4cbdfbbd2f4 | 285 | |
mbed_official | 181:a4cbdfbbd2f4 | 286 | /* Release Lock */ |
mbed_official | 181:a4cbdfbbd2f4 | 287 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 288 | |
mbed_official | 181:a4cbdfbbd2f4 | 289 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 290 | } |
mbed_official | 181:a4cbdfbbd2f4 | 291 | |
mbed_official | 181:a4cbdfbbd2f4 | 292 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 293 | * @brief IRDA MSP Init |
mbed_official | 181:a4cbdfbbd2f4 | 294 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 295 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 296 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 297 | __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 298 | { |
mbed_official | 181:a4cbdfbbd2f4 | 299 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 300 | the HAL_IRDA_MspInit could be implented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 301 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 302 | } |
mbed_official | 181:a4cbdfbbd2f4 | 303 | |
mbed_official | 181:a4cbdfbbd2f4 | 304 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 305 | * @brief IRDA MSP DeInit |
mbed_official | 181:a4cbdfbbd2f4 | 306 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 307 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 308 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 309 | __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 310 | { |
mbed_official | 181:a4cbdfbbd2f4 | 311 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 312 | the HAL_IRDA_MspDeInit could be implented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 313 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 314 | } |
mbed_official | 181:a4cbdfbbd2f4 | 315 | |
mbed_official | 181:a4cbdfbbd2f4 | 316 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 317 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 318 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 319 | |
mbed_official | 181:a4cbdfbbd2f4 | 320 | /** @defgroup HAL_IRDA_Group2 IO operation functions |
mbed_official | 181:a4cbdfbbd2f4 | 321 | * @brief IRDA Transmit/Receive functions |
mbed_official | 181:a4cbdfbbd2f4 | 322 | * |
mbed_official | 181:a4cbdfbbd2f4 | 323 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 324 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 325 | ##### I/O operation functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 326 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 327 | This subsection provides a set of functions allowing to manage the IRDA asynchronous |
mbed_official | 181:a4cbdfbbd2f4 | 328 | data transfers. |
mbed_official | 181:a4cbdfbbd2f4 | 329 | |
mbed_official | 181:a4cbdfbbd2f4 | 330 | (#) There are two modes of transfer: |
mbed_official | 181:a4cbdfbbd2f4 | 331 | (+) Blocking mode: the communication is performed in polling mode. |
mbed_official | 181:a4cbdfbbd2f4 | 332 | The HAL status of all data processing is returned by the same function |
mbed_official | 181:a4cbdfbbd2f4 | 333 | after finishing transfer. |
mbed_official | 181:a4cbdfbbd2f4 | 334 | (+) No-Blocking mode: the communication is performed using Interrupts |
mbed_official | 181:a4cbdfbbd2f4 | 335 | or DMA, these API's return the HAL status. |
mbed_official | 181:a4cbdfbbd2f4 | 336 | The end of the data processing will be indicated through the |
mbed_official | 181:a4cbdfbbd2f4 | 337 | dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 181:a4cbdfbbd2f4 | 338 | using DMA mode. |
mbed_official | 181:a4cbdfbbd2f4 | 339 | The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks |
mbed_official | 181:a4cbdfbbd2f4 | 340 | will be executed respectivelly at the end of the Transmit or Receive process |
mbed_official | 181:a4cbdfbbd2f4 | 341 | The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected |
mbed_official | 181:a4cbdfbbd2f4 | 342 | |
mbed_official | 181:a4cbdfbbd2f4 | 343 | (#) Blocking mode API's are : |
mbed_official | 181:a4cbdfbbd2f4 | 344 | (+) HAL_IRDA_Transmit() |
mbed_official | 181:a4cbdfbbd2f4 | 345 | (+) HAL_IRDA_Receive() |
mbed_official | 181:a4cbdfbbd2f4 | 346 | |
mbed_official | 181:a4cbdfbbd2f4 | 347 | (#) Non-Blocking mode API's with Interrupt are : |
mbed_official | 181:a4cbdfbbd2f4 | 348 | (+) HAL_IRDA_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 349 | (+) HAL_IRDA_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 350 | (+) HAL_IRDA_IRQHandler() |
mbed_official | 181:a4cbdfbbd2f4 | 351 | (+) IRDA_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 352 | (+) IRDA_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 353 | |
mbed_official | 181:a4cbdfbbd2f4 | 354 | (#) Non-Blocking mode functions with DMA are : |
mbed_official | 181:a4cbdfbbd2f4 | 355 | (+) HAL_IRDA_Transmit_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 356 | (+) HAL_IRDA_Receive_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 357 | |
mbed_official | 181:a4cbdfbbd2f4 | 358 | (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode: |
mbed_official | 181:a4cbdfbbd2f4 | 359 | (+) HAL_IRDA_TxCpltCallback() |
mbed_official | 181:a4cbdfbbd2f4 | 360 | (+) HAL_IRDA_RxCpltCallback() |
mbed_official | 181:a4cbdfbbd2f4 | 361 | (+) HAL_IRDA_ErrorCallback() |
mbed_official | 181:a4cbdfbbd2f4 | 362 | |
mbed_official | 181:a4cbdfbbd2f4 | 363 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 364 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 365 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 366 | |
mbed_official | 181:a4cbdfbbd2f4 | 367 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 368 | * @brief Send an amount of data in blocking mode |
mbed_official | 181:a4cbdfbbd2f4 | 369 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 370 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 371 | * @param Size: amount of data to be sent |
mbed_official | 181:a4cbdfbbd2f4 | 372 | * @param Timeout: Duration of the timeout |
mbed_official | 181:a4cbdfbbd2f4 | 373 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 374 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 375 | HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 376 | { |
mbed_official | 181:a4cbdfbbd2f4 | 377 | uint16_t* tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 378 | |
mbed_official | 181:a4cbdfbbd2f4 | 379 | if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 380 | { |
mbed_official | 181:a4cbdfbbd2f4 | 381 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 382 | { |
mbed_official | 181:a4cbdfbbd2f4 | 383 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 384 | } |
mbed_official | 181:a4cbdfbbd2f4 | 385 | |
mbed_official | 181:a4cbdfbbd2f4 | 386 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 387 | __HAL_LOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 388 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 389 | |
mbed_official | 181:a4cbdfbbd2f4 | 390 | if(hirda->State == HAL_IRDA_STATE_BUSY_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 391 | { |
mbed_official | 181:a4cbdfbbd2f4 | 392 | hirda->State = HAL_IRDA_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 393 | } |
mbed_official | 181:a4cbdfbbd2f4 | 394 | else |
mbed_official | 181:a4cbdfbbd2f4 | 395 | { |
mbed_official | 181:a4cbdfbbd2f4 | 396 | hirda->State = HAL_IRDA_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 397 | } |
mbed_official | 181:a4cbdfbbd2f4 | 398 | |
mbed_official | 181:a4cbdfbbd2f4 | 399 | hirda->TxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 400 | hirda->TxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 401 | while(hirda->TxXferCount > 0) |
mbed_official | 181:a4cbdfbbd2f4 | 402 | { |
mbed_official | 181:a4cbdfbbd2f4 | 403 | hirda->TxXferCount--; |
mbed_official | 181:a4cbdfbbd2f4 | 404 | |
mbed_official | 181:a4cbdfbbd2f4 | 405 | if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 406 | { |
mbed_official | 181:a4cbdfbbd2f4 | 407 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 408 | } |
mbed_official | 181:a4cbdfbbd2f4 | 409 | if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE)) |
mbed_official | 181:a4cbdfbbd2f4 | 410 | { |
mbed_official | 181:a4cbdfbbd2f4 | 411 | tmp = (uint16_t*) pData; |
mbed_official | 181:a4cbdfbbd2f4 | 412 | hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF); |
mbed_official | 181:a4cbdfbbd2f4 | 413 | pData +=2; |
mbed_official | 181:a4cbdfbbd2f4 | 414 | } |
mbed_official | 181:a4cbdfbbd2f4 | 415 | else |
mbed_official | 181:a4cbdfbbd2f4 | 416 | { |
mbed_official | 181:a4cbdfbbd2f4 | 417 | hirda->Instance->TDR = (*pData++ & (uint8_t)0xFF); |
mbed_official | 181:a4cbdfbbd2f4 | 418 | } |
mbed_official | 181:a4cbdfbbd2f4 | 419 | } |
mbed_official | 181:a4cbdfbbd2f4 | 420 | |
mbed_official | 181:a4cbdfbbd2f4 | 421 | if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 422 | { |
mbed_official | 181:a4cbdfbbd2f4 | 423 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 424 | } |
mbed_official | 181:a4cbdfbbd2f4 | 425 | |
mbed_official | 181:a4cbdfbbd2f4 | 426 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 427 | { |
mbed_official | 181:a4cbdfbbd2f4 | 428 | hirda->State = HAL_IRDA_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 429 | } |
mbed_official | 181:a4cbdfbbd2f4 | 430 | else |
mbed_official | 181:a4cbdfbbd2f4 | 431 | { |
mbed_official | 181:a4cbdfbbd2f4 | 432 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 433 | } |
mbed_official | 181:a4cbdfbbd2f4 | 434 | |
mbed_official | 181:a4cbdfbbd2f4 | 435 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 436 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 437 | |
mbed_official | 181:a4cbdfbbd2f4 | 438 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 439 | } |
mbed_official | 181:a4cbdfbbd2f4 | 440 | else |
mbed_official | 181:a4cbdfbbd2f4 | 441 | { |
mbed_official | 181:a4cbdfbbd2f4 | 442 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 443 | } |
mbed_official | 181:a4cbdfbbd2f4 | 444 | } |
mbed_official | 181:a4cbdfbbd2f4 | 445 | |
mbed_official | 181:a4cbdfbbd2f4 | 446 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 447 | * @brief Receive an amount of data in blocking mode |
mbed_official | 181:a4cbdfbbd2f4 | 448 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 449 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 450 | * @param Size: amount of data to be received |
mbed_official | 181:a4cbdfbbd2f4 | 451 | * @param Timeout: Duration of the timeout |
mbed_official | 181:a4cbdfbbd2f4 | 452 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 453 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 454 | HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 455 | { |
mbed_official | 181:a4cbdfbbd2f4 | 456 | uint16_t* tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 457 | uint16_t uhMask; |
mbed_official | 181:a4cbdfbbd2f4 | 458 | |
mbed_official | 181:a4cbdfbbd2f4 | 459 | if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX)) |
mbed_official | 181:a4cbdfbbd2f4 | 460 | { |
mbed_official | 181:a4cbdfbbd2f4 | 461 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 462 | { |
mbed_official | 181:a4cbdfbbd2f4 | 463 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 464 | } |
mbed_official | 181:a4cbdfbbd2f4 | 465 | |
mbed_official | 181:a4cbdfbbd2f4 | 466 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 467 | __HAL_LOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 468 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 469 | |
mbed_official | 181:a4cbdfbbd2f4 | 470 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX) |
mbed_official | 181:a4cbdfbbd2f4 | 471 | { |
mbed_official | 181:a4cbdfbbd2f4 | 472 | hirda->State = HAL_IRDA_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 473 | } |
mbed_official | 181:a4cbdfbbd2f4 | 474 | else |
mbed_official | 181:a4cbdfbbd2f4 | 475 | { |
mbed_official | 181:a4cbdfbbd2f4 | 476 | hirda->State = HAL_IRDA_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 477 | } |
mbed_official | 181:a4cbdfbbd2f4 | 478 | |
mbed_official | 181:a4cbdfbbd2f4 | 479 | hirda->RxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 480 | hirda->RxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 481 | |
mbed_official | 181:a4cbdfbbd2f4 | 482 | /* Computation of the mask to apply to the RDR register |
mbed_official | 181:a4cbdfbbd2f4 | 483 | of the UART associated to the IRDA */ |
mbed_official | 181:a4cbdfbbd2f4 | 484 | __HAL_IRDA_MASK_COMPUTATION(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 485 | uhMask = hirda->Mask; |
mbed_official | 181:a4cbdfbbd2f4 | 486 | |
mbed_official | 181:a4cbdfbbd2f4 | 487 | /* Check data remaining to be received */ |
mbed_official | 181:a4cbdfbbd2f4 | 488 | while(hirda->RxXferCount > 0) |
mbed_official | 181:a4cbdfbbd2f4 | 489 | { |
mbed_official | 181:a4cbdfbbd2f4 | 490 | hirda->RxXferCount--; |
mbed_official | 181:a4cbdfbbd2f4 | 491 | |
mbed_official | 181:a4cbdfbbd2f4 | 492 | if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 493 | { |
mbed_official | 181:a4cbdfbbd2f4 | 494 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 495 | } |
mbed_official | 181:a4cbdfbbd2f4 | 496 | if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE)) |
mbed_official | 181:a4cbdfbbd2f4 | 497 | { |
mbed_official | 181:a4cbdfbbd2f4 | 498 | tmp = (uint16_t*) pData ; |
mbed_official | 181:a4cbdfbbd2f4 | 499 | *tmp = (uint16_t)(hirda->Instance->RDR & uhMask); |
mbed_official | 181:a4cbdfbbd2f4 | 500 | pData +=2; |
mbed_official | 181:a4cbdfbbd2f4 | 501 | } |
mbed_official | 181:a4cbdfbbd2f4 | 502 | else |
mbed_official | 181:a4cbdfbbd2f4 | 503 | { |
mbed_official | 181:a4cbdfbbd2f4 | 504 | *pData++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask); |
mbed_official | 181:a4cbdfbbd2f4 | 505 | } |
mbed_official | 181:a4cbdfbbd2f4 | 506 | } |
mbed_official | 181:a4cbdfbbd2f4 | 507 | |
mbed_official | 181:a4cbdfbbd2f4 | 508 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 509 | { |
mbed_official | 181:a4cbdfbbd2f4 | 510 | hirda->State = HAL_IRDA_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 511 | } |
mbed_official | 181:a4cbdfbbd2f4 | 512 | else |
mbed_official | 181:a4cbdfbbd2f4 | 513 | { |
mbed_official | 181:a4cbdfbbd2f4 | 514 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 515 | } |
mbed_official | 181:a4cbdfbbd2f4 | 516 | |
mbed_official | 181:a4cbdfbbd2f4 | 517 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 518 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 519 | |
mbed_official | 181:a4cbdfbbd2f4 | 520 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 521 | } |
mbed_official | 181:a4cbdfbbd2f4 | 522 | else |
mbed_official | 181:a4cbdfbbd2f4 | 523 | { |
mbed_official | 181:a4cbdfbbd2f4 | 524 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 525 | } |
mbed_official | 181:a4cbdfbbd2f4 | 526 | } |
mbed_official | 181:a4cbdfbbd2f4 | 527 | |
mbed_official | 181:a4cbdfbbd2f4 | 528 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 529 | * @brief Send an amount of data in interrupt mode |
mbed_official | 181:a4cbdfbbd2f4 | 530 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 531 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 532 | * @param Size: amount of data to be sent |
mbed_official | 181:a4cbdfbbd2f4 | 533 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 534 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 535 | HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 536 | { |
mbed_official | 181:a4cbdfbbd2f4 | 537 | if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 538 | { |
mbed_official | 181:a4cbdfbbd2f4 | 539 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 540 | { |
mbed_official | 181:a4cbdfbbd2f4 | 541 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 542 | } |
mbed_official | 181:a4cbdfbbd2f4 | 543 | |
mbed_official | 181:a4cbdfbbd2f4 | 544 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 545 | __HAL_LOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 546 | |
mbed_official | 181:a4cbdfbbd2f4 | 547 | hirda->pTxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 548 | hirda->TxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 549 | hirda->TxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 550 | |
mbed_official | 181:a4cbdfbbd2f4 | 551 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 552 | if(hirda->State == HAL_IRDA_STATE_BUSY_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 553 | { |
mbed_official | 181:a4cbdfbbd2f4 | 554 | hirda->State = HAL_IRDA_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 555 | } |
mbed_official | 181:a4cbdfbbd2f4 | 556 | else |
mbed_official | 181:a4cbdfbbd2f4 | 557 | { |
mbed_official | 181:a4cbdfbbd2f4 | 558 | hirda->State = HAL_IRDA_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 559 | } |
mbed_official | 181:a4cbdfbbd2f4 | 560 | |
mbed_official | 181:a4cbdfbbd2f4 | 561 | /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 562 | __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 563 | |
mbed_official | 181:a4cbdfbbd2f4 | 564 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 565 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 566 | |
mbed_official | 181:a4cbdfbbd2f4 | 567 | /* Enable the IRDA Transmit Complete Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 568 | __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC); |
mbed_official | 181:a4cbdfbbd2f4 | 569 | |
mbed_official | 181:a4cbdfbbd2f4 | 570 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 571 | } |
mbed_official | 181:a4cbdfbbd2f4 | 572 | else |
mbed_official | 181:a4cbdfbbd2f4 | 573 | { |
mbed_official | 181:a4cbdfbbd2f4 | 574 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 575 | } |
mbed_official | 181:a4cbdfbbd2f4 | 576 | } |
mbed_official | 181:a4cbdfbbd2f4 | 577 | |
mbed_official | 181:a4cbdfbbd2f4 | 578 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 579 | * @brief Receive an amount of data in interrupt mode |
mbed_official | 181:a4cbdfbbd2f4 | 580 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 581 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 582 | * @param Size: amount of data to be received |
mbed_official | 181:a4cbdfbbd2f4 | 583 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 584 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 585 | HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 586 | { |
mbed_official | 181:a4cbdfbbd2f4 | 587 | if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX)) |
mbed_official | 181:a4cbdfbbd2f4 | 588 | { |
mbed_official | 181:a4cbdfbbd2f4 | 589 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 590 | { |
mbed_official | 181:a4cbdfbbd2f4 | 591 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 592 | } |
mbed_official | 181:a4cbdfbbd2f4 | 593 | |
mbed_official | 181:a4cbdfbbd2f4 | 594 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 595 | __HAL_LOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 596 | |
mbed_official | 181:a4cbdfbbd2f4 | 597 | hirda->pRxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 598 | hirda->RxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 599 | hirda->RxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 600 | |
mbed_official | 181:a4cbdfbbd2f4 | 601 | /* Computation of the mask to apply to the RDR register |
mbed_official | 181:a4cbdfbbd2f4 | 602 | of the UART associated to the IRDA */ |
mbed_official | 181:a4cbdfbbd2f4 | 603 | __HAL_IRDA_MASK_COMPUTATION(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 604 | |
mbed_official | 181:a4cbdfbbd2f4 | 605 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 606 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX) |
mbed_official | 181:a4cbdfbbd2f4 | 607 | { |
mbed_official | 181:a4cbdfbbd2f4 | 608 | hirda->State = HAL_IRDA_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 609 | } |
mbed_official | 181:a4cbdfbbd2f4 | 610 | else |
mbed_official | 181:a4cbdfbbd2f4 | 611 | { |
mbed_official | 181:a4cbdfbbd2f4 | 612 | hirda->State = HAL_IRDA_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 613 | } |
mbed_official | 181:a4cbdfbbd2f4 | 614 | |
mbed_official | 181:a4cbdfbbd2f4 | 615 | /* Enable the IRDA Parity Error Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 616 | __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 617 | |
mbed_official | 181:a4cbdfbbd2f4 | 618 | /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 619 | __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 620 | |
mbed_official | 181:a4cbdfbbd2f4 | 621 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 622 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 623 | |
mbed_official | 181:a4cbdfbbd2f4 | 624 | /* Enable the IRDA Data Register not empty Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 625 | __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 626 | |
mbed_official | 181:a4cbdfbbd2f4 | 627 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 628 | } |
mbed_official | 181:a4cbdfbbd2f4 | 629 | else |
mbed_official | 181:a4cbdfbbd2f4 | 630 | { |
mbed_official | 181:a4cbdfbbd2f4 | 631 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 632 | } |
mbed_official | 181:a4cbdfbbd2f4 | 633 | } |
mbed_official | 181:a4cbdfbbd2f4 | 634 | |
mbed_official | 181:a4cbdfbbd2f4 | 635 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 636 | * @brief Send an amount of data in DMA mode |
mbed_official | 181:a4cbdfbbd2f4 | 637 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 638 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 639 | * @param Size: amount of data to be sent |
mbed_official | 181:a4cbdfbbd2f4 | 640 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 641 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 642 | HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 643 | { |
mbed_official | 181:a4cbdfbbd2f4 | 644 | uint32_t *tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 645 | |
mbed_official | 181:a4cbdfbbd2f4 | 646 | if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 647 | { |
mbed_official | 181:a4cbdfbbd2f4 | 648 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 649 | { |
mbed_official | 181:a4cbdfbbd2f4 | 650 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 651 | } |
mbed_official | 181:a4cbdfbbd2f4 | 652 | |
mbed_official | 181:a4cbdfbbd2f4 | 653 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 654 | __HAL_LOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 655 | |
mbed_official | 181:a4cbdfbbd2f4 | 656 | hirda->pTxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 657 | hirda->TxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 658 | hirda->TxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 659 | |
mbed_official | 181:a4cbdfbbd2f4 | 660 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 661 | |
mbed_official | 181:a4cbdfbbd2f4 | 662 | if(hirda->State == HAL_IRDA_STATE_BUSY_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 663 | { |
mbed_official | 181:a4cbdfbbd2f4 | 664 | hirda->State = HAL_IRDA_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 665 | } |
mbed_official | 181:a4cbdfbbd2f4 | 666 | else |
mbed_official | 181:a4cbdfbbd2f4 | 667 | { |
mbed_official | 181:a4cbdfbbd2f4 | 668 | hirda->State = HAL_IRDA_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 669 | } |
mbed_official | 181:a4cbdfbbd2f4 | 670 | |
mbed_official | 181:a4cbdfbbd2f4 | 671 | /* Set the IRDA DMA transfert complete callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 672 | hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt; |
mbed_official | 181:a4cbdfbbd2f4 | 673 | |
mbed_official | 181:a4cbdfbbd2f4 | 674 | /* Set the DMA error callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 675 | hirda->hdmatx->XferErrorCallback = IRDA_DMAError; |
mbed_official | 181:a4cbdfbbd2f4 | 676 | |
mbed_official | 181:a4cbdfbbd2f4 | 677 | /* Enable the IRDA transmit DMA Stream */ |
mbed_official | 181:a4cbdfbbd2f4 | 678 | tmp = (uint32_t*)&pData; |
mbed_official | 181:a4cbdfbbd2f4 | 679 | HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->TDR, Size); |
mbed_official | 181:a4cbdfbbd2f4 | 680 | |
mbed_official | 181:a4cbdfbbd2f4 | 681 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
mbed_official | 181:a4cbdfbbd2f4 | 682 | in the IRDA CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 683 | hirda->Instance->CR3 |= USART_CR3_DMAT; |
mbed_official | 181:a4cbdfbbd2f4 | 684 | |
mbed_official | 181:a4cbdfbbd2f4 | 685 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 686 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 687 | |
mbed_official | 181:a4cbdfbbd2f4 | 688 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 689 | } |
mbed_official | 181:a4cbdfbbd2f4 | 690 | else |
mbed_official | 181:a4cbdfbbd2f4 | 691 | { |
mbed_official | 181:a4cbdfbbd2f4 | 692 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 693 | } |
mbed_official | 181:a4cbdfbbd2f4 | 694 | } |
mbed_official | 181:a4cbdfbbd2f4 | 695 | |
mbed_official | 181:a4cbdfbbd2f4 | 696 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 697 | * @brief Receive an amount of data in DMA mode |
mbed_official | 181:a4cbdfbbd2f4 | 698 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 699 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 700 | * @param Size: amount of data to be received |
mbed_official | 181:a4cbdfbbd2f4 | 701 | * @note When the IRDA parity is enabled (PCE = 1), the received data contain |
mbed_official | 181:a4cbdfbbd2f4 | 702 | * the parity bit (MSB position) |
mbed_official | 181:a4cbdfbbd2f4 | 703 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 704 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 705 | HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 706 | { |
mbed_official | 181:a4cbdfbbd2f4 | 707 | uint32_t *tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 708 | |
mbed_official | 181:a4cbdfbbd2f4 | 709 | if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX)) |
mbed_official | 181:a4cbdfbbd2f4 | 710 | { |
mbed_official | 181:a4cbdfbbd2f4 | 711 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 712 | { |
mbed_official | 181:a4cbdfbbd2f4 | 713 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 714 | } |
mbed_official | 181:a4cbdfbbd2f4 | 715 | |
mbed_official | 181:a4cbdfbbd2f4 | 716 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 717 | __HAL_LOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 718 | |
mbed_official | 181:a4cbdfbbd2f4 | 719 | hirda->pRxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 720 | hirda->RxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 721 | |
mbed_official | 181:a4cbdfbbd2f4 | 722 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 723 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX) |
mbed_official | 181:a4cbdfbbd2f4 | 724 | { |
mbed_official | 181:a4cbdfbbd2f4 | 725 | hirda->State = HAL_IRDA_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 726 | } |
mbed_official | 181:a4cbdfbbd2f4 | 727 | else |
mbed_official | 181:a4cbdfbbd2f4 | 728 | { |
mbed_official | 181:a4cbdfbbd2f4 | 729 | hirda->State = HAL_IRDA_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 730 | } |
mbed_official | 181:a4cbdfbbd2f4 | 731 | |
mbed_official | 181:a4cbdfbbd2f4 | 732 | /* Set the IRDA DMA transfert complete callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 733 | hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt; |
mbed_official | 181:a4cbdfbbd2f4 | 734 | |
mbed_official | 181:a4cbdfbbd2f4 | 735 | /* Set the DMA error callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 736 | hirda->hdmarx->XferErrorCallback = IRDA_DMAError; |
mbed_official | 181:a4cbdfbbd2f4 | 737 | |
mbed_official | 181:a4cbdfbbd2f4 | 738 | /* Enable the DMA Stream */ |
mbed_official | 181:a4cbdfbbd2f4 | 739 | tmp = (uint32_t*)&pData; |
mbed_official | 181:a4cbdfbbd2f4 | 740 | HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->RDR, *(uint32_t*)tmp, Size); |
mbed_official | 181:a4cbdfbbd2f4 | 741 | |
mbed_official | 181:a4cbdfbbd2f4 | 742 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
mbed_official | 181:a4cbdfbbd2f4 | 743 | in the IRDA CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 744 | hirda->Instance->CR3 |= USART_CR3_DMAR; |
mbed_official | 181:a4cbdfbbd2f4 | 745 | |
mbed_official | 181:a4cbdfbbd2f4 | 746 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 747 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 748 | |
mbed_official | 181:a4cbdfbbd2f4 | 749 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 750 | } |
mbed_official | 181:a4cbdfbbd2f4 | 751 | else |
mbed_official | 181:a4cbdfbbd2f4 | 752 | { |
mbed_official | 181:a4cbdfbbd2f4 | 753 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 754 | } |
mbed_official | 181:a4cbdfbbd2f4 | 755 | } |
mbed_official | 181:a4cbdfbbd2f4 | 756 | |
mbed_official | 181:a4cbdfbbd2f4 | 757 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 758 | * @brief This function handles IRDA interrupt request. |
mbed_official | 181:a4cbdfbbd2f4 | 759 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 760 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 761 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 762 | void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 763 | { |
mbed_official | 181:a4cbdfbbd2f4 | 764 | /* IRDA parity error interrupt occurred -------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 765 | if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_PE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 766 | { |
mbed_official | 181:a4cbdfbbd2f4 | 767 | __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_PEF); |
mbed_official | 181:a4cbdfbbd2f4 | 768 | |
mbed_official | 181:a4cbdfbbd2f4 | 769 | hirda->ErrorCode |= HAL_IRDA_ERROR_PE; |
mbed_official | 181:a4cbdfbbd2f4 | 770 | /* Set the IRDA state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 771 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 772 | } |
mbed_official | 181:a4cbdfbbd2f4 | 773 | |
mbed_official | 181:a4cbdfbbd2f4 | 774 | /* IRDA frame error interrupt occured --------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 775 | if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_FE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 776 | { |
mbed_official | 181:a4cbdfbbd2f4 | 777 | __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_FEF); |
mbed_official | 181:a4cbdfbbd2f4 | 778 | |
mbed_official | 181:a4cbdfbbd2f4 | 779 | hirda->ErrorCode |= HAL_IRDA_ERROR_FE; |
mbed_official | 181:a4cbdfbbd2f4 | 780 | /* Set the IRDA state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 781 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 782 | } |
mbed_official | 181:a4cbdfbbd2f4 | 783 | |
mbed_official | 181:a4cbdfbbd2f4 | 784 | /* IRDA noise error interrupt occured --------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 785 | if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_NE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 786 | { |
mbed_official | 181:a4cbdfbbd2f4 | 787 | __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_NEF); |
mbed_official | 181:a4cbdfbbd2f4 | 788 | |
mbed_official | 181:a4cbdfbbd2f4 | 789 | hirda->ErrorCode |= HAL_IRDA_ERROR_NE; |
mbed_official | 181:a4cbdfbbd2f4 | 790 | /* Set the IRDA state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 791 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 792 | } |
mbed_official | 181:a4cbdfbbd2f4 | 793 | |
mbed_official | 181:a4cbdfbbd2f4 | 794 | /* IRDA Over-Run interrupt occured -----------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 795 | if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_ORE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 796 | { |
mbed_official | 181:a4cbdfbbd2f4 | 797 | __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF); |
mbed_official | 181:a4cbdfbbd2f4 | 798 | |
mbed_official | 181:a4cbdfbbd2f4 | 799 | hirda->ErrorCode |= HAL_IRDA_ERROR_ORE; |
mbed_official | 181:a4cbdfbbd2f4 | 800 | /* Set the IRDA state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 801 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 802 | } |
mbed_official | 181:a4cbdfbbd2f4 | 803 | |
mbed_official | 181:a4cbdfbbd2f4 | 804 | /* Call IRDA Error Call back function if need be --------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 805 | if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE) |
mbed_official | 181:a4cbdfbbd2f4 | 806 | { |
mbed_official | 181:a4cbdfbbd2f4 | 807 | HAL_IRDA_ErrorCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 808 | } |
mbed_official | 181:a4cbdfbbd2f4 | 809 | |
mbed_official | 181:a4cbdfbbd2f4 | 810 | /* IRDA in mode Receiver ---------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 811 | if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_RXNE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 812 | { |
mbed_official | 181:a4cbdfbbd2f4 | 813 | IRDA_Receive_IT(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 814 | /* Clear RXNE interrupt flag */ |
mbed_official | 181:a4cbdfbbd2f4 | 815 | __HAL_IRDA_SEND_REQ(hirda, IRDA_RXDATA_FLUSH_REQUEST); |
mbed_official | 181:a4cbdfbbd2f4 | 816 | } |
mbed_official | 181:a4cbdfbbd2f4 | 817 | |
mbed_official | 181:a4cbdfbbd2f4 | 818 | |
mbed_official | 181:a4cbdfbbd2f4 | 819 | /* IRDA in mode Transmitter ------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 820 | if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TC) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TC) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 821 | { |
mbed_official | 181:a4cbdfbbd2f4 | 822 | IRDA_Transmit_IT(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 823 | } |
mbed_official | 181:a4cbdfbbd2f4 | 824 | |
mbed_official | 181:a4cbdfbbd2f4 | 825 | } |
mbed_official | 181:a4cbdfbbd2f4 | 826 | |
mbed_official | 181:a4cbdfbbd2f4 | 827 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 828 | * @brief DMA IRDA Tx transfer completed callback |
mbed_official | 181:a4cbdfbbd2f4 | 829 | * @param hdma: DMA handle |
mbed_official | 181:a4cbdfbbd2f4 | 830 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 831 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 832 | static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 181:a4cbdfbbd2f4 | 833 | { |
mbed_official | 181:a4cbdfbbd2f4 | 834 | IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 181:a4cbdfbbd2f4 | 835 | hirda->TxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 836 | |
mbed_official | 181:a4cbdfbbd2f4 | 837 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
mbed_official | 181:a4cbdfbbd2f4 | 838 | in the IRDA CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 839 | hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT); |
mbed_official | 181:a4cbdfbbd2f4 | 840 | |
mbed_official | 181:a4cbdfbbd2f4 | 841 | /* Wait for IRDA TC Flag */ |
mbed_official | 181:a4cbdfbbd2f4 | 842 | if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, HAL_IRDA_TXDMA_TIMEOUTVALUE) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 843 | { |
mbed_official | 181:a4cbdfbbd2f4 | 844 | /* Timeout Occured */ |
mbed_official | 181:a4cbdfbbd2f4 | 845 | hirda->State = HAL_IRDA_STATE_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 846 | HAL_IRDA_ErrorCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 847 | } |
mbed_official | 181:a4cbdfbbd2f4 | 848 | else |
mbed_official | 181:a4cbdfbbd2f4 | 849 | { |
mbed_official | 181:a4cbdfbbd2f4 | 850 | /* No Timeout */ |
mbed_official | 181:a4cbdfbbd2f4 | 851 | |
mbed_official | 181:a4cbdfbbd2f4 | 852 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 853 | { |
mbed_official | 181:a4cbdfbbd2f4 | 854 | hirda->State = HAL_IRDA_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 855 | } |
mbed_official | 181:a4cbdfbbd2f4 | 856 | else |
mbed_official | 181:a4cbdfbbd2f4 | 857 | { |
mbed_official | 181:a4cbdfbbd2f4 | 858 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 859 | } |
mbed_official | 181:a4cbdfbbd2f4 | 860 | HAL_IRDA_TxCpltCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 861 | } |
mbed_official | 181:a4cbdfbbd2f4 | 862 | } |
mbed_official | 181:a4cbdfbbd2f4 | 863 | |
mbed_official | 181:a4cbdfbbd2f4 | 864 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 865 | * @brief DMA IRDA Rx Transfer completed callback |
mbed_official | 181:a4cbdfbbd2f4 | 866 | * @param hdma: DMA handle |
mbed_official | 181:a4cbdfbbd2f4 | 867 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 868 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 869 | static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 181:a4cbdfbbd2f4 | 870 | { |
mbed_official | 181:a4cbdfbbd2f4 | 871 | IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 181:a4cbdfbbd2f4 | 872 | hirda->RxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 873 | |
mbed_official | 181:a4cbdfbbd2f4 | 874 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
mbed_official | 181:a4cbdfbbd2f4 | 875 | in the IRDA CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 876 | hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR); |
mbed_official | 181:a4cbdfbbd2f4 | 877 | |
mbed_official | 181:a4cbdfbbd2f4 | 878 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 879 | { |
mbed_official | 181:a4cbdfbbd2f4 | 880 | hirda->State = HAL_IRDA_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 881 | } |
mbed_official | 181:a4cbdfbbd2f4 | 882 | else |
mbed_official | 181:a4cbdfbbd2f4 | 883 | { |
mbed_official | 181:a4cbdfbbd2f4 | 884 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 885 | } |
mbed_official | 181:a4cbdfbbd2f4 | 886 | |
mbed_official | 181:a4cbdfbbd2f4 | 887 | HAL_IRDA_RxCpltCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 888 | } |
mbed_official | 181:a4cbdfbbd2f4 | 889 | |
mbed_official | 181:a4cbdfbbd2f4 | 890 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 891 | * @brief DMA IRDA communication error callback |
mbed_official | 181:a4cbdfbbd2f4 | 892 | * @param hdma: DMA handle |
mbed_official | 181:a4cbdfbbd2f4 | 893 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 894 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 895 | static void IRDA_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 181:a4cbdfbbd2f4 | 896 | { |
mbed_official | 181:a4cbdfbbd2f4 | 897 | IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 181:a4cbdfbbd2f4 | 898 | hirda->RxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 899 | hirda->TxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 900 | hirda->State= HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 901 | hirda->ErrorCode |= HAL_IRDA_ERROR_DMA; |
mbed_official | 181:a4cbdfbbd2f4 | 902 | HAL_IRDA_ErrorCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 903 | } |
mbed_official | 181:a4cbdfbbd2f4 | 904 | |
mbed_official | 181:a4cbdfbbd2f4 | 905 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 906 | * @brief Tx Transfer completed callback |
mbed_official | 181:a4cbdfbbd2f4 | 907 | * @param hirda: irda handle |
mbed_official | 181:a4cbdfbbd2f4 | 908 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 909 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 910 | __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 911 | { |
mbed_official | 181:a4cbdfbbd2f4 | 912 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 913 | the HAL_IRDA_TxCpltCallback can be implemented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 914 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 915 | } |
mbed_official | 181:a4cbdfbbd2f4 | 916 | |
mbed_official | 181:a4cbdfbbd2f4 | 917 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 918 | * @brief Rx Transfer completed callback |
mbed_official | 181:a4cbdfbbd2f4 | 919 | * @param hirda: irda handle |
mbed_official | 181:a4cbdfbbd2f4 | 920 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 921 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 922 | __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 923 | { |
mbed_official | 181:a4cbdfbbd2f4 | 924 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 925 | the HAL_IRDA_TxCpltCallback can be implemented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 926 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 927 | } |
mbed_official | 181:a4cbdfbbd2f4 | 928 | |
mbed_official | 181:a4cbdfbbd2f4 | 929 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 930 | * @brief IRDA error callback |
mbed_official | 181:a4cbdfbbd2f4 | 931 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 932 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 933 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 934 | __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 935 | { |
mbed_official | 181:a4cbdfbbd2f4 | 936 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 937 | the HAL_IRDA_ErrorCallback can be implemented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 938 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 939 | } |
mbed_official | 181:a4cbdfbbd2f4 | 940 | |
mbed_official | 181:a4cbdfbbd2f4 | 941 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 942 | * @brief Receive an amount of data in non blocking mode. |
mbed_official | 181:a4cbdfbbd2f4 | 943 | * Function called under interruption only, once |
mbed_official | 181:a4cbdfbbd2f4 | 944 | * interruptions have been enabled by HAL_IRDA_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 945 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 946 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 947 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 948 | static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 949 | { |
mbed_official | 181:a4cbdfbbd2f4 | 950 | uint16_t* tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 951 | |
mbed_official | 181:a4cbdfbbd2f4 | 952 | if((hirda->State == HAL_IRDA_STATE_BUSY_TX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 953 | { |
mbed_official | 181:a4cbdfbbd2f4 | 954 | if(hirda->TxXferCount == 0) |
mbed_official | 181:a4cbdfbbd2f4 | 955 | { |
mbed_official | 181:a4cbdfbbd2f4 | 956 | /* Disable the IRDA Transmit Complete Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 957 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TC); |
mbed_official | 181:a4cbdfbbd2f4 | 958 | |
mbed_official | 181:a4cbdfbbd2f4 | 959 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 960 | { |
mbed_official | 181:a4cbdfbbd2f4 | 961 | hirda->State = HAL_IRDA_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 962 | } |
mbed_official | 181:a4cbdfbbd2f4 | 963 | else |
mbed_official | 181:a4cbdfbbd2f4 | 964 | { |
mbed_official | 181:a4cbdfbbd2f4 | 965 | /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 966 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 967 | |
mbed_official | 181:a4cbdfbbd2f4 | 968 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 969 | } |
mbed_official | 181:a4cbdfbbd2f4 | 970 | |
mbed_official | 181:a4cbdfbbd2f4 | 971 | HAL_IRDA_TxCpltCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 972 | |
mbed_official | 181:a4cbdfbbd2f4 | 973 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 974 | } |
mbed_official | 181:a4cbdfbbd2f4 | 975 | else |
mbed_official | 181:a4cbdfbbd2f4 | 976 | { |
mbed_official | 181:a4cbdfbbd2f4 | 977 | if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE)) |
mbed_official | 181:a4cbdfbbd2f4 | 978 | { |
mbed_official | 181:a4cbdfbbd2f4 | 979 | tmp = (uint16_t*) hirda->pTxBuffPtr; |
mbed_official | 181:a4cbdfbbd2f4 | 980 | hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF); |
mbed_official | 181:a4cbdfbbd2f4 | 981 | hirda->pTxBuffPtr += 2; |
mbed_official | 181:a4cbdfbbd2f4 | 982 | } |
mbed_official | 181:a4cbdfbbd2f4 | 983 | else |
mbed_official | 181:a4cbdfbbd2f4 | 984 | { |
mbed_official | 181:a4cbdfbbd2f4 | 985 | hirda->Instance->TDR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0xFF); |
mbed_official | 181:a4cbdfbbd2f4 | 986 | } |
mbed_official | 181:a4cbdfbbd2f4 | 987 | hirda->TxXferCount--; |
mbed_official | 181:a4cbdfbbd2f4 | 988 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 989 | } |
mbed_official | 181:a4cbdfbbd2f4 | 990 | } |
mbed_official | 181:a4cbdfbbd2f4 | 991 | else |
mbed_official | 181:a4cbdfbbd2f4 | 992 | { |
mbed_official | 181:a4cbdfbbd2f4 | 993 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 994 | } |
mbed_official | 181:a4cbdfbbd2f4 | 995 | } |
mbed_official | 181:a4cbdfbbd2f4 | 996 | |
mbed_official | 181:a4cbdfbbd2f4 | 997 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 998 | * @brief Receive an amount of data in non blocking mode. |
mbed_official | 181:a4cbdfbbd2f4 | 999 | * Function called under interruption only, once |
mbed_official | 181:a4cbdfbbd2f4 | 1000 | * interruptions have been enabled by HAL_IRDA_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 1001 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 1002 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 1003 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1004 | static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 1005 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1006 | uint16_t* tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 1007 | uint16_t uhMask = hirda->Mask; |
mbed_official | 181:a4cbdfbbd2f4 | 1008 | |
mbed_official | 181:a4cbdfbbd2f4 | 1009 | if ((hirda->State == HAL_IRDA_STATE_BUSY_RX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 1010 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1011 | if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE)) |
mbed_official | 181:a4cbdfbbd2f4 | 1012 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1013 | tmp = (uint16_t*) hirda->pRxBuffPtr ; |
mbed_official | 181:a4cbdfbbd2f4 | 1014 | *tmp = (uint16_t)(hirda->Instance->RDR & uhMask); |
mbed_official | 181:a4cbdfbbd2f4 | 1015 | hirda->pRxBuffPtr +=2; |
mbed_official | 181:a4cbdfbbd2f4 | 1016 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1017 | else |
mbed_official | 181:a4cbdfbbd2f4 | 1018 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1019 | *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask); |
mbed_official | 181:a4cbdfbbd2f4 | 1020 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1021 | |
mbed_official | 181:a4cbdfbbd2f4 | 1022 | if(--hirda->RxXferCount == 0) |
mbed_official | 181:a4cbdfbbd2f4 | 1023 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1024 | while(HAL_IS_BIT_SET(hirda->Instance->ISR, IRDA_FLAG_RXNE)) |
mbed_official | 181:a4cbdfbbd2f4 | 1025 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1026 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1027 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 1028 | |
mbed_official | 181:a4cbdfbbd2f4 | 1029 | if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 1030 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1031 | hirda->State = HAL_IRDA_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 1032 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1033 | else |
mbed_official | 181:a4cbdfbbd2f4 | 1034 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1035 | /* Disable the IRDA Parity Error Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 1036 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 1037 | |
mbed_official | 181:a4cbdfbbd2f4 | 1038 | /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 1039 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 1040 | |
mbed_official | 181:a4cbdfbbd2f4 | 1041 | hirda->State = HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 1042 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1043 | |
mbed_official | 181:a4cbdfbbd2f4 | 1044 | HAL_IRDA_RxCpltCallback(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 1045 | |
mbed_official | 181:a4cbdfbbd2f4 | 1046 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1047 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1048 | |
mbed_official | 181:a4cbdfbbd2f4 | 1049 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1050 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1051 | else |
mbed_official | 181:a4cbdfbbd2f4 | 1052 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1053 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 1054 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1055 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1056 | |
mbed_official | 181:a4cbdfbbd2f4 | 1057 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1058 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1059 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1060 | |
mbed_official | 181:a4cbdfbbd2f4 | 1061 | /** @defgroup HAL_IRDA_Group3 Peripheral Control functions |
mbed_official | 181:a4cbdfbbd2f4 | 1062 | * @brief IRDA control functions |
mbed_official | 181:a4cbdfbbd2f4 | 1063 | * |
mbed_official | 181:a4cbdfbbd2f4 | 1064 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 1065 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 1066 | ##### Peripheral Control functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 1067 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 1068 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 1069 | This subsection provides a set of functions allowing to control the IRDA. |
mbed_official | 181:a4cbdfbbd2f4 | 1070 | (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IRDA peripheral. |
mbed_official | 181:a4cbdfbbd2f4 | 1071 | (+) IRDA_SetConfig() API is used to configure the IRDA communications parameters. |
mbed_official | 181:a4cbdfbbd2f4 | 1072 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 1073 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 1074 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1075 | |
mbed_official | 181:a4cbdfbbd2f4 | 1076 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1077 | * @brief return the IRDA state |
mbed_official | 181:a4cbdfbbd2f4 | 1078 | * @param hirda: irda handle |
mbed_official | 181:a4cbdfbbd2f4 | 1079 | * @retval HAL state |
mbed_official | 181:a4cbdfbbd2f4 | 1080 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1081 | HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 1082 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1083 | return hirda->State; |
mbed_official | 181:a4cbdfbbd2f4 | 1084 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1085 | |
mbed_official | 181:a4cbdfbbd2f4 | 1086 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1087 | * @brief Return the IRDA error code |
mbed_official | 181:a4cbdfbbd2f4 | 1088 | * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains |
mbed_official | 181:a4cbdfbbd2f4 | 1089 | * the configuration information for the specified IRDA. |
mbed_official | 181:a4cbdfbbd2f4 | 1090 | * @retval IRDA Error Code |
mbed_official | 181:a4cbdfbbd2f4 | 1091 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1092 | uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 1093 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1094 | return hirda->ErrorCode; |
mbed_official | 181:a4cbdfbbd2f4 | 1095 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1096 | |
mbed_official | 181:a4cbdfbbd2f4 | 1097 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1098 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1099 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1100 | |
mbed_official | 181:a4cbdfbbd2f4 | 1101 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1102 | * @brief Configure the IRDA peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 1103 | * @param hirda: irda handle |
mbed_official | 181:a4cbdfbbd2f4 | 1104 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 1105 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1106 | static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 1107 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1108 | uint32_t tmpreg = 0x00000000; |
mbed_official | 181:a4cbdfbbd2f4 | 1109 | uint32_t clocksource = 0x00000000; |
mbed_official | 181:a4cbdfbbd2f4 | 1110 | |
mbed_official | 181:a4cbdfbbd2f4 | 1111 | /* Check the communication parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 1112 | assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate)); |
mbed_official | 181:a4cbdfbbd2f4 | 1113 | assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength)); |
mbed_official | 181:a4cbdfbbd2f4 | 1114 | assert_param(IS_IRDA_PARITY(hirda->Init.Parity)); |
mbed_official | 181:a4cbdfbbd2f4 | 1115 | assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode)); |
mbed_official | 181:a4cbdfbbd2f4 | 1116 | assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler)); |
mbed_official | 181:a4cbdfbbd2f4 | 1117 | assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode)); |
mbed_official | 181:a4cbdfbbd2f4 | 1118 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1119 | /* Configure the IRDA Word Length, Parity and transfer Mode: |
mbed_official | 181:a4cbdfbbd2f4 | 1120 | Set the M bits according to hirda->Init.WordLength value |
mbed_official | 181:a4cbdfbbd2f4 | 1121 | Set PCE and PS bits according to hirda->Init.Parity value |
mbed_official | 181:a4cbdfbbd2f4 | 1122 | Set TE and RE bits according to hirda->Init.Mode value */ |
mbed_official | 181:a4cbdfbbd2f4 | 1123 | tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ; |
mbed_official | 181:a4cbdfbbd2f4 | 1124 | |
mbed_official | 181:a4cbdfbbd2f4 | 1125 | MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg); |
mbed_official | 181:a4cbdfbbd2f4 | 1126 | |
mbed_official | 181:a4cbdfbbd2f4 | 1127 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1128 | MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode); |
mbed_official | 181:a4cbdfbbd2f4 | 1129 | |
mbed_official | 181:a4cbdfbbd2f4 | 1130 | /*-------------------------- USART GTPR Configuration ----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1131 | MODIFY_REG(hirda->Instance->GTPR, (uint32_t)USART_GTPR_PSC, hirda->Init.Prescaler); |
mbed_official | 181:a4cbdfbbd2f4 | 1132 | |
mbed_official | 181:a4cbdfbbd2f4 | 1133 | /*-------------------------- USART BRR Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1134 | __HAL_IRDA_GETCLOCKSOURCE(hirda, clocksource); |
mbed_official | 181:a4cbdfbbd2f4 | 1135 | switch (clocksource) |
mbed_official | 181:a4cbdfbbd2f4 | 1136 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1137 | case IRDA_CLOCKSOURCE_PCLK1: |
mbed_official | 181:a4cbdfbbd2f4 | 1138 | hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hirda->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1139 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1140 | case IRDA_CLOCKSOURCE_PCLK2: |
mbed_official | 181:a4cbdfbbd2f4 | 1141 | hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK2Freq() / hirda->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1142 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1143 | case IRDA_CLOCKSOURCE_HSI: |
mbed_official | 181:a4cbdfbbd2f4 | 1144 | hirda->Instance->BRR = (uint16_t)(HSI_VALUE / hirda->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1145 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1146 | case IRDA_CLOCKSOURCE_SYSCLK: |
mbed_official | 181:a4cbdfbbd2f4 | 1147 | hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hirda->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1148 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1149 | case IRDA_CLOCKSOURCE_LSE: |
mbed_official | 181:a4cbdfbbd2f4 | 1150 | hirda->Instance->BRR = (uint16_t)(LSE_VALUE / hirda->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1151 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1152 | default: |
mbed_official | 181:a4cbdfbbd2f4 | 1153 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1154 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1155 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1156 | |
mbed_official | 181:a4cbdfbbd2f4 | 1157 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1158 | * @brief Check the IRDA Idle State |
mbed_official | 181:a4cbdfbbd2f4 | 1159 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 1160 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 1161 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1162 | static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda) |
mbed_official | 181:a4cbdfbbd2f4 | 1163 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1164 | /* Initialize the IRDA ErrorCode */ |
mbed_official | 181:a4cbdfbbd2f4 | 1165 | hirda->ErrorCode = HAL_IRDA_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 1166 | |
mbed_official | 181:a4cbdfbbd2f4 | 1167 | /* Check if the Transmitter is enabled */ |
mbed_official | 181:a4cbdfbbd2f4 | 1168 | if((hirda->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
mbed_official | 181:a4cbdfbbd2f4 | 1169 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1170 | /* Wait until TEACK flag is set */ |
mbed_official | 181:a4cbdfbbd2f4 | 1171 | if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_TEACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1172 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1173 | hirda->State= HAL_IRDA_STATE_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1174 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1175 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1176 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1177 | /* Check if the Receiver is enabled */ |
mbed_official | 181:a4cbdfbbd2f4 | 1178 | if((hirda->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE) |
mbed_official | 181:a4cbdfbbd2f4 | 1179 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1180 | if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_REACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1181 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1182 | hirda->State= HAL_IRDA_STATE_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1183 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1184 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1185 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1186 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 1187 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 1188 | |
mbed_official | 181:a4cbdfbbd2f4 | 1189 | /* Initialize the IRDA state*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1190 | hirda->State= HAL_IRDA_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 1191 | |
mbed_official | 181:a4cbdfbbd2f4 | 1192 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1193 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1194 | |
mbed_official | 181:a4cbdfbbd2f4 | 1195 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1196 | * @brief Handle IRDA Communication Timeout. |
mbed_official | 181:a4cbdfbbd2f4 | 1197 | * @param hirda: IRDA handle |
mbed_official | 181:a4cbdfbbd2f4 | 1198 | * @param Flag: specifies the IRDA flag to check. |
mbed_official | 181:a4cbdfbbd2f4 | 1199 | * @param Status: the flag status (SET or RESET). The function is locked in a while loop as long as the flag remains set to Status. |
mbed_official | 181:a4cbdfbbd2f4 | 1200 | * @param Timeout: Timeout duration |
mbed_official | 181:a4cbdfbbd2f4 | 1201 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 1202 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1203 | static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 1204 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1205 | uint32_t tickstart = 0x00; |
mbed_official | 181:a4cbdfbbd2f4 | 1206 | tickstart = HAL_GetTick(); |
mbed_official | 181:a4cbdfbbd2f4 | 1207 | |
mbed_official | 181:a4cbdfbbd2f4 | 1208 | /* Wait until flag is set */ |
mbed_official | 181:a4cbdfbbd2f4 | 1209 | if(Status == RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 1210 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1211 | while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 1212 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1213 | /* Check for the Timeout */ |
mbed_official | 181:a4cbdfbbd2f4 | 1214 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 181:a4cbdfbbd2f4 | 1215 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1216 | if((HAL_GetTick() - tickstart ) > Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 1217 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1218 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
mbed_official | 181:a4cbdfbbd2f4 | 1219 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE); |
mbed_official | 181:a4cbdfbbd2f4 | 1220 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 1221 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 1222 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 1223 | |
mbed_official | 181:a4cbdfbbd2f4 | 1224 | hirda->State= HAL_IRDA_STATE_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1225 | |
mbed_official | 181:a4cbdfbbd2f4 | 1226 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 1227 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 1228 | |
mbed_official | 181:a4cbdfbbd2f4 | 1229 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1230 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1231 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1232 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1233 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1234 | else |
mbed_official | 181:a4cbdfbbd2f4 | 1235 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1236 | while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 1237 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1238 | /* Check for the Timeout */ |
mbed_official | 181:a4cbdfbbd2f4 | 1239 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 181:a4cbdfbbd2f4 | 1240 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1241 | if((HAL_GetTick() - tickstart ) > Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 1242 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1243 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
mbed_official | 181:a4cbdfbbd2f4 | 1244 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE); |
mbed_official | 181:a4cbdfbbd2f4 | 1245 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 1246 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 1247 | __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 1248 | |
mbed_official | 181:a4cbdfbbd2f4 | 1249 | hirda->State= HAL_IRDA_STATE_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1250 | |
mbed_official | 181:a4cbdfbbd2f4 | 1251 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 1252 | __HAL_UNLOCK(hirda); |
mbed_official | 181:a4cbdfbbd2f4 | 1253 | |
mbed_official | 181:a4cbdfbbd2f4 | 1254 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1255 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1256 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1257 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1258 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1259 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1260 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1261 | |
mbed_official | 181:a4cbdfbbd2f4 | 1262 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1263 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1264 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1265 | |
mbed_official | 181:a4cbdfbbd2f4 | 1266 | #endif /* HAL_IRDA_MODULE_ENABLED */ |
mbed_official | 181:a4cbdfbbd2f4 | 1267 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1268 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1269 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1270 | |
mbed_official | 181:a4cbdfbbd2f4 | 1271 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1272 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1273 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1274 | |
mbed_official | 181:a4cbdfbbd2f4 | 1275 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |