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