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