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