mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
Kojto
Date:
Tue Feb 02 14:43:35 2016 +0000
Revision:
113:f141b2784e32
Parent:
98:8ab26030e058
Child:
128:9bcdf88f62b0
Release 113 of the mbed library

Changes:
- new targets - Silabs Perl Gecko, TY51822
- Silabs - emlib update to 4.1.0, various bugfixes as result
- STM B96B_F446VE - add async serial support
- Freescale KLXX - rtc lock fix
- LPC11U68 and LPC1549 - pwm bugfixes - duty cycle

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 113:f141b2784e32 5 * @version 4.2.1
Kojto 98:8ab26030e058 6 *******************************************************************************
Kojto 98:8ab26030e058 7 * @section License
Kojto 113:f141b2784e32 8 * <b>(C) Copyright 2015 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 113:f141b2784e32 35 #ifndef __SILICON_LABS_EM_USART_H__
Kojto 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 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 113:f141b2784e32 287 #if defined(_USART_TIMING_CSHOLD_MASK)
Kojto 113:f141b2784e32 288 /** Auto CS enabling */
Kojto 113:f141b2784e32 289 bool autoCsEnable;
Kojto 113:f141b2784e32 290 /** Auto CS hold time in baud cycles */
Kojto 113:f141b2784e32 291 uint8_t autoCsHold;
Kojto 113:f141b2784e32 292 /** Auto CS setup time in baud cycles */
Kojto 113:f141b2784e32 293 uint8_t autoCsSetup;
Kojto 113:f141b2784e32 294 #endif
Kojto 98:8ab26030e058 295 } USART_InitAsync_TypeDef;
Kojto 98:8ab26030e058 296
Kojto 98:8ab26030e058 297 /** USART PRS trigger enable */
Kojto 98:8ab26030e058 298 typedef struct
Kojto 98:8ab26030e058 299 {
Kojto 113:f141b2784e32 300 #if defined(USART_TRIGCTRL_AUTOTXTEN)
Kojto 98:8ab26030e058 301 /** Enable AUTOTX */
Kojto 98:8ab26030e058 302 bool autoTxTriggerEnable;
Kojto 98:8ab26030e058 303 #endif
Kojto 98:8ab26030e058 304 /** Trigger receive via PRS channel */
Kojto 98:8ab26030e058 305 bool rxTriggerEnable;
Kojto 98:8ab26030e058 306 /** Trigger transmit via PRS channel */
Kojto 98:8ab26030e058 307 bool txTriggerEnable;
Kojto 98:8ab26030e058 308 /** PRS channel to be used to trigger auto transmission */
Kojto 98:8ab26030e058 309 USART_PrsTriggerCh_TypeDef prsTriggerChannel;
Kojto 98:8ab26030e058 310 } USART_PrsTriggerInit_TypeDef;
Kojto 98:8ab26030e058 311
Kojto 98:8ab26030e058 312 /** Default config for USART async init structure. */
Kojto 113:f141b2784e32 313 #if defined(_USART_TIMING_CSHOLD_MASK) && defined(USART_CTRL_MVDIS)
Kojto 113:f141b2784e32 314 #define USART_INITASYNC_DEFAULT \
Kojto 113:f141b2784e32 315 { \
Kojto 113:f141b2784e32 316 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 317 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 318 115200, /* 115200 bits/s. */ \
Kojto 113:f141b2784e32 319 usartOVS16, /* 16x oversampling. */ \
Kojto 113:f141b2784e32 320 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 321 usartNoParity, /* No parity. */ \
Kojto 113:f141b2784e32 322 usartStopbits1, /* 1 stopbit. */ \
Kojto 113:f141b2784e32 323 false, /* Do not disable majority vote. */ \
Kojto 113:f141b2784e32 324 false, /* Not USART PRS input mode. */ \
Kojto 113:f141b2784e32 325 usartPrsRxCh0, /* PRS channel 0. */ \
Kojto 113:f141b2784e32 326 false, /* Auto CS functionality enable/disable switch */ \
Kojto 113:f141b2784e32 327 0, /* Auto CS Hold cycles */ \
Kojto 113:f141b2784e32 328 0 /* Auto CS Setup cycles */ \
Kojto 113:f141b2784e32 329 }
Kojto 113:f141b2784e32 330 #elif defined(USART_INPUT_RXPRS) && defined(USART_CTRL_MVDIS)
Kojto 113:f141b2784e32 331 #define USART_INITASYNC_DEFAULT \
Kojto 113:f141b2784e32 332 { \
Kojto 113:f141b2784e32 333 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 334 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 335 115200, /* 115200 bits/s. */ \
Kojto 113:f141b2784e32 336 usartOVS16, /* 16x oversampling. */ \
Kojto 113:f141b2784e32 337 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 338 usartNoParity, /* No parity. */ \
Kojto 113:f141b2784e32 339 usartStopbits1, /* 1 stopbit. */ \
Kojto 113:f141b2784e32 340 false, /* Do not disable majority vote. */ \
Kojto 113:f141b2784e32 341 false, /* Not USART PRS input mode. */ \
Kojto 113:f141b2784e32 342 usartPrsRxCh0 /* PRS channel 0. */ \
Kojto 113:f141b2784e32 343 }
Kojto 98:8ab26030e058 344 #else
Kojto 113:f141b2784e32 345 #define USART_INITASYNC_DEFAULT \
Kojto 113:f141b2784e32 346 { \
Kojto 113:f141b2784e32 347 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 348 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 349 115200, /* 115200 bits/s. */ \
Kojto 113:f141b2784e32 350 usartOVS16, /* 16x oversampling. */ \
Kojto 113:f141b2784e32 351 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 352 usartNoParity, /* No parity. */ \
Kojto 113:f141b2784e32 353 usartStopbits1 /* 1 stopbit. */ \
Kojto 113:f141b2784e32 354 }
Kojto 98:8ab26030e058 355 #endif
Kojto 98:8ab26030e058 356
Kojto 98:8ab26030e058 357 /** Default config for USART PRS triggering structure. */
Kojto 113:f141b2784e32 358 #if defined(USART_TRIGCTRL_AUTOTXTEN)
Kojto 113:f141b2784e32 359 #define USART_INITPRSTRIGGER_DEFAULT \
Kojto 113:f141b2784e32 360 { \
Kojto 113:f141b2784e32 361 false, /* Do not enable autoTX triggering. */ \
Kojto 113:f141b2784e32 362 false, /* Do not enable receive triggering. */ \
Kojto 113:f141b2784e32 363 false, /* Do not enable transmit triggering. */ \
Kojto 113:f141b2784e32 364 usartPrsTriggerCh0 /* Set default channel to zero. */ \
Kojto 113:f141b2784e32 365 }
Kojto 98:8ab26030e058 366 #else
Kojto 113:f141b2784e32 367 #define USART_INITPRSTRIGGER_DEFAULT \
Kojto 113:f141b2784e32 368 { \
Kojto 113:f141b2784e32 369 false, /* Do not enable receive triggering. */ \
Kojto 113:f141b2784e32 370 false, /* Do not enable transmit triggering. */ \
Kojto 113:f141b2784e32 371 usartPrsTriggerCh0 /* Set default channel to zero. */ \
Kojto 113:f141b2784e32 372 }
Kojto 98:8ab26030e058 373 #endif
Kojto 98:8ab26030e058 374
Kojto 98:8ab26030e058 375 /** Synchronous mode init structure. */
Kojto 98:8ab26030e058 376 typedef struct
Kojto 98:8ab26030e058 377 {
Kojto 98:8ab26030e058 378 /** Specifies whether TX and/or RX shall be enabled when init completed. */
Kojto 98:8ab26030e058 379 USART_Enable_TypeDef enable;
Kojto 98:8ab26030e058 380
Kojto 98:8ab26030e058 381 /**
Kojto 98:8ab26030e058 382 * USART/UART reference clock assumed when configuring baudrate setup. Set
Kojto 98:8ab26030e058 383 * it to 0 if currently configurated reference clock shall be used.
Kojto 98:8ab26030e058 384 */
Kojto 98:8ab26030e058 385 uint32_t refFreq;
Kojto 98:8ab26030e058 386
Kojto 98:8ab26030e058 387 /** Desired baudrate. */
Kojto 98:8ab26030e058 388 uint32_t baudrate;
Kojto 98:8ab26030e058 389
Kojto 98:8ab26030e058 390 /** Number of databits in frame. */
Kojto 98:8ab26030e058 391 USART_Databits_TypeDef databits;
Kojto 98:8ab26030e058 392
Kojto 98:8ab26030e058 393 /** Select if to operate in master or slave mode. */
Kojto 98:8ab26030e058 394 bool master;
Kojto 98:8ab26030e058 395
Kojto 98:8ab26030e058 396 /** Select if to send most or least significant bit first. */
Kojto 98:8ab26030e058 397 bool msbf;
Kojto 98:8ab26030e058 398
Kojto 98:8ab26030e058 399 /** Clock polarity/phase mode. */
Kojto 98:8ab26030e058 400 USART_ClockMode_TypeDef clockMode;
Kojto 98:8ab26030e058 401
Kojto 113:f141b2784e32 402 #if defined(USART_INPUT_RXPRS) && defined(USART_TRIGCTRL_AUTOTXTEN)
Kojto 98:8ab26030e058 403 /** Enable USART Rx via PRS. */
Kojto 98:8ab26030e058 404 bool prsRxEnable;
Kojto 98:8ab26030e058 405
Kojto 98:8ab26030e058 406 /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
Kojto 98:8ab26030e058 407 USART_PrsRxCh_TypeDef prsRxCh;
Kojto 98:8ab26030e058 408
Kojto 98:8ab26030e058 409 /** Enable AUTOTX mode. Transmits as long as RX is not full.
Kojto 98:8ab26030e058 410 * If TX is empty, underflows are generated. */
Kojto 98:8ab26030e058 411 bool autoTx;
Kojto 98:8ab26030e058 412 #endif
Kojto 113:f141b2784e32 413 #if defined(_USART_TIMING_CSHOLD_MASK)
Kojto 113:f141b2784e32 414 /** Auto CS enabling */
Kojto 113:f141b2784e32 415 bool autoCsEnable;
Kojto 113:f141b2784e32 416 /** Auto CS hold time in baud cycles */
Kojto 113:f141b2784e32 417 uint8_t autoCsHold;
Kojto 113:f141b2784e32 418 /** Auto CS setup time in baud cycles */
Kojto 113:f141b2784e32 419 uint8_t autoCsSetup;
Kojto 113:f141b2784e32 420 #endif
Kojto 98:8ab26030e058 421 } USART_InitSync_TypeDef;
Kojto 98:8ab26030e058 422
Kojto 98:8ab26030e058 423 /** Default config for USART sync init structure. */
Kojto 113:f141b2784e32 424 #if defined(_USART_TIMING_CSHOLD_MASK)
Kojto 113:f141b2784e32 425 #define USART_INITSYNC_DEFAULT \
Kojto 113:f141b2784e32 426 { \
Kojto 113:f141b2784e32 427 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 428 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 429 1000000, /* 1 Mbits/s. */ \
Kojto 113:f141b2784e32 430 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 431 true, /* Master mode. */ \
Kojto 113:f141b2784e32 432 false, /* Send least significant bit first. */ \
Kojto 113:f141b2784e32 433 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
Kojto 113:f141b2784e32 434 false, /* Not USART PRS input mode. */ \
Kojto 113:f141b2784e32 435 usartPrsRxCh0, /* PRS channel 0. */ \
Kojto 113:f141b2784e32 436 false, /* No AUTOTX mode. */ \
Kojto 113:f141b2784e32 437 false, /* No AUTOCS mode */ \
Kojto 113:f141b2784e32 438 0, /* Auto CS Hold cycles */ \
Kojto 113:f141b2784e32 439 0 /* Auto CS Setup cycles */ \
Kojto 113:f141b2784e32 440 }
Kojto 113:f141b2784e32 441 #elif defined(USART_INPUT_RXPRS) && defined(USART_TRIGCTRL_AUTOTXTEN)
Kojto 113:f141b2784e32 442 #define USART_INITSYNC_DEFAULT \
Kojto 113:f141b2784e32 443 { \
Kojto 113:f141b2784e32 444 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 445 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 446 1000000, /* 1 Mbits/s. */ \
Kojto 113:f141b2784e32 447 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 448 true, /* Master mode. */ \
Kojto 113:f141b2784e32 449 false, /* Send least significant bit first. */ \
Kojto 113:f141b2784e32 450 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
Kojto 113:f141b2784e32 451 false, /* Not USART PRS input mode. */ \
Kojto 113:f141b2784e32 452 usartPrsRxCh0, /* PRS channel 0. */ \
Kojto 113:f141b2784e32 453 false /* No AUTOTX mode. */ \
Kojto 113:f141b2784e32 454 }
Kojto 98:8ab26030e058 455 #else
Kojto 113:f141b2784e32 456 #define USART_INITSYNC_DEFAULT \
Kojto 113:f141b2784e32 457 { \
Kojto 113:f141b2784e32 458 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 459 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 460 1000000, /* 1 Mbits/s. */ \
Kojto 113:f141b2784e32 461 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 462 true, /* Master mode. */ \
Kojto 113:f141b2784e32 463 false, /* Send least significant bit first. */ \
Kojto 113:f141b2784e32 464 usartClockMode0 /* Clock idle low, sample on rising edge. */ \
Kojto 113:f141b2784e32 465 }
Kojto 98:8ab26030e058 466 #endif
Kojto 98:8ab26030e058 467
Kojto 98:8ab26030e058 468
Kojto 98:8ab26030e058 469 /** IrDA mode init structure. Inherited from asynchronous mode init structure */
Kojto 98:8ab26030e058 470 typedef struct
Kojto 98:8ab26030e058 471 {
Kojto 98:8ab26030e058 472 /** General Async initialization structure. */
Kojto 98:8ab26030e058 473 USART_InitAsync_TypeDef async;
Kojto 98:8ab26030e058 474
Kojto 98:8ab26030e058 475 /** Set to invert Rx signal before IrDA demodulator. */
Kojto 98:8ab26030e058 476 bool irRxInv;
Kojto 98:8ab26030e058 477
Kojto 98:8ab26030e058 478 /** Set to enable filter on IrDA demodulator. */
Kojto 98:8ab26030e058 479 bool irFilt;
Kojto 98:8ab26030e058 480
Kojto 98:8ab26030e058 481 /** Configure the pulse width generated by the IrDA modulator as a fraction
Kojto 98:8ab26030e058 482 * of the configured USART bit period. */
Kojto 98:8ab26030e058 483 USART_IrDAPw_Typedef irPw;
Kojto 98:8ab26030e058 484
Kojto 98:8ab26030e058 485 /** Enable the PRS channel selected by irPrsSel as input to IrDA module
Kojto 98:8ab26030e058 486 * instead of TX. */
Kojto 98:8ab26030e058 487 bool irPrsEn;
Kojto 98:8ab26030e058 488
Kojto 98:8ab26030e058 489 /** A PRS can be used as input to the pulse modulator instead of TX.
Kojto 98:8ab26030e058 490 * This value selects the channel to use. */
Kojto 98:8ab26030e058 491 USART_IrDAPrsSel_Typedef irPrsSel;
Kojto 98:8ab26030e058 492 } USART_InitIrDA_TypeDef;
Kojto 98:8ab26030e058 493
Kojto 98:8ab26030e058 494
Kojto 98:8ab26030e058 495 /** Default config for IrDA mode init structure. */
Kojto 113:f141b2784e32 496 #define USART_INITIRDA_DEFAULT \
Kojto 113:f141b2784e32 497 { \
Kojto 113:f141b2784e32 498 { \
Kojto 113:f141b2784e32 499 usartEnable, /* Enable RX/TX when init completed. */ \
Kojto 113:f141b2784e32 500 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 501 115200, /* 115200 bits/s. */ \
Kojto 113:f141b2784e32 502 usartOVS16, /* 16x oversampling. */ \
Kojto 113:f141b2784e32 503 usartDatabits8, /* 8 databits. */ \
Kojto 113:f141b2784e32 504 usartEvenParity, /* Even parity. */ \
Kojto 113:f141b2784e32 505 usartStopbits1 /* 1 stopbit. */ \
Kojto 113:f141b2784e32 506 }, \
Kojto 113:f141b2784e32 507 false, /* Rx invert disabled. */ \
Kojto 113:f141b2784e32 508 false, /* Filtering disabled. */ \
Kojto 113:f141b2784e32 509 usartIrDAPwTHREE, /* Pulse width is set to ONE. */ \
Kojto 113:f141b2784e32 510 false, /* Routing to PRS is disabled. */ \
Kojto 113:f141b2784e32 511 usartIrDAPrsCh0 /* PRS channel 0. */ \
Kojto 113:f141b2784e32 512 }
Kojto 98:8ab26030e058 513
Kojto 98:8ab26030e058 514
Kojto 113:f141b2784e32 515 #if defined(_USART_I2SCTRL_MASK)
Kojto 98:8ab26030e058 516 /** I2S mode init structure. Inherited from synchronous mode init structure */
Kojto 98:8ab26030e058 517 typedef struct
Kojto 98:8ab26030e058 518 {
Kojto 98:8ab26030e058 519 /** General Sync initialization structure. */
Kojto 98:8ab26030e058 520 USART_InitSync_TypeDef sync;
Kojto 98:8ab26030e058 521
Kojto 98:8ab26030e058 522 /** I2S mode. */
Kojto 98:8ab26030e058 523 USART_I2sFormat_TypeDef format;
Kojto 98:8ab26030e058 524
Kojto 98:8ab26030e058 525 /** Delay on I2S data. Set to add a one-cycle delay between a transition
Kojto 98:8ab26030e058 526 * on the word-clock and the start of the I2S word.
Kojto 98:8ab26030e058 527 * Should be set for standard I2S format. */
Kojto 98:8ab26030e058 528 bool delay;
Kojto 98:8ab26030e058 529
Kojto 98:8ab26030e058 530 /** Separate DMA Request For Left/Right Data. */
Kojto 98:8ab26030e058 531 bool dmaSplit;
Kojto 98:8ab26030e058 532
Kojto 98:8ab26030e058 533 /** Justification of I2S data within the frame */
Kojto 98:8ab26030e058 534 USART_I2sJustify_TypeDef justify;
Kojto 98:8ab26030e058 535
Kojto 98:8ab26030e058 536 /** Stero or Mono, set to true for mono. */
Kojto 98:8ab26030e058 537 bool mono;
Kojto 98:8ab26030e058 538 } USART_InitI2s_TypeDef;
Kojto 98:8ab26030e058 539
Kojto 98:8ab26030e058 540
Kojto 98:8ab26030e058 541 /** Default config for I2S mode init structure. */
Kojto 113:f141b2784e32 542 #define USART_INITI2S_DEFAULT \
Kojto 113:f141b2784e32 543 { \
Kojto 113:f141b2784e32 544 { \
Kojto 113:f141b2784e32 545 usartEnableTx, /* Enable TX when init completed. */ \
Kojto 113:f141b2784e32 546 0, /* Use current configured reference clock for configuring baudrate. */ \
Kojto 113:f141b2784e32 547 1000000, /* Baudrate 1M bits/s. */ \
Kojto 113:f141b2784e32 548 usartDatabits16, /* 16 databits. */ \
Kojto 113:f141b2784e32 549 true, /* Operate as I2S master. */ \
Kojto 113:f141b2784e32 550 true, /* Most significant bit first. */ \
Kojto 113:f141b2784e32 551 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
Kojto 113:f141b2784e32 552 false, /* Don't enable USARTRx via PRS. */ \
Kojto 113:f141b2784e32 553 usartPrsRxCh0, /* PRS channel selection (dummy). */ \
Kojto 113:f141b2784e32 554 false /* Disable AUTOTX mode. */ \
Kojto 113:f141b2784e32 555 }, \
Kojto 113:f141b2784e32 556 usartI2sFormatW16D16, /* 16-bit word, 16-bit data */ \
Kojto 113:f141b2784e32 557 true, /* Delay on I2S data. */ \
Kojto 113:f141b2784e32 558 false, /* No DMA split. */ \
Kojto 113:f141b2784e32 559 usartI2sJustifyLeft, /* Data is left-justified within the frame */ \
Kojto 113:f141b2784e32 560 false /* Stereo mode. */ \
Kojto 113:f141b2784e32 561 }
Kojto 98:8ab26030e058 562 #endif
Kojto 98:8ab26030e058 563
Kojto 98:8ab26030e058 564 /*******************************************************************************
Kojto 98:8ab26030e058 565 ***************************** PROTOTYPES **********************************
Kojto 98:8ab26030e058 566 ******************************************************************************/
Kojto 98:8ab26030e058 567
Kojto 98:8ab26030e058 568 void USART_BaudrateAsyncSet(USART_TypeDef *usart,
Kojto 98:8ab26030e058 569 uint32_t refFreq,
Kojto 98:8ab26030e058 570 uint32_t baudrate,
Kojto 98:8ab26030e058 571 USART_OVS_TypeDef ovs);
Kojto 98:8ab26030e058 572 uint32_t USART_BaudrateCalc(uint32_t refFreq,
Kojto 98:8ab26030e058 573 uint32_t clkdiv,
Kojto 98:8ab26030e058 574 bool syncmode,
Kojto 98:8ab26030e058 575 USART_OVS_TypeDef ovs);
Kojto 98:8ab26030e058 576 uint32_t USART_BaudrateGet(USART_TypeDef *usart);
Kojto 98:8ab26030e058 577 void USART_BaudrateSyncSet(USART_TypeDef *usart,
Kojto 98:8ab26030e058 578 uint32_t refFreq,
Kojto 98:8ab26030e058 579 uint32_t baudrate);
Kojto 98:8ab26030e058 580 void USART_Enable(USART_TypeDef *usart, USART_Enable_TypeDef enable);
Kojto 98:8ab26030e058 581
Kojto 98:8ab26030e058 582 void USART_InitAsync(USART_TypeDef *usart, const USART_InitAsync_TypeDef *init);
Kojto 98:8ab26030e058 583 void USART_InitSync(USART_TypeDef *usart, const USART_InitSync_TypeDef *init);
Kojto 113:f141b2784e32 584 #if defined(USART0) || ((USART_COUNT == 1) && defined(USART1))
Kojto 98:8ab26030e058 585 void USART_InitIrDA(const USART_InitIrDA_TypeDef *init);
Kojto 98:8ab26030e058 586 #endif
Kojto 98:8ab26030e058 587
Kojto 113:f141b2784e32 588 #if defined(_USART_I2SCTRL_MASK)
Kojto 98:8ab26030e058 589 void USART_InitI2s(USART_TypeDef *usart, USART_InitI2s_TypeDef *init);
Kojto 98:8ab26030e058 590 #endif
Kojto 98:8ab26030e058 591 void USART_InitPrsTrigger(USART_TypeDef *usart, const USART_PrsTriggerInit_TypeDef *init);
Kojto 98:8ab26030e058 592
Kojto 98:8ab26030e058 593
Kojto 98:8ab26030e058 594 /***************************************************************************//**
Kojto 98:8ab26030e058 595 * @brief
Kojto 98:8ab26030e058 596 * Clear one or more pending USART interrupts.
Kojto 98:8ab26030e058 597 *
Kojto 98:8ab26030e058 598 * @param[in] usart
Kojto 98:8ab26030e058 599 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 600 *
Kojto 98:8ab26030e058 601 * @param[in] flags
Kojto 98:8ab26030e058 602 * Pending USART/UART interrupt source(s) to clear. Use one or more valid
Kojto 98:8ab26030e058 603 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 604 ******************************************************************************/
Kojto 98:8ab26030e058 605 __STATIC_INLINE void USART_IntClear(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 606 {
Kojto 98:8ab26030e058 607 usart->IFC = flags;
Kojto 98:8ab26030e058 608 }
Kojto 98:8ab26030e058 609
Kojto 98:8ab26030e058 610
Kojto 98:8ab26030e058 611 /***************************************************************************//**
Kojto 98:8ab26030e058 612 * @brief
Kojto 98:8ab26030e058 613 * Disable one or more USART interrupts.
Kojto 98:8ab26030e058 614 *
Kojto 98:8ab26030e058 615 * @param[in] usart
Kojto 98:8ab26030e058 616 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 617 *
Kojto 98:8ab26030e058 618 * @param[in] flags
Kojto 98:8ab26030e058 619 * USART/UART interrupt source(s) to disable. Use one or more valid
Kojto 98:8ab26030e058 620 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 621 ******************************************************************************/
Kojto 98:8ab26030e058 622 __STATIC_INLINE void USART_IntDisable(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 623 {
Kojto 113:f141b2784e32 624 usart->IEN &= ~flags;
Kojto 98:8ab26030e058 625 }
Kojto 98:8ab26030e058 626
Kojto 98:8ab26030e058 627
Kojto 98:8ab26030e058 628 /***************************************************************************//**
Kojto 98:8ab26030e058 629 * @brief
Kojto 98:8ab26030e058 630 * Enable one or more USART interrupts.
Kojto 98:8ab26030e058 631 *
Kojto 98:8ab26030e058 632 * @note
Kojto 98:8ab26030e058 633 * Depending on the use, a pending interrupt may already be set prior to
Kojto 98:8ab26030e058 634 * enabling the interrupt. Consider using USART_IntClear() prior to enabling
Kojto 98:8ab26030e058 635 * if such a pending interrupt should be ignored.
Kojto 98:8ab26030e058 636 *
Kojto 98:8ab26030e058 637 * @param[in] usart
Kojto 98:8ab26030e058 638 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 639 *
Kojto 98:8ab26030e058 640 * @param[in] flags
Kojto 98:8ab26030e058 641 * USART/UART interrupt source(s) to enable. Use one or more valid
Kojto 98:8ab26030e058 642 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 643 ******************************************************************************/
Kojto 98:8ab26030e058 644 __STATIC_INLINE void USART_IntEnable(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 645 {
Kojto 98:8ab26030e058 646 usart->IEN |= flags;
Kojto 98:8ab26030e058 647 }
Kojto 98:8ab26030e058 648
Kojto 98:8ab26030e058 649
Kojto 98:8ab26030e058 650 /***************************************************************************//**
Kojto 98:8ab26030e058 651 * @brief
Kojto 98:8ab26030e058 652 * Get pending USART interrupt flags.
Kojto 98:8ab26030e058 653 *
Kojto 98:8ab26030e058 654 * @note
Kojto 98:8ab26030e058 655 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 656 *
Kojto 98:8ab26030e058 657 * @param[in] usart
Kojto 98:8ab26030e058 658 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 659 *
Kojto 98:8ab26030e058 660 * @return
Kojto 98:8ab26030e058 661 * USART/UART interrupt source(s) pending. Returns one or more valid
Kojto 98:8ab26030e058 662 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 663 ******************************************************************************/
Kojto 98:8ab26030e058 664 __STATIC_INLINE uint32_t USART_IntGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 665 {
Kojto 98:8ab26030e058 666 return usart->IF;
Kojto 98:8ab26030e058 667 }
Kojto 98:8ab26030e058 668
Kojto 98:8ab26030e058 669
Kojto 98:8ab26030e058 670 /***************************************************************************//**
Kojto 98:8ab26030e058 671 * @brief
Kojto 98:8ab26030e058 672 * Get enabled and pending USART interrupt flags.
Kojto 98:8ab26030e058 673 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 98:8ab26030e058 674 *
Kojto 98:8ab26030e058 675 * @param[in] usart
Kojto 98:8ab26030e058 676 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 677 *
Kojto 98:8ab26030e058 678 * @note
Kojto 98:8ab26030e058 679 * Interrupt flags are not cleared by the use of this function.
Kojto 98:8ab26030e058 680 *
Kojto 98:8ab26030e058 681 * @return
Kojto 98:8ab26030e058 682 * Pending and enabled USART interrupt sources.
Kojto 98:8ab26030e058 683 * The return value is the bitwise AND combination of
Kojto 98:8ab26030e058 684 * - the OR combination of enabled interrupt sources in USARTx_IEN_nnn
Kojto 98:8ab26030e058 685 * register (USARTx_IEN_nnn) and
Kojto 98:8ab26030e058 686 * - the OR combination of valid interrupt flags of the USART module
Kojto 98:8ab26030e058 687 * (USARTx_IF_nnn).
Kojto 98:8ab26030e058 688 ******************************************************************************/
Kojto 98:8ab26030e058 689 __STATIC_INLINE uint32_t USART_IntGetEnabled(USART_TypeDef *usart)
Kojto 98:8ab26030e058 690 {
Kojto 113:f141b2784e32 691 uint32_t ien;
Kojto 98:8ab26030e058 692
Kojto 98:8ab26030e058 693 /* Store USARTx->IEN in temporary variable in order to define explicit order
Kojto 98:8ab26030e058 694 * of volatile accesses. */
Kojto 113:f141b2784e32 695 ien = usart->IEN;
Kojto 98:8ab26030e058 696
Kojto 98:8ab26030e058 697 /* Bitwise AND of pending and enabled interrupts */
Kojto 113:f141b2784e32 698 return usart->IF & ien;
Kojto 98:8ab26030e058 699 }
Kojto 98:8ab26030e058 700
Kojto 98:8ab26030e058 701
Kojto 98:8ab26030e058 702 /***************************************************************************//**
Kojto 98:8ab26030e058 703 * @brief
Kojto 98:8ab26030e058 704 * Set one or more pending USART interrupts from SW.
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 * @param[in] flags
Kojto 98:8ab26030e058 710 * USART/UART interrupt source(s) to set to pending. Use one or more valid
Kojto 98:8ab26030e058 711 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 712 ******************************************************************************/
Kojto 98:8ab26030e058 713 __STATIC_INLINE void USART_IntSet(USART_TypeDef *usart, uint32_t flags)
Kojto 98:8ab26030e058 714 {
Kojto 98:8ab26030e058 715 usart->IFS = flags;
Kojto 98:8ab26030e058 716 }
Kojto 98:8ab26030e058 717
Kojto 98:8ab26030e058 718
Kojto 98:8ab26030e058 719 /***************************************************************************//**
Kojto 98:8ab26030e058 720 * @brief
Kojto 98:8ab26030e058 721 * Get USART STATUS register.
Kojto 98:8ab26030e058 722 *
Kojto 98:8ab26030e058 723 * @param[in] usart
Kojto 98:8ab26030e058 724 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 725 *
Kojto 98:8ab26030e058 726 * @return
Kojto 98:8ab26030e058 727 * STATUS register value.
Kojto 98:8ab26030e058 728 *
Kojto 98:8ab26030e058 729 ******************************************************************************/
Kojto 113:f141b2784e32 730 __STATIC_INLINE uint32_t USART_StatusGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 731 {
Kojto 98:8ab26030e058 732 return usart->STATUS;
Kojto 98:8ab26030e058 733 }
Kojto 98:8ab26030e058 734
Kojto 98:8ab26030e058 735 void USART_Reset(USART_TypeDef *usart);
Kojto 98:8ab26030e058 736 uint8_t USART_Rx(USART_TypeDef *usart);
Kojto 98:8ab26030e058 737 uint16_t USART_RxDouble(USART_TypeDef *usart);
Kojto 98:8ab26030e058 738 uint32_t USART_RxDoubleExt(USART_TypeDef *usart);
Kojto 98:8ab26030e058 739 uint16_t USART_RxExt(USART_TypeDef *usart);
Kojto 98:8ab26030e058 740
Kojto 98:8ab26030e058 741
Kojto 98:8ab26030e058 742 /***************************************************************************//**
Kojto 98:8ab26030e058 743 * @brief
Kojto 98:8ab26030e058 744 * Receive one 4-8 bit frame, (or part of 10-16 bit frame).
Kojto 98:8ab26030e058 745 *
Kojto 98:8ab26030e058 746 * @details
Kojto 98:8ab26030e058 747 * This function is used to quickly receive one 4-8 bits frame by reading the
Kojto 98:8ab26030e058 748 * RXDATA register directly, without checking the STATUS register for the
Kojto 98:8ab26030e058 749 * RXDATAV flag. This can be useful from the RXDATAV interrupt handler,
Kojto 98:8ab26030e058 750 * i.e. waiting is superfluous, in order to quickly read the received data.
Kojto 98:8ab26030e058 751 * Please refer to @ref USART_RxDataXGet() for reception of 9 bit frames.
Kojto 98:8ab26030e058 752 *
Kojto 98:8ab26030e058 753 * @note
Kojto 98:8ab26030e058 754 * Since this function does not check whether the RXDATA register actually
Kojto 98:8ab26030e058 755 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 756 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 757 * like when handling an RXDATAV interrupt. The @ref USART_Rx() is normally a
Kojto 98:8ab26030e058 758 * better choice if the validity of the RXDATA register is not certain.
Kojto 98:8ab26030e058 759 *
Kojto 98:8ab26030e058 760 * @note
Kojto 98:8ab26030e058 761 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 762 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 763 *
Kojto 98:8ab26030e058 764 * @param[in] usart
Kojto 98:8ab26030e058 765 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 766 *
Kojto 98:8ab26030e058 767 * @return
Kojto 98:8ab26030e058 768 * Data received.
Kojto 98:8ab26030e058 769 ******************************************************************************/
Kojto 113:f141b2784e32 770 __STATIC_INLINE uint8_t USART_RxDataGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 771 {
Kojto 113:f141b2784e32 772 return (uint8_t)usart->RXDATA;
Kojto 98:8ab26030e058 773 }
Kojto 98:8ab26030e058 774
Kojto 98:8ab26030e058 775
Kojto 98:8ab26030e058 776 /***************************************************************************//**
Kojto 98:8ab26030e058 777 * @brief
Kojto 98:8ab26030e058 778 * Receive two 4-8 bit frames, or one 10-16 bit frame.
Kojto 98:8ab26030e058 779 *
Kojto 98:8ab26030e058 780 * @details
Kojto 98:8ab26030e058 781 * This function is used to quickly receive one 10-16 bits frame or two 4-8
Kojto 98:8ab26030e058 782 * bit frames by reading the RXDOUBLE register directly, without checking
Kojto 98:8ab26030e058 783 * the STATUS register for the RXDATAV flag. This can be useful from the
Kojto 98:8ab26030e058 784 * RXDATAV interrupt handler, i.e. waiting is superfluous, in order to
Kojto 98:8ab26030e058 785 * quickly read the received data.
Kojto 98:8ab26030e058 786 * This function is normally used to receive one frame when operating with
Kojto 98:8ab26030e058 787 * frame length 10-16 bits. Please refer to @ref USART_RxDoubleXGet()
Kojto 98:8ab26030e058 788 * for reception of two 9 bit frames.
Kojto 98:8ab26030e058 789 *
Kojto 98:8ab26030e058 790 * @note
Kojto 98:8ab26030e058 791 * Since this function does not check whether the RXDOUBLE register actually
Kojto 98:8ab26030e058 792 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 793 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 794 * like when handling an RXDATAV interrupt. The @ref USART_RxDouble() is
Kojto 98:8ab26030e058 795 * normally a better choice if the validity of the RXDOUBLE register is not
Kojto 98:8ab26030e058 796 * certain.
Kojto 98:8ab26030e058 797 *
Kojto 98:8ab26030e058 798 * @note
Kojto 98:8ab26030e058 799 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 800 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 801 *
Kojto 98:8ab26030e058 802 * @param[in] usart
Kojto 98:8ab26030e058 803 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 804 *
Kojto 98:8ab26030e058 805 * @return
Kojto 98:8ab26030e058 806 * Data received.
Kojto 98:8ab26030e058 807 ******************************************************************************/
Kojto 113:f141b2784e32 808 __STATIC_INLINE uint16_t USART_RxDoubleGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 809 {
Kojto 113:f141b2784e32 810 return (uint16_t)usart->RXDOUBLE;
Kojto 98:8ab26030e058 811 }
Kojto 98:8ab26030e058 812
Kojto 98:8ab26030e058 813
Kojto 98:8ab26030e058 814 /***************************************************************************//**
Kojto 98:8ab26030e058 815 * @brief
Kojto 98:8ab26030e058 816 * Receive two 4-9 bit frames, or one 10-16 bit frame with extended
Kojto 98:8ab26030e058 817 * information.
Kojto 98:8ab26030e058 818 *
Kojto 98:8ab26030e058 819 * @details
Kojto 98:8ab26030e058 820 * This function is used to quickly receive one 10-16 bits frame or two 4-9
Kojto 98:8ab26030e058 821 * bit frames by reading the RXDOUBLEX register directly, without checking
Kojto 98:8ab26030e058 822 * the STATUS register for the RXDATAV flag. This can be useful from the
Kojto 98:8ab26030e058 823 * RXDATAV interrupt handler, i.e. waiting is superfluous, in order to
Kojto 98:8ab26030e058 824 * quickly read the received data.
Kojto 98:8ab26030e058 825 *
Kojto 98:8ab26030e058 826 * @note
Kojto 98:8ab26030e058 827 * Since this function does not check whether the RXDOUBLEX register actually
Kojto 98:8ab26030e058 828 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 829 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 830 * like when handling an RXDATAV interrupt. The @ref USART_RxDoubleExt() is
Kojto 98:8ab26030e058 831 * normally a better choice if the validity of the RXDOUBLEX register is not
Kojto 98:8ab26030e058 832 * certain.
Kojto 98:8ab26030e058 833 *
Kojto 98:8ab26030e058 834 * @note
Kojto 98:8ab26030e058 835 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 836 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 837 *
Kojto 98:8ab26030e058 838 * @param[in] usart
Kojto 98:8ab26030e058 839 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 840 *
Kojto 98:8ab26030e058 841 * @return
Kojto 98:8ab26030e058 842 * Data received.
Kojto 98:8ab26030e058 843 ******************************************************************************/
Kojto 113:f141b2784e32 844 __STATIC_INLINE uint32_t USART_RxDoubleXGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 845 {
Kojto 98:8ab26030e058 846 return usart->RXDOUBLEX;
Kojto 98:8ab26030e058 847 }
Kojto 98:8ab26030e058 848
Kojto 98:8ab26030e058 849
Kojto 98:8ab26030e058 850 /***************************************************************************//**
Kojto 98:8ab26030e058 851 * @brief
Kojto 98:8ab26030e058 852 * Receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended
Kojto 98:8ab26030e058 853 * information.
Kojto 98:8ab26030e058 854 *
Kojto 98:8ab26030e058 855 * @details
Kojto 98:8ab26030e058 856 * This function is used to quickly receive one 4-9 bit frame, (or part of
Kojto 98:8ab26030e058 857 * 10-16 bit frame) with extended information by reading the RXDATAX register
Kojto 98:8ab26030e058 858 * directly, without checking the STATUS register for the RXDATAV flag. This
Kojto 98:8ab26030e058 859 * can be useful from the RXDATAV interrupt handler, i.e. waiting is
Kojto 98:8ab26030e058 860 * superfluous, in order to quickly read the received data.
Kojto 98:8ab26030e058 861 *
Kojto 98:8ab26030e058 862 * @note
Kojto 98:8ab26030e058 863 * Since this function does not check whether the RXDATAX register actually
Kojto 98:8ab26030e058 864 * holds valid data, it should only be used in situations when it is certain
Kojto 98:8ab26030e058 865 * that there is valid data, ensured by some external program routine, e.g.
Kojto 98:8ab26030e058 866 * like when handling an RXDATAV interrupt. The @ref USART_RxExt() is normally
Kojto 98:8ab26030e058 867 * a better choice if the validity of the RXDATAX register is not certain.
Kojto 98:8ab26030e058 868 *
Kojto 98:8ab26030e058 869 * @note
Kojto 98:8ab26030e058 870 * Notice that possible parity/stop bits in asynchronous mode are not
Kojto 98:8ab26030e058 871 * considered part of specified frame bit length.
Kojto 98:8ab26030e058 872 *
Kojto 98:8ab26030e058 873 * @param[in] usart
Kojto 98:8ab26030e058 874 * Pointer to USART/UART peripheral register block.
Kojto 98:8ab26030e058 875 *
Kojto 98:8ab26030e058 876 * @return
Kojto 98:8ab26030e058 877 * Data received.
Kojto 98:8ab26030e058 878 ******************************************************************************/
Kojto 113:f141b2784e32 879 __STATIC_INLINE uint16_t USART_RxDataXGet(USART_TypeDef *usart)
Kojto 98:8ab26030e058 880 {
Kojto 113:f141b2784e32 881 return (uint16_t)usart->RXDATAX;
Kojto 98:8ab26030e058 882 }
Kojto 98:8ab26030e058 883
Kojto 98:8ab26030e058 884 uint8_t USART_SpiTransfer(USART_TypeDef *usart, uint8_t data);
Kojto 98:8ab26030e058 885 void USART_Tx(USART_TypeDef *usart, uint8_t data);
Kojto 98:8ab26030e058 886 void USART_TxDouble(USART_TypeDef *usart, uint16_t data);
Kojto 98:8ab26030e058 887 void USART_TxDoubleExt(USART_TypeDef *usart, uint32_t data);
Kojto 98:8ab26030e058 888 void USART_TxExt(USART_TypeDef *usart, uint16_t data);
Kojto 98:8ab26030e058 889
Kojto 98:8ab26030e058 890
Kojto 98:8ab26030e058 891 /** @} (end addtogroup USART) */
Kojto 98:8ab26030e058 892 /** @} (end addtogroup EM_Library) */
Kojto 98:8ab26030e058 893
Kojto 98:8ab26030e058 894 #ifdef __cplusplus
Kojto 98:8ab26030e058 895 }
Kojto 98:8ab26030e058 896 #endif
Kojto 98:8ab26030e058 897
Kojto 98:8ab26030e058 898 #endif /* defined(USART_COUNT) && (USART_COUNT > 0) */
Kojto 113:f141b2784e32 899 #endif /* __SILICON_LABS_EM_USART_H__ */