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