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