mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
Kojto
Date:
Wed Apr 29 10:16:23 2015 +0100
Revision:
98:8ab26030e058
Child:
113:f141b2784e32
Release 98 of the mbed library

Changes:
- Silabs new targets (Giant, Zero, Happy, Leopard, Wonder Geckos)
- Asynchronous SPI, I2C, Serial
- LowPower classes
- Nordic - nordic SDK v8.0 update
- Teensy - gcc arm fix for startup
- Nucleo F411 - usb freq fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 98:8ab26030e058 1 /***************************************************************************//**
Kojto 98:8ab26030e058 2 * @file em_usart.h
Kojto 98:8ab26030e058 3 * @brief Universal synchronous/asynchronous receiver/transmitter (USART/UART)
Kojto 98:8ab26030e058 4 * peripheral API
Kojto 98:8ab26030e058 5 * @version 3.20.12
Kojto 98:8ab26030e058 6 *******************************************************************************
Kojto 98:8ab26030e058 7 * @section License
Kojto 98:8ab26030e058 8 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
Kojto 98:8ab26030e058 9 *******************************************************************************
Kojto 98:8ab26030e058 10 *
Kojto 98:8ab26030e058 11 * Permission is granted to anyone to use this software for any purpose,
Kojto 98:8ab26030e058 12 * including commercial applications, and to alter it and redistribute it
Kojto 98:8ab26030e058 13 * freely, subject to the following restrictions:
Kojto 98:8ab26030e058 14 *
Kojto 98:8ab26030e058 15 * 1. The origin of this software must not be misrepresented; you must not
Kojto 98:8ab26030e058 16 * claim that you wrote the original software.
Kojto 98:8ab26030e058 17 * 2. Altered source versions must be plainly marked as such, and must not be
Kojto 98:8ab26030e058 18 * misrepresented as being the original software.
Kojto 98:8ab26030e058 19 * 3. This notice may not be removed or altered from any source distribution.
Kojto 98:8ab26030e058 20 *
Kojto 98:8ab26030e058 21 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
Kojto 98:8ab26030e058 22 * obligation to support this Software. Silicon Labs is providing the
Kojto 98:8ab26030e058 23 * Software "AS IS", with no express or implied warranties of any kind,
Kojto 98:8ab26030e058 24 * including, but not limited to, any implied warranties of merchantability
Kojto 98:8ab26030e058 25 * or fitness for any particular purpose or warranties against infringement
Kojto 98:8ab26030e058 26 * of any proprietary rights of a third party.
Kojto 98:8ab26030e058 27 *
Kojto 98:8ab26030e058 28 * Silicon Labs will not be liable for any consequential, incidental, or
Kojto 98:8ab26030e058 29 * special damages, or any other relief, or for any claim by any third party,
Kojto 98:8ab26030e058 30 * arising from your use of this Software.
Kojto 98:8ab26030e058 31 *
Kojto 98:8ab26030e058 32 ******************************************************************************/
Kojto 98:8ab26030e058 33
Kojto 98:8ab26030e058 34
Kojto 98:8ab26030e058 35 #ifndef __SILICON_LABS_EM_USART_H_
Kojto 98:8ab26030e058 36 #define __SILICON_LABS_EM_USART_H_
Kojto 98:8ab26030e058 37
Kojto 98:8ab26030e058 38 #include "em_device.h"
Kojto 98:8ab26030e058 39 #if defined(USART_COUNT) && (USART_COUNT > 0)
Kojto 98:8ab26030e058 40
Kojto 98:8ab26030e058 41 #include <stdbool.h>
Kojto 98:8ab26030e058 42
Kojto 98:8ab26030e058 43 #ifdef __cplusplus
Kojto 98:8ab26030e058 44 extern "C" {
Kojto 98:8ab26030e058 45 #endif
Kojto 98:8ab26030e058 46
Kojto 98:8ab26030e058 47 /***************************************************************************//**
Kojto 98:8ab26030e058 48 * @addtogroup EM_Library
Kojto 98:8ab26030e058 49 * @{
Kojto 98:8ab26030e058 50 ******************************************************************************/
Kojto 98:8ab26030e058 51
Kojto 98:8ab26030e058 52 /***************************************************************************//**
Kojto 98:8ab26030e058 53 * @addtogroup USART
Kojto 98:8ab26030e058 54 * @brief Universal Synchronous/Asynchronous Receiver/Transmitter (USART) peripheral API
Kojto 98:8ab26030e058 55 * @{
Kojto 98:8ab26030e058 56 ******************************************************************************/
Kojto 98:8ab26030e058 57
Kojto 98:8ab26030e058 58 /*******************************************************************************
Kojto 98:8ab26030e058 59 ******************************** ENUMS ************************************
Kojto 98:8ab26030e058 60 ******************************************************************************/
Kojto 98:8ab26030e058 61
Kojto 98:8ab26030e058 62 /** Databit selection. */
Kojto 98:8ab26030e058 63 typedef enum
Kojto 98:8ab26030e058 64 {
Kojto 98:8ab26030e058 65 usartDatabits4 = USART_FRAME_DATABITS_FOUR, /**< 4 databits (not available for UART). */
Kojto 98:8ab26030e058 66 usartDatabits5 = USART_FRAME_DATABITS_FIVE, /**< 5 databits (not available for UART). */
Kojto 98:8ab26030e058 67 usartDatabits6 = USART_FRAME_DATABITS_SIX, /**< 6 databits (not available for UART). */
Kojto 98:8ab26030e058 68 usartDatabits7 = USART_FRAME_DATABITS_SEVEN, /**< 7 databits (not available for UART). */
Kojto 98:8ab26030e058 69 usartDatabits8 = USART_FRAME_DATABITS_EIGHT, /**< 8 databits. */
Kojto 98:8ab26030e058 70 usartDatabits9 = USART_FRAME_DATABITS_NINE, /**< 9 databits. */
Kojto 98:8ab26030e058 71 usartDatabits10 = USART_FRAME_DATABITS_TEN, /**< 10 databits (not available for UART). */
Kojto 98:8ab26030e058 72 usartDatabits11 = USART_FRAME_DATABITS_ELEVEN, /**< 11 databits (not available for UART). */
Kojto 98:8ab26030e058 73 usartDatabits12 = USART_FRAME_DATABITS_TWELVE, /**< 12 databits (not available for UART). */
Kojto 98:8ab26030e058 74 usartDatabits13 = USART_FRAME_DATABITS_THIRTEEN, /**< 13 databits (not available for UART). */
Kojto 98:8ab26030e058 75 usartDatabits14 = USART_FRAME_DATABITS_FOURTEEN, /**< 14 databits (not available for UART). */
Kojto 98:8ab26030e058 76 usartDatabits15 = USART_FRAME_DATABITS_FIFTEEN, /**< 15 databits (not available for UART). */
Kojto 98:8ab26030e058 77 usartDatabits16 = USART_FRAME_DATABITS_SIXTEEN /**< 16 databits (not available for UART). */
Kojto 98:8ab26030e058 78 } USART_Databits_TypeDef;
Kojto 98:8ab26030e058 79
Kojto 98:8ab26030e058 80
Kojto 98:8ab26030e058 81 /** Enable selection. */
Kojto 98:8ab26030e058 82 typedef enum
Kojto 98:8ab26030e058 83 {
Kojto 98:8ab26030e058 84 /** Disable both receiver and transmitter. */
Kojto 98:8ab26030e058 85 usartDisable = 0x0,
Kojto 98:8ab26030e058 86
Kojto 98:8ab26030e058 87 /** Enable receiver only, transmitter disabled. */
Kojto 98:8ab26030e058 88 usartEnableRx = USART_CMD_RXEN,
Kojto 98:8ab26030e058 89
Kojto 98:8ab26030e058 90 /** Enable transmitter only, receiver disabled. */
Kojto 98:8ab26030e058 91 usartEnableTx = USART_CMD_TXEN,
Kojto 98:8ab26030e058 92
Kojto 98:8ab26030e058 93 /** Enable both receiver and transmitter. */
Kojto 98:8ab26030e058 94 usartEnable = (USART_CMD_RXEN | USART_CMD_TXEN)
Kojto 98:8ab26030e058 95 } USART_Enable_TypeDef;
Kojto 98:8ab26030e058 96
Kojto 98:8ab26030e058 97
Kojto 98:8ab26030e058 98 /** Oversampling selection, used for asynchronous operation. */
Kojto 98:8ab26030e058 99 typedef enum
Kojto 98:8ab26030e058 100 {
Kojto 98:8ab26030e058 101 usartOVS16 = USART_CTRL_OVS_X16, /**< 16x oversampling (normal). */
Kojto 98:8ab26030e058 102 usartOVS8 = USART_CTRL_OVS_X8, /**< 8x oversampling. */
Kojto 98:8ab26030e058 103 usartOVS6 = USART_CTRL_OVS_X6, /**< 6x oversampling. */
Kojto 98:8ab26030e058 104 usartOVS4 = USART_CTRL_OVS_X4 /**< 4x oversampling. */
Kojto 98:8ab26030e058 105 } USART_OVS_TypeDef;
Kojto 98:8ab26030e058 106
Kojto 98:8ab26030e058 107
Kojto 98:8ab26030e058 108 /** Parity selection, mainly used for asynchronous operation. */
Kojto 98:8ab26030e058 109 typedef enum
Kojto 98:8ab26030e058 110 {
Kojto 98:8ab26030e058 111 usartNoParity = USART_FRAME_PARITY_NONE, /**< No parity. */
Kojto 98:8ab26030e058 112 usartEvenParity = USART_FRAME_PARITY_EVEN, /**< Even parity. */
Kojto 98:8ab26030e058 113 usartOddParity = USART_FRAME_PARITY_ODD /**< Odd parity. */
Kojto 98:8ab26030e058 114 } USART_Parity_TypeDef;
Kojto 98:8ab26030e058 115
Kojto 98:8ab26030e058 116
Kojto 98:8ab26030e058 117 /** Stopbits selection, used for asynchronous operation. */
Kojto 98:8ab26030e058 118 typedef enum
Kojto 98:8ab26030e058 119 {
Kojto 98:8ab26030e058 120 usartStopbits0p5 = USART_FRAME_STOPBITS_HALF, /**< 0.5 stopbits. */
Kojto 98:8ab26030e058 121 usartStopbits1 = USART_FRAME_STOPBITS_ONE, /**< 1 stopbits. */
Kojto 98:8ab26030e058 122 usartStopbits1p5 = USART_FRAME_STOPBITS_ONEANDAHALF, /**< 1.5 stopbits. */
Kojto 98:8ab26030e058 123 usartStopbits2 = USART_FRAME_STOPBITS_TWO /**< 2 stopbits. */
Kojto 98:8ab26030e058 124 } USART_Stopbits_TypeDef;
Kojto 98:8ab26030e058 125
Kojto 98:8ab26030e058 126
Kojto 98:8ab26030e058 127 /** Clock polarity/phase mode. */
Kojto 98:8ab26030e058 128 typedef enum
Kojto 98:8ab26030e058 129 {
Kojto 98:8ab26030e058 130 /** Clock idle low, sample on rising edge. */
Kojto 98:8ab26030e058 131 usartClockMode0 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLELEADING,
Kojto 98:8ab26030e058 132
Kojto 98:8ab26030e058 133 /** Clock idle low, sample on falling edge. */
Kojto 98:8ab26030e058 134 usartClockMode1 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLETRAILING,
Kojto 98:8ab26030e058 135
Kojto 98:8ab26030e058 136 /** Clock idle high, sample on falling edge. */
Kojto 98:8ab26030e058 137 usartClockMode2 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLELEADING,
Kojto 98:8ab26030e058 138
Kojto 98:8ab26030e058 139 /** Clock idle high, sample on rising edge. */
Kojto 98:8ab26030e058 140 usartClockMode3 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLETRAILING
Kojto 98:8ab26030e058 141 } USART_ClockMode_TypeDef;
Kojto 98:8ab26030e058 142
Kojto 98:8ab26030e058 143
Kojto 98:8ab26030e058 144 /** Pulse width selection for IrDA mode. */
Kojto 98:8ab26030e058 145 typedef enum
Kojto 98:8ab26030e058 146 {
Kojto 98:8ab26030e058 147 /** IrDA pulse width is 1/16 for OVS=0 and 1/8 for OVS=1 */
Kojto 98:8ab26030e058 148 usartIrDAPwONE = USART_IRCTRL_IRPW_ONE,
Kojto 98:8ab26030e058 149
Kojto 98:8ab26030e058 150 /** IrDA pulse width is 2/16 for OVS=0 and 2/8 for OVS=1 */
Kojto 98:8ab26030e058 151 usartIrDAPwTWO = USART_IRCTRL_IRPW_TWO,
Kojto 98:8ab26030e058 152
Kojto 98:8ab26030e058 153 /** IrDA pulse width is 3/16 for OVS=0 and 3/8 for OVS=1 */
Kojto 98:8ab26030e058 154 usartIrDAPwTHREE = USART_IRCTRL_IRPW_THREE,
Kojto 98:8ab26030e058 155
Kojto 98:8ab26030e058 156 /** IrDA pulse width is 4/16 for OVS=0 and 4/8 for OVS=1 */
Kojto 98:8ab26030e058 157 usartIrDAPwFOUR = USART_IRCTRL_IRPW_FOUR
Kojto 98:8ab26030e058 158 } USART_IrDAPw_Typedef;
Kojto 98:8ab26030e058 159
Kojto 98:8ab26030e058 160
Kojto 98:8ab26030e058 161 /** PRS channel selection for IrDA mode. */
Kojto 98:8ab26030e058 162 typedef enum
Kojto 98:8ab26030e058 163 {
Kojto 98:8ab26030e058 164 usartIrDAPrsCh0 = USART_IRCTRL_IRPRSSEL_PRSCH0, /**< PRS channel 0 */
Kojto 98:8ab26030e058 165 usartIrDAPrsCh1 = USART_IRCTRL_IRPRSSEL_PRSCH1, /**< PRS channel 1 */
Kojto 98:8ab26030e058 166 usartIrDAPrsCh2 = USART_IRCTRL_IRPRSSEL_PRSCH2, /**< PRS channel 2 */
Kojto 98:8ab26030e058 167 usartIrDAPrsCh3 = USART_IRCTRL_IRPRSSEL_PRSCH3, /**< PRS channel 3 */
Kojto 98:8ab26030e058 168 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH4 )
Kojto 98:8ab26030e058 169 usartIrDAPrsCh4 = USART_IRCTRL_IRPRSSEL_PRSCH4, /**< PRS channel 4 */
Kojto 98:8ab26030e058 170 #endif
Kojto 98:8ab26030e058 171 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH5 )
Kojto 98:8ab26030e058 172 usartIrDAPrsCh5 = USART_IRCTRL_IRPRSSEL_PRSCH5, /**< PRS channel 5 */
Kojto 98:8ab26030e058 173 #endif
Kojto 98:8ab26030e058 174 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH6 )
Kojto 98:8ab26030e058 175 usartIrDAPrsCh6 = USART_IRCTRL_IRPRSSEL_PRSCH6, /**< PRS channel 6 */
Kojto 98:8ab26030e058 176 #endif
Kojto 98:8ab26030e058 177 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH7 )
Kojto 98:8ab26030e058 178 usartIrDAPrsCh7 = USART_IRCTRL_IRPRSSEL_PRSCH7, /**< PRS channel 7 */
Kojto 98:8ab26030e058 179 #endif
Kojto 98:8ab26030e058 180 } USART_IrDAPrsSel_Typedef;
Kojto 98:8ab26030e058 181
Kojto 98:8ab26030e058 182 #if defined( _USART_I2SCTRL_MASK )
Kojto 98:8ab26030e058 183 /** I2S format selection. */
Kojto 98:8ab26030e058 184 typedef enum
Kojto 98:8ab26030e058 185 {
Kojto 98:8ab26030e058 186 usartI2sFormatW32D32 = USART_I2SCTRL_FORMAT_W32D32, /**< 32-bit word, 32-bit data */
Kojto 98:8ab26030e058 187 usartI2sFormatW32D24M = USART_I2SCTRL_FORMAT_W32D24M, /**< 32-bit word, 32-bit data with 8 lsb masked */
Kojto 98:8ab26030e058 188 usartI2sFormatW32D24 = USART_I2SCTRL_FORMAT_W32D24, /**< 32-bit word, 24-bit data */
Kojto 98:8ab26030e058 189 usartI2sFormatW32D16 = USART_I2SCTRL_FORMAT_W32D16, /**< 32-bit word, 16-bit data */
Kojto 98:8ab26030e058 190 usartI2sFormatW32D8 = USART_I2SCTRL_FORMAT_W32D8, /**< 32-bit word, 8-bit data */
Kojto 98:8ab26030e058 191 usartI2sFormatW16D16 = USART_I2SCTRL_FORMAT_W16D16, /**< 16-bit word, 16-bit data */
Kojto 98:8ab26030e058 192 usartI2sFormatW16D8 = USART_I2SCTRL_FORMAT_W16D8, /**< 16-bit word, 8-bit data */
Kojto 98:8ab26030e058 193 usartI2sFormatW8D8 = USART_I2SCTRL_FORMAT_W8D8 /**< 8-bit word, 8-bit data */
Kojto 98:8ab26030e058 194 } USART_I2sFormat_TypeDef;
Kojto 98:8ab26030e058 195
Kojto 98:8ab26030e058 196 /** I2S frame data justify. */
Kojto 98:8ab26030e058 197 typedef enum
Kojto 98:8ab26030e058 198 {
Kojto 98:8ab26030e058 199 usartI2sJustifyLeft = USART_I2SCTRL_JUSTIFY_LEFT, /**< Data is left-justified within the frame */
Kojto 98:8ab26030e058 200 usartI2sJustifyRight = USART_I2SCTRL_JUSTIFY_RIGHT /**< Data is right-justified within the frame */
Kojto 98:8ab26030e058 201 } USART_I2sJustify_TypeDef;
Kojto 98:8ab26030e058 202 #endif
Kojto 98:8ab26030e058 203
Kojto 98:8ab26030e058 204 #if defined( _USART_INPUT_MASK )
Kojto 98:8ab26030e058 205 /** USART Rx input PRS selection. */
Kojto 98:8ab26030e058 206 typedef enum
Kojto 98:8ab26030e058 207 {
Kojto 98:8ab26030e058 208 usartPrsRxCh0 = USART_INPUT_RXPRSSEL_PRSCH0, /**< PRSCH0 selected as USART_INPUT */
Kojto 98:8ab26030e058 209 usartPrsRxCh1 = USART_INPUT_RXPRSSEL_PRSCH1, /**< PRSCH1 selected as USART_INPUT */
Kojto 98:8ab26030e058 210 usartPrsRxCh2 = USART_INPUT_RXPRSSEL_PRSCH2, /**< PRSCH2 selected as USART_INPUT */
Kojto 98:8ab26030e058 211 usartPrsRxCh3 = USART_INPUT_RXPRSSEL_PRSCH3, /**< PRSCH3 selected as USART_INPUT */
Kojto 98:8ab26030e058 212
Kojto 98:8ab26030e058 213 #if defined( USART_INPUT_RXPRSSEL_PRSCH7 )
Kojto 98:8ab26030e058 214 usartPrsRxCh4 = USART_INPUT_RXPRSSEL_PRSCH4, /**< PRSCH4 selected as USART_INPUT */
Kojto 98:8ab26030e058 215 usartPrsRxCh5 = USART_INPUT_RXPRSSEL_PRSCH5, /**< PRSCH5 selected as USART_INPUT */
Kojto 98:8ab26030e058 216 usartPrsRxCh6 = USART_INPUT_RXPRSSEL_PRSCH6, /**< PRSCH6 selected as USART_INPUT */
Kojto 98:8ab26030e058 217 usartPrsRxCh7 = USART_INPUT_RXPRSSEL_PRSCH7, /**< PRSCH7 selected as USART_INPUT */
Kojto 98:8ab26030e058 218 #endif
Kojto 98:8ab26030e058 219
Kojto 98:8ab26030e058 220 #if defined( USART_INPUT_RXPRSSEL_PRSCH11 )
Kojto 98:8ab26030e058 221 usartPrsRxCh8 = USART_INPUT_RXPRSSEL_PRSCH8, /**< PRSCH8 selected as USART_INPUT */
Kojto 98:8ab26030e058 222 usartPrsRxCh9 = USART_INPUT_RXPRSSEL_PRSCH9, /**< PRSCH9 selected as USART_INPUT */
Kojto 98:8ab26030e058 223 usartPrsRxCh10 = USART_INPUT_RXPRSSEL_PRSCH10, /**< PRSCH10 selected as USART_INPUT */
Kojto 98:8ab26030e058 224 usartPrsRxCh11 = USART_INPUT_RXPRSSEL_PRSCH11 /**< PRSCH11 selected as USART_INPUT */
Kojto 98:8ab26030e058 225 #endif
Kojto 98:8ab26030e058 226 } USART_PrsRxCh_TypeDef;
Kojto 98:8ab26030e058 227 #endif
Kojto 98:8ab26030e058 228
Kojto 98:8ab26030e058 229 /** USART PRS Transmit Trigger Channels */
Kojto 98:8ab26030e058 230 typedef enum
Kojto 98:8ab26030e058 231 {
Kojto 98:8ab26030e058 232 usartPrsTriggerCh0 = USART_TRIGCTRL_TSEL_PRSCH0, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 233 usartPrsTriggerCh1 = USART_TRIGCTRL_TSEL_PRSCH1, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 234 usartPrsTriggerCh2 = USART_TRIGCTRL_TSEL_PRSCH2, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 235 usartPrsTriggerCh3 = USART_TRIGCTRL_TSEL_PRSCH3, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 236
Kojto 98:8ab26030e058 237 #if defined( USART_TRIGCTRL_TSEL_PRSCH7 )
Kojto 98:8ab26030e058 238 usartPrsTriggerCh4 = USART_TRIGCTRL_TSEL_PRSCH4, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 239 usartPrsTriggerCh5 = USART_TRIGCTRL_TSEL_PRSCH5, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 240 usartPrsTriggerCh6 = USART_TRIGCTRL_TSEL_PRSCH6, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 241 usartPrsTriggerCh7 = USART_TRIGCTRL_TSEL_PRSCH7, /**< PRSCH0 selected as USART Trigger */
Kojto 98:8ab26030e058 242 #endif
Kojto 98:8ab26030e058 243 } USART_PrsTriggerCh_TypeDef;
Kojto 98:8ab26030e058 244
Kojto 98:8ab26030e058 245 /*******************************************************************************
Kojto 98:8ab26030e058 246 ******************************* STRUCTS ***********************************
Kojto 98:8ab26030e058 247 ******************************************************************************/
Kojto 98:8ab26030e058 248
Kojto 98:8ab26030e058 249 /** Asynchronous mode init structure. */
Kojto 98:8ab26030e058 250 typedef struct
Kojto 98:8ab26030e058 251 {
Kojto 98:8ab26030e058 252 /** Specifies whether TX and/or RX shall be enabled when init completed. */
Kojto 98:8ab26030e058 253 USART_Enable_TypeDef enable;
Kojto 98:8ab26030e058 254
Kojto 98:8ab26030e058 255 /**
Kojto 98:8ab26030e058 256 * USART/UART reference clock assumed when configuring baudrate setup. Set
Kojto 98:8ab26030e058 257 * it to 0 if currently configurated reference clock shall be used.
Kojto 98:8ab26030e058 258 */
Kojto 98:8ab26030e058 259 uint32_t refFreq;
Kojto 98:8ab26030e058 260
Kojto 98:8ab26030e058 261 /** Desired baudrate. */
Kojto 98:8ab26030e058 262 uint32_t baudrate;
Kojto 98:8ab26030e058 263
Kojto 98:8ab26030e058 264 /** Oversampling used. */
Kojto 98:8ab26030e058 265 USART_OVS_TypeDef oversampling;
Kojto 98:8ab26030e058 266
Kojto 98:8ab26030e058 267 /** Number of databits in frame. Notice that UART modules only support 8 or
Kojto 98:8ab26030e058 268 * 9 databits. */
Kojto 98:8ab26030e058 269 USART_Databits_TypeDef databits;
Kojto 98:8ab26030e058 270
Kojto 98:8ab26030e058 271 /** Parity mode to use. */
Kojto 98:8ab26030e058 272 USART_Parity_TypeDef parity;
Kojto 98:8ab26030e058 273
Kojto 98:8ab26030e058 274 /** Number of stopbits to use. */
Kojto 98:8ab26030e058 275 USART_Stopbits_TypeDef stopbits;
Kojto 98:8ab26030e058 276
Kojto 98:8ab26030e058 277 #if defined( USART_INPUT_RXPRS ) && defined( USART_CTRL_MVDIS )
Kojto 98:8ab26030e058 278 /** Majority Vote Disable for 16x, 8x and 6x oversampling modes. */
Kojto 98:8ab26030e058 279 bool mvdis;
Kojto 98:8ab26030e058 280
Kojto 98:8ab26030e058 281 /** Enable USART Rx via PRS. */
Kojto 98:8ab26030e058 282 bool prsRxEnable;
Kojto 98:8ab26030e058 283
Kojto 98:8ab26030e058 284 /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
Kojto 98:8ab26030e058 285 USART_PrsRxCh_TypeDef prsRxCh;
Kojto 98:8ab26030e058 286 #endif
Kojto 98:8ab26030e058 287 } USART_InitAsync_TypeDef;
Kojto 98:8ab26030e058 288
Kojto 98:8ab26030e058 289 /** USART PRS trigger enable */
Kojto 98:8ab26030e058 290 typedef struct
Kojto 98:8ab26030e058 291 {
Kojto 98:8ab26030e058 292 #if defined( USART_TRIGCTRL_AUTOTXTEN )
Kojto 98:8ab26030e058 293 /** Enable AUTOTX */
Kojto 98:8ab26030e058 294 bool autoTxTriggerEnable;
Kojto 98:8ab26030e058 295 #endif
Kojto 98:8ab26030e058 296 /** Trigger receive via PRS channel */
Kojto 98:8ab26030e058 297 bool rxTriggerEnable;
Kojto 98:8ab26030e058 298 /** Trigger transmit via PRS channel */
Kojto 98:8ab26030e058 299 bool txTriggerEnable;
Kojto 98:8ab26030e058 300 /** PRS channel to be used to trigger auto transmission */
Kojto 98:8ab26030e058 301 USART_PrsTriggerCh_TypeDef prsTriggerChannel;
Kojto 98:8ab26030e058 302 } USART_PrsTriggerInit_TypeDef;
Kojto 98:8ab26030e058 303
Kojto 98:8ab26030e058 304 /** Default config for USART async init structure. */
Kojto 98:8ab26030e058 305 #if defined( USART_INPUT_RXPRS ) && defined( USART_CTRL_MVDIS )
Kojto 98:8ab26030e058 306 #define USART_INITASYNC_DEFAULT \
Kojto 98:8ab26030e058 307 { usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 98:8ab26030e058 308 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 98:8ab26030e058 309 115200, /* 115200 bits/s. */ \
Kojto 98:8ab26030e058 310 usartOVS16, /* 16x oversampling. */ \
Kojto 98:8ab26030e058 311 usartDatabits8, /* 8 databits. */ \
Kojto 98:8ab26030e058 312 usartNoParity, /* No parity. */ \
Kojto 98:8ab26030e058 313 usartStopbits1, /* 1 stopbit. */ \
Kojto 98:8ab26030e058 314 false, /* Do not disable majority vote. */ \
Kojto 98:8ab26030e058 315 false, /* Not USART PRS input mode. */ \
Kojto 98:8ab26030e058 316 usartPrsRxCh0 /* PRS channel 0. */ \
Kojto 98:8ab26030e058 317 }
Kojto 98:8ab26030e058 318 #else
Kojto 98:8ab26030e058 319 #define USART_INITASYNC_DEFAULT \
Kojto 98:8ab26030e058 320 { usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 98:8ab26030e058 321 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 98:8ab26030e058 322 115200, /* 115200 bits/s. */ \
Kojto 98:8ab26030e058 323 usartOVS16, /* 16x oversampling. */ \
Kojto 98:8ab26030e058 324 usartDatabits8, /* 8 databits. */ \
Kojto 98:8ab26030e058 325 usartNoParity, /* No parity. */ \
Kojto 98:8ab26030e058 326 usartStopbits1 /* 1 stopbit. */ \
Kojto 98:8ab26030e058 327 }
Kojto 98:8ab26030e058 328 #endif
Kojto 98:8ab26030e058 329
Kojto 98:8ab26030e058 330 /** Default config for USART PRS triggering structure. */
Kojto 98:8ab26030e058 331 #if defined ( USART_TRIGCTRL_AUTOTXTEN )
Kojto 98:8ab26030e058 332 #define USART_INITPRSTRIGGER_DEFAULT \
Kojto 98:8ab26030e058 333 { false, /* Do not enable autoTX triggering. */ \
Kojto 98:8ab26030e058 334 false, /* Do not enable receive triggering. */ \
Kojto 98:8ab26030e058 335 false, /* Do not enable transmit triggering. */ \
Kojto 98:8ab26030e058 336 usartPrsTriggerCh0 /* Set default channel to zero. */ \
Kojto 98:8ab26030e058 337 }
Kojto 98:8ab26030e058 338 #else
Kojto 98:8ab26030e058 339 #define USART_INITPRSTRIGGER_DEFAULT \
Kojto 98:8ab26030e058 340 { false, /* Do not enable receive triggering. */ \
Kojto 98:8ab26030e058 341 false, /* Do not enable transmit triggering. */ \
Kojto 98:8ab26030e058 342 usartPrsTriggerCh0 /* Set default channel to zero. */ \
Kojto 98:8ab26030e058 343 }
Kojto 98:8ab26030e058 344 #endif
Kojto 98:8ab26030e058 345
Kojto 98:8ab26030e058 346 /** Synchronous mode init structure. */
Kojto 98:8ab26030e058 347 typedef struct
Kojto 98:8ab26030e058 348 {
Kojto 98:8ab26030e058 349 /** Specifies whether TX and/or RX shall be enabled when init completed. */
Kojto 98:8ab26030e058 350 USART_Enable_TypeDef enable;
Kojto 98:8ab26030e058 351
Kojto 98:8ab26030e058 352 /**
Kojto 98:8ab26030e058 353 * USART/UART reference clock assumed when configuring baudrate setup. Set
Kojto 98:8ab26030e058 354 * it to 0 if currently configurated reference clock shall be used.
Kojto 98:8ab26030e058 355 */
Kojto 98:8ab26030e058 356 uint32_t refFreq;
Kojto 98:8ab26030e058 357
Kojto 98:8ab26030e058 358 /** Desired baudrate. */
Kojto 98:8ab26030e058 359 uint32_t baudrate;
Kojto 98:8ab26030e058 360
Kojto 98:8ab26030e058 361 /** Number of databits in frame. */
Kojto 98:8ab26030e058 362 USART_Databits_TypeDef databits;
Kojto 98:8ab26030e058 363
Kojto 98:8ab26030e058 364 /** Select if to operate in master or slave mode. */
Kojto 98:8ab26030e058 365 bool master;
Kojto 98:8ab26030e058 366
Kojto 98:8ab26030e058 367 /** Select if to send most or least significant bit first. */
Kojto 98:8ab26030e058 368 bool msbf;
Kojto 98:8ab26030e058 369
Kojto 98:8ab26030e058 370 /** Clock polarity/phase mode. */
Kojto 98:8ab26030e058 371 USART_ClockMode_TypeDef clockMode;
Kojto 98:8ab26030e058 372
Kojto 98:8ab26030e058 373 #if defined( USART_INPUT_RXPRS ) && defined( USART_TRIGCTRL_AUTOTXTEN )
Kojto 98:8ab26030e058 374 /** Enable USART Rx via PRS. */
Kojto 98:8ab26030e058 375 bool prsRxEnable;
Kojto 98:8ab26030e058 376
Kojto 98:8ab26030e058 377 /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
Kojto 98:8ab26030e058 378 USART_PrsRxCh_TypeDef prsRxCh;
Kojto 98:8ab26030e058 379
Kojto 98:8ab26030e058 380 /** Enable AUTOTX mode. Transmits as long as RX is not full.
Kojto 98:8ab26030e058 381 * If TX is empty, underflows are generated. */
Kojto 98:8ab26030e058 382 bool autoTx;
Kojto 98:8ab26030e058 383 #endif
Kojto 98:8ab26030e058 384 } USART_InitSync_TypeDef;
Kojto 98:8ab26030e058 385
Kojto 98:8ab26030e058 386 /** Default config for USART sync init structure. */
Kojto 98:8ab26030e058 387 #if defined( USART_INPUT_RXPRS ) && defined( USART_TRIGCTRL_AUTOTXTEN )
Kojto 98:8ab26030e058 388 #define USART_INITSYNC_DEFAULT \
Kojto 98:8ab26030e058 389 { usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 98:8ab26030e058 390 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 98:8ab26030e058 391 1000000, /* 1 Mbits/s. */ \
Kojto 98:8ab26030e058 392 usartDatabits8, /* 8 databits. */ \
Kojto 98:8ab26030e058 393 true, /* Master mode. */ \
Kojto 98:8ab26030e058 394 false, /* Send least significant bit first. */ \
Kojto 98:8ab26030e058 395 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
Kojto 98:8ab26030e058 396 false, /* Not USART PRS input mode. */ \
Kojto 98:8ab26030e058 397 usartPrsRxCh0, /* PRS channel 0. */ \
Kojto 98:8ab26030e058 398 false /* No AUTOTX mode. */ \
Kojto 98:8ab26030e058 399 }
Kojto 98:8ab26030e058 400 #else
Kojto 98:8ab26030e058 401 #define USART_INITSYNC_DEFAULT \
Kojto 98:8ab26030e058 402 { usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 98:8ab26030e058 403 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 98:8ab26030e058 404 1000000, /* 1 Mbits/s. */ \
Kojto 98:8ab26030e058 405 usartDatabits8, /* 8 databits. */ \
Kojto 98:8ab26030e058 406 true, /* Master mode. */ \
Kojto 98:8ab26030e058 407 false, /* Send least significant bit first. */ \
Kojto 98:8ab26030e058 408 usartClockMode0 /* Clock idle low, sample on rising edge. */ \
Kojto 98:8ab26030e058 409 }
Kojto 98:8ab26030e058 410 #endif
Kojto 98:8ab26030e058 411
Kojto 98:8ab26030e058 412
Kojto 98:8ab26030e058 413 /** IrDA mode init structure. Inherited from asynchronous mode init structure */
Kojto 98:8ab26030e058 414 typedef struct
Kojto 98:8ab26030e058 415 {
Kojto 98:8ab26030e058 416 /** General Async initialization structure. */
Kojto 98:8ab26030e058 417 USART_InitAsync_TypeDef async;
Kojto 98:8ab26030e058 418
Kojto 98:8ab26030e058 419 /** Set to invert Rx signal before IrDA demodulator. */
Kojto 98:8ab26030e058 420 bool irRxInv;
Kojto 98:8ab26030e058 421
Kojto 98:8ab26030e058 422 /** Set to enable filter on IrDA demodulator. */
Kojto 98:8ab26030e058 423 bool irFilt;
Kojto 98:8ab26030e058 424
Kojto 98:8ab26030e058 425 /** Configure the pulse width generated by the IrDA modulator as a fraction
Kojto 98:8ab26030e058 426 * of the configured USART bit period. */
Kojto 98:8ab26030e058 427 USART_IrDAPw_Typedef irPw;
Kojto 98:8ab26030e058 428
Kojto 98:8ab26030e058 429 /** Enable the PRS channel selected by irPrsSel as input to IrDA module
Kojto 98:8ab26030e058 430 * instead of TX. */
Kojto 98:8ab26030e058 431 bool irPrsEn;
Kojto 98:8ab26030e058 432
Kojto 98:8ab26030e058 433 /** A PRS can be used as input to the pulse modulator instead of TX.
Kojto 98:8ab26030e058 434 * This value selects the channel to use. */
Kojto 98:8ab26030e058 435 USART_IrDAPrsSel_Typedef irPrsSel;
Kojto 98:8ab26030e058 436 } USART_InitIrDA_TypeDef;
Kojto 98:8ab26030e058 437
Kojto 98:8ab26030e058 438
Kojto 98:8ab26030e058 439 /** Default config for IrDA mode init structure. */
Kojto 98:8ab26030e058 440 #define USART_INITIRDA_DEFAULT \
Kojto 98:8ab26030e058 441 { \
Kojto 98:8ab26030e058 442 { usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 98:8ab26030e058 443 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 98:8ab26030e058 444 115200, /* 115200 bits/s. */ \
Kojto 98:8ab26030e058 445 usartOVS16, /* 16x oversampling. */ \
Kojto 98:8ab26030e058 446 usartDatabits8, /* 8 databits. */ \
Kojto 98:8ab26030e058 447 usartEvenParity, /* Even parity. */ \
Kojto 98:8ab26030e058 448 usartStopbits1 /* 1 stopbit. */ \
Kojto 98:8ab26030e058 449 }, \
Kojto 98:8ab26030e058 450 false, /* Rx invert disabled. */ \
Kojto 98:8ab26030e058 451 false, /* Filtering disabled. */ \
Kojto 98:8ab26030e058 452 usartIrDAPwTHREE, /* Pulse width is set to ONE. */ \
Kojto 98:8ab26030e058 453 false, /* Routing to PRS is disabled. */ \
Kojto 98:8ab26030e058 454 usartIrDAPrsCh0 /* PRS channel 0. */ \
Kojto 98:8ab26030e058 455 }
Kojto 98:8ab26030e058 456
Kojto 98:8ab26030e058 457
Kojto 98:8ab26030e058 458 #if defined( _USART_I2SCTRL_MASK )
Kojto 98:8ab26030e058 459 /** I2S mode init structure. Inherited from synchronous mode init structure */
Kojto 98:8ab26030e058 460 typedef struct
Kojto 98:8ab26030e058 461 {
Kojto 98:8ab26030e058 462 /** General Sync initialization structure. */
Kojto 98:8ab26030e058 463 USART_InitSync_TypeDef sync;
Kojto 98:8ab26030e058 464
Kojto 98:8ab26030e058 465 /** I2S mode. */
Kojto 98:8ab26030e058 466 USART_I2sFormat_TypeDef format;
Kojto 98:8ab26030e058 467
Kojto 98:8ab26030e058 468 /** Delay on I2S data. Set to add a one-cycle delay between a transition
Kojto 98:8ab26030e058 469 * on the word-clock and the start of the I2S word.
Kojto 98:8ab26030e058 470 * Should be set for standard I2S format. */
Kojto 98:8ab26030e058 471 bool delay;
Kojto 98:8ab26030e058 472
Kojto 98:8ab26030e058 473 /** Separate DMA Request For Left/Right Data. */
Kojto 98:8ab26030e058 474 bool dmaSplit;
Kojto 98:8ab26030e058 475
Kojto 98:8ab26030e058 476 /** Justification of I2S data within the frame */
Kojto 98:8ab26030e058 477 USART_I2sJustify_TypeDef justify;
Kojto 98:8ab26030e058 478
Kojto 98:8ab26030e058 479 /** Stero or Mono, set to true for mono. */
Kojto 98:8ab26030e058 480 bool mono;
Kojto 98:8ab26030e058 481 } USART_InitI2s_TypeDef;
Kojto 98:8ab26030e058 482
Kojto 98:8ab26030e058 483
Kojto 98:8ab26030e058 484 /** Default config for I2S mode init structure. */
Kojto 98:8ab26030e058 485 #define USART_INITI2S_DEFAULT \
Kojto 98:8ab26030e058 486 { \
Kojto 98:8ab26030e058 487 { usartEnableTx, /* Enable TX when init completed. */ \
Kojto 98:8ab26030e058 488 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 98:8ab26030e058 489 1000000, /* Baudrate 1M bits/s. */ \
Kojto 98:8ab26030e058 490 usartDatabits16, /* 16 databits. */ \
Kojto 98:8ab26030e058 491 true, /* Operate as I2S master. */ \
Kojto 98:8ab26030e058 492 true, /* Most significant bit first. */ \
Kojto 98:8ab26030e058 493 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
Kojto 98:8ab26030e058 494 false, /* Don't enable USARTRx via PRS. */ \
Kojto 98:8ab26030e058 495 usartPrsRxCh0, /* PRS channel selection (dummy). */ \
Kojto 98:8ab26030e058 496 false /* Disable AUTOTX mode. */ \
Kojto 98:8ab26030e058 497 }, \
Kojto 98:8ab26030e058 498 usartI2sFormatW16D16, /* 16-bit word, 16-bit data */ \
Kojto 98:8ab26030e058 499 true, /* Delay on I2S data. */ \
Kojto 98:8ab26030e058 500 false, /* No DMA split. */ \
Kojto 98:8ab26030e058 501 usartI2sJustifyLeft, /* Data is left-justified within the frame */ \
Kojto 98:8ab26030e058 502 false /* Stereo mode. */ \
Kojto 98:8ab26030e058 503 }
Kojto 98:8ab26030e058 504 #endif
Kojto 98:8ab26030e058 505
Kojto 98:8ab26030e058 506 /*******************************************************************************
Kojto 98:8ab26030e058 507 ***************************** PROTOTYPES **********************************
Kojto 98:8ab26030e058 508 ******************************************************************************/
Kojto 98:8ab26030e058 509
Kojto 98:8ab26030e058 510 void USART_BaudrateAsyncSet(USART_TypeDef *usart,
Kojto 98:8ab26030e058 511 uint32_t refFreq,
Kojto 98:8ab26030e058 512 uint32_t baudrate,
Kojto 98:8ab26030e058 513 USART_OVS_TypeDef ovs);
Kojto 98:8ab26030e058 514 uint32_t USART_BaudrateCalc(uint32_t refFreq,
Kojto 98:8ab26030e058 515 uint32_t clkdiv,
Kojto 98:8ab26030e058 516 bool syncmode,
Kojto 98:8ab26030e058 517 USART_OVS_TypeDef ovs);
Kojto 98:8ab26030e058 518 uint32_t USART_BaudrateGet(USART_TypeDef *usart);
Kojto 98:8ab26030e058 519 void USART_BaudrateSyncSet(USART_TypeDef *usart,
Kojto 98:8ab26030e058 520 uint32_t refFreq,
Kojto 98:8ab26030e058 521 uint32_t baudrate);
Kojto 98:8ab26030e058 522 void USART_Enable(USART_TypeDef *usart, USART_Enable_TypeDef enable);
Kojto 98:8ab26030e058 523
Kojto 98:8ab26030e058 524 void USART_InitAsync(USART_TypeDef *usart, const USART_InitAsync_TypeDef *init);
Kojto 98:8ab26030e058 525 void USART_InitSync(USART_TypeDef *usart, const USART_InitSync_TypeDef *init);
Kojto 98:8ab26030e058 526 #if defined(USART0) || ( (USART_COUNT == 1) && defined( USART1 ) )
Kojto 98:8ab26030e058 527 void USART_InitIrDA(const USART_InitIrDA_TypeDef *init);
Kojto 98:8ab26030e058 528 #endif
Kojto 98:8ab26030e058 529
Kojto 98:8ab26030e058 530 #if defined( _USART_I2SCTRL_MASK )
Kojto 98:8ab26030e058 531 void USART_InitI2s(USART_TypeDef *usart, USART_InitI2s_TypeDef *init);
Kojto 98:8ab26030e058 532 #endif
Kojto 98:8ab26030e058 533 void USART_InitPrsTrigger(USART_TypeDef *usart, const USART_PrsTriggerInit_TypeDef *init);
Kojto 98:8ab26030e058 534
Kojto 98:8ab26030e058 535
Kojto 98:8ab26030e058 536 /***************************************************************************//**
Kojto 98:8ab26030e058 537 * @brief
Kojto 98:8ab26030e058 538 * Clear one or more pending USART interrupts.
Kojto 98:8ab26030e058 539 *
Kojto 98:8ab26030e058 540 * @param[in] usart
Kojto 98:8ab26030e058 541 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 542 *
Kojto 98:8ab26030e058 543 * @param[in] flags
Kojto 98:8ab26030e058 544 * Pending USART/UART interrupt source(s) to clear. Use one or more valid
Kojto 98:8ab26030e058 545 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 546 ******************************************************************************/
Kojto 98:8ab26030e058 547 __STATIC_INLINE void USART_IntClear(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 548 {
Kojto 98:8ab26030e058 549 usart->IFC = flags;
Kojto 98:8ab26030e058 550 }
Kojto 98:8ab26030e058 551
Kojto 98:8ab26030e058 552
Kojto 98:8ab26030e058 553 /***************************************************************************//**
Kojto 98:8ab26030e058 554 * @brief
Kojto 98:8ab26030e058 555 * Disable one or more USART interrupts.
Kojto 98:8ab26030e058 556 *
Kojto 98:8ab26030e058 557 * @param[in] usart
Kojto 98:8ab26030e058 558 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 559 *
Kojto 98:8ab26030e058 560 * @param[in] flags
Kojto 98:8ab26030e058 561 * USART/UART interrupt source(s) to disable. Use one or more valid
Kojto 98:8ab26030e058 562 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 563 ******************************************************************************/
Kojto 98:8ab26030e058 564 __STATIC_INLINE void USART_IntDisable(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 565 {
Kojto 98:8ab26030e058 566 usart->IEN &= ~(flags);
Kojto 98:8ab26030e058 567 }
Kojto 98:8ab26030e058 568
Kojto 98:8ab26030e058 569
Kojto 98:8ab26030e058 570 /***************************************************************************//**
Kojto 98:8ab26030e058 571 * @brief
Kojto 98:8ab26030e058 572 * Enable one or more USART interrupts.
Kojto 98:8ab26030e058 573 *
Kojto 98:8ab26030e058 574 * @note
Kojto 98:8ab26030e058 575 * Depending on the use, a pending interrupt may already be set prior to
Kojto 98:8ab26030e058 576 * enabling the interrupt. Consider using USART_IntClear() prior to enabling
Kojto 98:8ab26030e058 577 * if such a pending interrupt should be ignored.
Kojto 98:8ab26030e058 578 *
Kojto 98:8ab26030e058 579 * @param[in] usart
Kojto 98:8ab26030e058 580 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 581 *
Kojto 98:8ab26030e058 582 * @param[in] flags
Kojto 98:8ab26030e058 583 * USART/UART interrupt source(s) to enable. Use one or more valid
Kojto 98:8ab26030e058 584 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 585 ******************************************************************************/
Kojto 98:8ab26030e058 586 __STATIC_INLINE void USART_IntEnable(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 587 {
Kojto 98:8ab26030e058 588 usart->IEN |= flags;
Kojto 98:8ab26030e058 589 }
Kojto 98:8ab26030e058 590
Kojto 98:8ab26030e058 591
Kojto 98:8ab26030e058 592 /***************************************************************************//**
Kojto 98:8ab26030e058 593 * @brief
Kojto 98:8ab26030e058 594 * Get pending USART interrupt flags.
Kojto 98:8ab26030e058 595 *
Kojto 98:8ab26030e058 596 * @note
Kojto 98:8ab26030e058 597 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 598 *
Kojto 98:8ab26030e058 599 * @param[in] usart
Kojto 98:8ab26030e058 600 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 601 *
Kojto 98:8ab26030e058 602 * @return
Kojto 98:8ab26030e058 603 * USART/UART interrupt source(s) pending. Returns one or more valid
Kojto 98:8ab26030e058 604 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 605 ******************************************************************************/
Kojto 98:8ab26030e058 606 __STATIC_INLINE uint32_t USART_IntGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 607 {
Kojto 98:8ab26030e058 608 return usart->IF;
Kojto 98:8ab26030e058 609 }
Kojto 98:8ab26030e058 610
Kojto 98:8ab26030e058 611
Kojto 98:8ab26030e058 612 /***************************************************************************//**
Kojto 98:8ab26030e058 613 * @brief
Kojto 98:8ab26030e058 614 * Get enabled and pending USART interrupt flags.
Kojto 98:8ab26030e058 615 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 98:8ab26030e058 616 *
Kojto 98:8ab26030e058 617 * @param[in] usart
Kojto 98:8ab26030e058 618 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 619 *
Kojto 98:8ab26030e058 620 * @note
Kojto 98:8ab26030e058 621 * Interrupt flags are not cleared by the use of this function.
Kojto 98:8ab26030e058 622 *
Kojto 98:8ab26030e058 623 * @return
Kojto 98:8ab26030e058 624 * Pending and enabled USART interrupt sources.
Kojto 98:8ab26030e058 625 * The return value is the bitwise AND combination of
Kojto 98:8ab26030e058 626 * - the OR combination of enabled interrupt sources in USARTx_IEN_nnn
Kojto 98:8ab26030e058 627 * register (USARTx_IEN_nnn) and
Kojto 98:8ab26030e058 628 * - the OR combination of valid interrupt flags of the USART module
Kojto 98:8ab26030e058 629 * (USARTx_IF_nnn).
Kojto 98:8ab26030e058 630 ******************************************************************************/
Kojto 98:8ab26030e058 631 __STATIC_INLINE uint32_t USART_IntGetEnabled(USART_TypeDef *usart)
Kojto 98:8ab26030e058 632 {
Kojto 98:8ab26030e058 633 uint32_t tmp;
Kojto 98:8ab26030e058 634
Kojto 98:8ab26030e058 635 /* Store USARTx->IEN in temporary variable in order to define explicit order
Kojto 98:8ab26030e058 636 * of volatile accesses. */
Kojto 98:8ab26030e058 637 tmp = usart->IEN;
Kojto 98:8ab26030e058 638
Kojto 98:8ab26030e058 639 /* Bitwise AND of pending and enabled interrupts */
Kojto 98:8ab26030e058 640 return usart->IF & tmp;
Kojto 98:8ab26030e058 641 }
Kojto 98:8ab26030e058 642
Kojto 98:8ab26030e058 643
Kojto 98:8ab26030e058 644 /***************************************************************************//**
Kojto 98:8ab26030e058 645 * @brief
Kojto 98:8ab26030e058 646 * Set one or more pending USART interrupts from SW.
Kojto 98:8ab26030e058 647 *
Kojto 98:8ab26030e058 648 * @param[in] usart
Kojto 98:8ab26030e058 649 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 650 *
Kojto 98:8ab26030e058 651 * @param[in] flags
Kojto 98:8ab26030e058 652 * USART/UART interrupt source(s) to set to pending. Use one or more valid
Kojto 98:8ab26030e058 653 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 654 ******************************************************************************/
Kojto 98:8ab26030e058 655 __STATIC_INLINE void USART_IntSet(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 656 {
Kojto 98:8ab26030e058 657 usart->IFS = flags;
Kojto 98:8ab26030e058 658 }
Kojto 98:8ab26030e058 659
Kojto 98:8ab26030e058 660
Kojto 98:8ab26030e058 661 /***************************************************************************//**
Kojto 98:8ab26030e058 662 * @brief
Kojto 98:8ab26030e058 663 * Get USART STATUS register.
Kojto 98:8ab26030e058 664 *
Kojto 98:8ab26030e058 665 * @param[in] usart
Kojto 98:8ab26030e058 666 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 667 *
Kojto 98:8ab26030e058 668 * @return
Kojto 98:8ab26030e058 669 * STATUS register value.
Kojto 98:8ab26030e058 670 *
Kojto 98:8ab26030e058 671 ******************************************************************************/
Kojto 98:8ab26030e058 672 static __INLINE uint32_t USART_StatusGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 673 {
Kojto 98:8ab26030e058 674 return usart->STATUS;
Kojto 98:8ab26030e058 675 }
Kojto 98:8ab26030e058 676
Kojto 98:8ab26030e058 677 void USART_Reset(USART_TypeDef *usart);
Kojto 98:8ab26030e058 678 uint8_t USART_Rx(USART_TypeDef *usart);
Kojto 98:8ab26030e058 679 uint16_t USART_RxDouble(USART_TypeDef *usart);
Kojto 98:8ab26030e058 680 uint32_t USART_RxDoubleExt(USART_TypeDef *usart);
Kojto 98:8ab26030e058 681 uint16_t USART_RxExt(USART_TypeDef *usart);
Kojto 98:8ab26030e058 682
Kojto 98:8ab26030e058 683
Kojto 98:8ab26030e058 684 /***************************************************************************//**
Kojto 98:8ab26030e058 685 * @brief
Kojto 98:8ab26030e058 686 * Receive one 4-8 bit frame, (or part of 10-16 bit frame).
Kojto 98:8ab26030e058 687 *
Kojto 98:8ab26030e058 688 * @details
Kojto 98:8ab26030e058 689 * This function is used to quickly receive one 4-8 bits frame by reading the
Kojto 98:8ab26030e058 690 * RXDATA register directly, without checking the STATUS register for the
Kojto 98:8ab26030e058 691 * RXDATAV flag. This can be useful from the RXDATAV interrupt handler,
Kojto 98:8ab26030e058 692 * i.e. waiting is superfluous, in order to quickly read the received data.
Kojto 98:8ab26030e058 693 * Please refer to @ref USART_RxDataXGet() for reception of 9 bit frames.
Kojto 98:8ab26030e058 694 *
Kojto 98:8ab26030e058 695 * @note
Kojto 98:8ab26030e058 696 * Since this function does not check whether the RXDATA register actually
Kojto 98:8ab26030e058 697 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 698 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 699 * like when handling an RXDATAV interrupt. The @ref USART_Rx() is normally a
Kojto 98:8ab26030e058 700 * better choice if the validity of the RXDATA register is not certain.
Kojto 98:8ab26030e058 701 *
Kojto 98:8ab26030e058 702 * @note
Kojto 98:8ab26030e058 703 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 704 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 705 *
Kojto 98:8ab26030e058 706 * @param[in] usart
Kojto 98:8ab26030e058 707 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 708 *
Kojto 98:8ab26030e058 709 * @return
Kojto 98:8ab26030e058 710 * Data received.
Kojto 98:8ab26030e058 711 ******************************************************************************/
Kojto 98:8ab26030e058 712 static __INLINE uint8_t USART_RxDataGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 713 {
Kojto 98:8ab26030e058 714 return (uint8_t) (usart->RXDATA);
Kojto 98:8ab26030e058 715 }
Kojto 98:8ab26030e058 716
Kojto 98:8ab26030e058 717
Kojto 98:8ab26030e058 718 /***************************************************************************//**
Kojto 98:8ab26030e058 719 * @brief
Kojto 98:8ab26030e058 720 * Receive two 4-8 bit frames, or one 10-16 bit frame.
Kojto 98:8ab26030e058 721 *
Kojto 98:8ab26030e058 722 * @details
Kojto 98:8ab26030e058 723 * This function is used to quickly receive one 10-16 bits frame or two 4-8
Kojto 98:8ab26030e058 724 * bit frames by reading the RXDOUBLE register directly, without checking
Kojto 98:8ab26030e058 725 * the STATUS register for the RXDATAV flag. This can be useful from the
Kojto 98:8ab26030e058 726 * RXDATAV interrupt handler, i.e. waiting is superfluous, in order to
Kojto 98:8ab26030e058 727 * quickly read the received data.
Kojto 98:8ab26030e058 728 * This function is normally used to receive one frame when operating with
Kojto 98:8ab26030e058 729 * frame length 10-16 bits. Please refer to @ref USART_RxDoubleXGet()
Kojto 98:8ab26030e058 730 * for reception of two 9 bit frames.
Kojto 98:8ab26030e058 731 *
Kojto 98:8ab26030e058 732 * @note
Kojto 98:8ab26030e058 733 * Since this function does not check whether the RXDOUBLE register actually
Kojto 98:8ab26030e058 734 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 735 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 736 * like when handling an RXDATAV interrupt. The @ref USART_RxDouble() is
Kojto 98:8ab26030e058 737 * normally a better choice if the validity of the RXDOUBLE register is not
Kojto 98:8ab26030e058 738 * certain.
Kojto 98:8ab26030e058 739 *
Kojto 98:8ab26030e058 740 * @note
Kojto 98:8ab26030e058 741 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 742 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 743 *
Kojto 98:8ab26030e058 744 * @param[in] usart
Kojto 98:8ab26030e058 745 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 746 *
Kojto 98:8ab26030e058 747 * @return
Kojto 98:8ab26030e058 748 * Data received.
Kojto 98:8ab26030e058 749 ******************************************************************************/
Kojto 98:8ab26030e058 750 static __INLINE uint16_t USART_RxDoubleGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 751 {
Kojto 98:8ab26030e058 752 return (uint16_t) (usart->RXDOUBLE);
Kojto 98:8ab26030e058 753 }
Kojto 98:8ab26030e058 754
Kojto 98:8ab26030e058 755
Kojto 98:8ab26030e058 756 /***************************************************************************//**
Kojto 98:8ab26030e058 757 * @brief
Kojto 98:8ab26030e058 758 * Receive two 4-9 bit frames, or one 10-16 bit frame with extended
Kojto 98:8ab26030e058 759 * information.
Kojto 98:8ab26030e058 760 *
Kojto 98:8ab26030e058 761 * @details
Kojto 98:8ab26030e058 762 * This function is used to quickly receive one 10-16 bits frame or two 4-9
Kojto 98:8ab26030e058 763 * bit frames by reading the RXDOUBLEX register directly, without checking
Kojto 98:8ab26030e058 764 * the STATUS register for the RXDATAV flag. This can be useful from the
Kojto 98:8ab26030e058 765 * RXDATAV interrupt handler, i.e. waiting is superfluous, in order to
Kojto 98:8ab26030e058 766 * quickly read the received data.
Kojto 98:8ab26030e058 767 *
Kojto 98:8ab26030e058 768 * @note
Kojto 98:8ab26030e058 769 * Since this function does not check whether the RXDOUBLEX register actually
Kojto 98:8ab26030e058 770 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 771 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 772 * like when handling an RXDATAV interrupt. The @ref USART_RxDoubleExt() is
Kojto 98:8ab26030e058 773 * normally a better choice if the validity of the RXDOUBLEX register is not
Kojto 98:8ab26030e058 774 * certain.
Kojto 98:8ab26030e058 775 *
Kojto 98:8ab26030e058 776 * @note
Kojto 98:8ab26030e058 777 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 778 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 779 *
Kojto 98:8ab26030e058 780 * @param[in] usart
Kojto 98:8ab26030e058 781 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 782 *
Kojto 98:8ab26030e058 783 * @return
Kojto 98:8ab26030e058 784 * Data received.
Kojto 98:8ab26030e058 785 ******************************************************************************/
Kojto 98:8ab26030e058 786 static __INLINE uint32_t USART_RxDoubleXGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 787 {
Kojto 98:8ab26030e058 788 return usart->RXDOUBLEX;
Kojto 98:8ab26030e058 789 }
Kojto 98:8ab26030e058 790
Kojto 98:8ab26030e058 791
Kojto 98:8ab26030e058 792 /***************************************************************************//**
Kojto 98:8ab26030e058 793 * @brief
Kojto 98:8ab26030e058 794 * Receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended
Kojto 98:8ab26030e058 795 * information.
Kojto 98:8ab26030e058 796 *
Kojto 98:8ab26030e058 797 * @details
Kojto 98:8ab26030e058 798 * This function is used to quickly receive one 4-9 bit frame, (or part of
Kojto 98:8ab26030e058 799 * 10-16 bit frame) with extended information by reading the RXDATAX register
Kojto 98:8ab26030e058 800 * directly, without checking the STATUS register for the RXDATAV flag. This
Kojto 98:8ab26030e058 801 * can be useful from the RXDATAV interrupt handler, i.e. waiting is
Kojto 98:8ab26030e058 802 * superfluous, in order to quickly read the received data.
Kojto 98:8ab26030e058 803 *
Kojto 98:8ab26030e058 804 * @note
Kojto 98:8ab26030e058 805 * Since this function does not check whether the RXDATAX register actually
Kojto 98:8ab26030e058 806 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 807 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 808 * like when handling an RXDATAV interrupt. The @ref USART_RxExt() is normally
Kojto 98:8ab26030e058 809 * a better choice if the validity of the RXDATAX register is not certain.
Kojto 98:8ab26030e058 810 *
Kojto 98:8ab26030e058 811 * @note
Kojto 98:8ab26030e058 812 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 813 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 814 *
Kojto 98:8ab26030e058 815 * @param[in] usart
Kojto 98:8ab26030e058 816 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 817 *
Kojto 98:8ab26030e058 818 * @return
Kojto 98:8ab26030e058 819 * Data received.
Kojto 98:8ab26030e058 820 ******************************************************************************/
Kojto 98:8ab26030e058 821 static __INLINE uint16_t USART_RxDataXGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 822 {
Kojto 98:8ab26030e058 823 return (uint16_t) (usart->RXDATAX);
Kojto 98:8ab26030e058 824 }
Kojto 98:8ab26030e058 825
Kojto 98:8ab26030e058 826 uint8_t USART_SpiTransfer(USART_TypeDef *usart, uint8_t data);
Kojto 98:8ab26030e058 827 void USART_Tx(USART_TypeDef *usart, uint8_t data);
Kojto 98:8ab26030e058 828 void USART_TxDouble(USART_TypeDef *usart, uint16_t data);
Kojto 98:8ab26030e058 829 void USART_TxDoubleExt(USART_TypeDef *usart, uint32_t data);
Kojto 98:8ab26030e058 830 void USART_TxExt(USART_TypeDef *usart, uint16_t data);
Kojto 98:8ab26030e058 831
Kojto 98:8ab26030e058 832
Kojto 98:8ab26030e058 833 /** @} (end addtogroup USART) */
Kojto 98:8ab26030e058 834 /** @} (end addtogroup EM_Library) */
Kojto 98:8ab26030e058 835
Kojto 98:8ab26030e058 836 #ifdef __cplusplus
Kojto 98:8ab26030e058 837 }
Kojto 98:8ab26030e058 838 #endif
Kojto 98:8ab26030e058 839
Kojto 98:8ab26030e058 840 #endif /* defined(USART_COUNT) && (USART_COUNT > 0) */
Kojto 98:8ab26030e058 841 #endif /* __SILICON_LABS_EM_USART_H_ */