efm32_usart.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Universal synchronous/asynchronous receiver/transmitter (USART/UART)
  4. * peripheral API for EFM32.
  5. * @author Energy Micro AS
  6. * @version 2.0.0
  7. *******************************************************************************
  8. * @section License
  9. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  10. *******************************************************************************
  11. *
  12. * This source code is the property of Energy Micro AS. The source and compiled
  13. * code may only be used on Energy Micro "EFM32" microcontrollers.
  14. *
  15. * This copyright notice may not be removed from the source code nor changed.
  16. *
  17. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  18. * obligation to support this Software. Energy Micro AS is providing the
  19. * Software "AS IS", with no express or implied warranties of any kind,
  20. * including, but not limited to, any implied warranties of merchantability
  21. * or fitness for any particular purpose or warranties against infringement
  22. * of any proprietary rights of a third party.
  23. *
  24. * Energy Micro AS will not be liable for any consequential, incidental, or
  25. * special damages, or any other relief, or for any claim by any third party,
  26. * arising from your use of this Software.
  27. *
  28. ******************************************************************************/
  29. #ifndef __EFM32_USART_H
  30. #define __EFM32_USART_H
  31. #include <stdbool.h>
  32. #include "efm32.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /***************************************************************************//**
  37. * @addtogroup EFM32_Library
  38. * @{
  39. ******************************************************************************/
  40. /***************************************************************************//**
  41. * @addtogroup USART
  42. * @brief Universal Synchronous/Asynchronous Receiver/Transmitter (USART) peripheral API for EFM32
  43. * @{
  44. ******************************************************************************/
  45. /*******************************************************************************
  46. ******************************** ENUMS ************************************
  47. ******************************************************************************/
  48. /** Databit selection. */
  49. typedef enum
  50. {
  51. usartDatabits4 = USART_FRAME_DATABITS_FOUR, /**< 4 databits (not available for UART). */
  52. usartDatabits5 = USART_FRAME_DATABITS_FIVE, /**< 5 databits (not available for UART). */
  53. usartDatabits6 = USART_FRAME_DATABITS_SIX, /**< 6 databits (not available for UART). */
  54. usartDatabits7 = USART_FRAME_DATABITS_SEVEN, /**< 7 databits (not available for UART). */
  55. usartDatabits8 = USART_FRAME_DATABITS_EIGHT, /**< 8 databits. */
  56. usartDatabits9 = USART_FRAME_DATABITS_NINE, /**< 9 databits. */
  57. usartDatabits10 = USART_FRAME_DATABITS_TEN, /**< 10 databits (not available for UART). */
  58. usartDatabits11 = USART_FRAME_DATABITS_ELEVEN, /**< 11 databits (not available for UART). */
  59. usartDatabits12 = USART_FRAME_DATABITS_TWELVE, /**< 12 databits (not available for UART). */
  60. usartDatabits13 = USART_FRAME_DATABITS_THIRTEEN, /**< 13 databits (not available for UART). */
  61. usartDatabits14 = USART_FRAME_DATABITS_FOURTEEN, /**< 14 databits (not available for UART). */
  62. usartDatabits15 = USART_FRAME_DATABITS_FIFTEEN, /**< 15 databits (not available for UART). */
  63. usartDatabits16 = USART_FRAME_DATABITS_SIXTEEN /**< 16 databits (not available for UART). */
  64. } USART_Databits_TypeDef;
  65. /** Enable selection. */
  66. typedef enum
  67. {
  68. /** Disable both receiver and transmitter. */
  69. usartDisable = 0x0,
  70. /** Enable receiver only, transmitter disabled. */
  71. usartEnableRx = USART_CMD_RXEN,
  72. /** Enable transmitter only, receiver disabled. */
  73. usartEnableTx = USART_CMD_TXEN,
  74. /** Enable both receiver and transmitter. */
  75. usartEnable = (USART_CMD_RXEN | USART_CMD_TXEN)
  76. } USART_Enable_TypeDef;
  77. /** Oversampling selection, used for asynchronous operation. */
  78. typedef enum
  79. {
  80. usartOVS16 = USART_CTRL_OVS_X16, /**< 16x oversampling (normal). */
  81. usartOVS8 = USART_CTRL_OVS_X8, /**< 8x oversampling. */
  82. usartOVS6 = USART_CTRL_OVS_X6, /**< 6x oversampling. */
  83. usartOVS4 = USART_CTRL_OVS_X4 /**< 4x oversampling. */
  84. } USART_OVS_TypeDef;
  85. /** Parity selection, mainly used for asynchronous operation. */
  86. typedef enum
  87. {
  88. usartNoParity = USART_FRAME_PARITY_NONE, /**< No parity. */
  89. usartEvenParity = USART_FRAME_PARITY_EVEN, /**< Even parity. */
  90. usartOddParity = USART_FRAME_PARITY_ODD /**< Odd parity. */
  91. } USART_Parity_TypeDef;
  92. /** Stopbits selection, used for asynchronous operation. */
  93. typedef enum
  94. {
  95. usartStopbits0p5 = USART_FRAME_STOPBITS_HALF, /**< 0.5 stopbits. */
  96. usartStopbits1 = USART_FRAME_STOPBITS_ONE, /**< 1 stopbits. */
  97. usartStopbits1p5 = USART_FRAME_STOPBITS_ONEANDAHALF, /**< 1.5 stopbits. */
  98. usartStopbits2 = USART_FRAME_STOPBITS_TWO /**< 2 stopbits. */
  99. } USART_Stopbits_TypeDef;
  100. /** Clock polarity/phase mode. */
  101. typedef enum
  102. {
  103. /** Clock idle low, sample on rising edge. */
  104. usartClockMode0 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLELEADING,
  105. /** Clock idle low, sample on falling edge. */
  106. usartClockMode1 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLETRAILING,
  107. /** Clock idle high, sample on falling edge. */
  108. usartClockMode2 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLELEADING,
  109. /** Clock idle high, sample on rising edge. */
  110. usartClockMode3 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLETRAILING
  111. } USART_ClockMode_TypeDef;
  112. /** Pulse width selection for IrDA mode. */
  113. typedef enum
  114. {
  115. /** IrDA pulse width is 1/16 for OVS=0 and 1/8 for OVS=1 */
  116. usartIrDAPwONE = USART_IRCTRL_IRPW_ONE,
  117. /** IrDA pulse width is 2/16 for OVS=0 and 2/8 for OVS=1 */
  118. usartIrDAPwTWO = USART_IRCTRL_IRPW_TWO,
  119. /** IrDA pulse width is 3/16 for OVS=0 and 3/8 for OVS=1 */
  120. usartIrDAPwTHREE = USART_IRCTRL_IRPW_THREE,
  121. /** IrDA pulse width is 4/16 for OVS=0 and 4/8 for OVS=1 */
  122. usartIrDAPwFOUR = USART_IRCTRL_IRPW_FOUR
  123. } USART_IrDAPw_Typedef;
  124. /** PRS channel selection for IrDA mode. */
  125. typedef enum
  126. {
  127. usartIrDAPrsCh0 = USART_IRCTRL_IRPRSSEL_PRSCH0, /**< PRS channel 0 */
  128. usartIrDAPrsCh1 = USART_IRCTRL_IRPRSSEL_PRSCH1, /**< PRS channel 1 */
  129. usartIrDAPrsCh2 = USART_IRCTRL_IRPRSSEL_PRSCH2, /**< PRS channel 2 */
  130. usartIrDAPrsCh3 = USART_IRCTRL_IRPRSSEL_PRSCH3, /**< PRS channel 3 */
  131. usartIrDAPrsCh4 = USART_IRCTRL_IRPRSSEL_PRSCH4, /**< PRS channel 4 */
  132. usartIrDAPrsCh5 = USART_IRCTRL_IRPRSSEL_PRSCH5, /**< PRS channel 5 */
  133. usartIrDAPrsCh6 = USART_IRCTRL_IRPRSSEL_PRSCH6, /**< PRS channel 6 */
  134. usartIrDAPrsCh7 = USART_IRCTRL_IRPRSSEL_PRSCH7 /**< PRS channel 7 */
  135. } USART_IrDAPrsSel_Typedef;
  136. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  137. /** I2S format selection. */
  138. typedef enum
  139. {
  140. usartI2sFormatW32D32 = USART_I2SCTRL_FORMAT_W32D32, /**< 32-bit word, 32-bit data */
  141. usartI2sFormatW32D24M = USART_I2SCTRL_FORMAT_W32D24M, /**< 32-bit word, 32-bit data with 8 lsb masked */
  142. usartI2sFormatW32D24 = USART_I2SCTRL_FORMAT_W32D24, /**< 32-bit word, 24-bit data */
  143. usartI2sFormatW32D16 = USART_I2SCTRL_FORMAT_W32D16, /**< 32-bit word, 16-bit data */
  144. usartI2sFormatW32D8 = USART_I2SCTRL_FORMAT_W32D8, /**< 32-bit word, 8-bit data */
  145. usartI2sFormatW16D16 = USART_I2SCTRL_FORMAT_W16D16, /**< 16-bit word, 16-bit data */
  146. usartI2sFormatW16D8 = USART_I2SCTRL_FORMAT_W16D8, /**< 16-bit word, 8-bit data */
  147. usartI2sFormatW8D8 = USART_I2SCTRL_FORMAT_W8D8 /**< 8-bit word, 8-bit data */
  148. } USART_I2sFormat_TypeDef;
  149. /** I2S frame data justify. */
  150. typedef enum
  151. {
  152. usartI2sJustifyLeft = USART_I2SCTRL_JUSTIFY_LEFT, /**< Data is left-justified within the frame */
  153. usartI2sJustifyRight = USART_I2SCTRL_JUSTIFY_RIGHT /**< Data is right-justified within the frame */
  154. } USART_I2sJustify_TypeDef;
  155. /** USART Rx input PRS selection. */
  156. typedef enum
  157. {
  158. usartPrsRxCh0 = _USART_INPUT_RXPRSSEL_PRSCH0, /**< PRSCH0 selected as USART_INPUT */
  159. usartPrsRxCh1 = _USART_INPUT_RXPRSSEL_PRSCH1, /**< PRSCH1 selected as USART_INPUT */
  160. usartPrsRxCh2 = _USART_INPUT_RXPRSSEL_PRSCH2, /**< PRSCH2 selected as USART_INPUT */
  161. usartPrsRxCh3 = _USART_INPUT_RXPRSSEL_PRSCH3, /**< PRSCH3 selected as USART_INPUT */
  162. usartPrsRxCh4 = _USART_INPUT_RXPRSSEL_PRSCH4, /**< PRSCH4 selected as USART_INPUT */
  163. usartPrsRxCh5 = _USART_INPUT_RXPRSSEL_PRSCH5, /**< PRSCH5 selected as USART_INPUT */
  164. usartPrsRxCh6 = _USART_INPUT_RXPRSSEL_PRSCH6, /**< PRSCH6 selected as USART_INPUT */
  165. #if defined(_EFM32_TINY_FAMILY)
  166. usartPrsRxCh7 = _USART_INPUT_RXPRSSEL_PRSCH7 /**< PRSCH7 selected as USART_INPUT */
  167. #elif defined(_EFM32_GIANT_FAMILY)
  168. usartPrsRxCh7 = _USART_INPUT_RXPRSSEL_PRSCH7, /**< PRSCH7 selected as USART_INPUT */
  169. usartPrsRxCh8 = _USART_INPUT_RXPRSSEL_PRSCH8, /**< PRSCH8 selected as USART_INPUT */
  170. usartPrsRxCh9 = _USART_INPUT_RXPRSSEL_PRSCH9, /**< PRSCH9 selected as USART_INPUT */
  171. usartPrsRxCh10 = _USART_INPUT_RXPRSSEL_PRSCH10, /**< PRSCH10 selected as USART_INPUT */
  172. usartPrsRxCh11 = _USART_INPUT_RXPRSSEL_PRSCH11 /**< PRSCH11 selected as USART_INPUT */
  173. #else
  174. #error Unknown EFM32 family.
  175. #endif
  176. } USART_PrsRxCh_TypeDef;
  177. #endif
  178. /*******************************************************************************
  179. ******************************* STRUCTS ***********************************
  180. ******************************************************************************/
  181. /** Asynchronous mode init structure. */
  182. typedef struct
  183. {
  184. /** Specifies whether TX and/or RX shall be enabled when init completed. */
  185. USART_Enable_TypeDef enable;
  186. /**
  187. * USART/UART reference clock assumed when configuring baudrate setup. Set
  188. * it to 0 if currently configurated reference clock shall be used.
  189. */
  190. uint32_t refFreq;
  191. /** Desired baudrate. */
  192. uint32_t baudrate;
  193. /** Oversampling used. */
  194. USART_OVS_TypeDef oversampling;
  195. /** Number of databits in frame. Notice that UART modules only support 8 or
  196. * 9 databits. */
  197. USART_Databits_TypeDef databits;
  198. /** Parity mode to use. */
  199. USART_Parity_TypeDef parity;
  200. /** Number of stopbits to use. */
  201. USART_Stopbits_TypeDef stopbits;
  202. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  203. /** Majority Vote Disable for 16x, 8x and 6x oversampling modes. */
  204. bool mvdis;
  205. /** Enable USART Rx via PRS. */
  206. bool prsRxEnable;
  207. /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
  208. USART_PrsRxCh_TypeDef prsRxCh;
  209. #endif
  210. } USART_InitAsync_TypeDef;
  211. /** Default config for USART async init structure. */
  212. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  213. #define USART_INITASYNC_DEFAULT \
  214. { usartEnable, /* Enable RX/TX when init completed. */ \
  215. 0, /* Use current configured reference clock for configuring baudrate. */ \
  216. 115200, /* 115200 bits/s. */ \
  217. usartOVS16, /* 16x oversampling. */ \
  218. usartDatabits8, /* 8 databits. */ \
  219. usartNoParity, /* No parity. */ \
  220. usartStopbits1, /* 1 stopbit. */ \
  221. false, /* Do not disable majority vote. */ \
  222. false, /* Not USART PRS input mode. */ \
  223. usartPrsRxCh0 /* PRS channel 0. */ \
  224. }
  225. #else
  226. #define USART_INITASYNC_DEFAULT \
  227. { usartEnable, /* Enable RX/TX when init completed. */ \
  228. 0, /* Use current configured reference clock for configuring baudrate. */ \
  229. 115200, /* 115200 bits/s. */ \
  230. usartOVS16, /* 16x oversampling. */ \
  231. usartDatabits8, /* 8 databits. */ \
  232. usartNoParity, /* No parity. */ \
  233. usartStopbits1 /* 1 stopbit. */ \
  234. }
  235. #endif
  236. /** Synchronous mode init structure. */
  237. typedef struct
  238. {
  239. /** Specifies whether TX and/or RX shall be enabled when init completed. */
  240. USART_Enable_TypeDef enable;
  241. /**
  242. * USART/UART reference clock assumed when configuring baudrate setup. Set
  243. * it to 0 if currently configurated reference clock shall be used.
  244. */
  245. uint32_t refFreq;
  246. /** Desired baudrate. */
  247. uint32_t baudrate;
  248. /** Number of databits in frame. */
  249. USART_Databits_TypeDef databits;
  250. /** Select if to operate in master or slave mode. */
  251. bool master;
  252. /** Select if to send most or least significant bit first. */
  253. bool msbf;
  254. /** Clock polarity/phase mode. */
  255. USART_ClockMode_TypeDef clockMode;
  256. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  257. /** Enable USART Rx via PRS. */
  258. bool prsRxEnable;
  259. /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
  260. USART_PrsRxCh_TypeDef prsRxCh;
  261. /** Enable AUTOTX mode. Transmits as long as RX is not full.
  262. * If TX is empty, underflows are generated. */
  263. bool autoTx;
  264. #endif
  265. } USART_InitSync_TypeDef;
  266. /** Default config for USART sync init structure. */
  267. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  268. #define USART_INITSYNC_DEFAULT \
  269. { usartEnable, /* Enable RX/TX when init completed. */ \
  270. 0, /* Use current configured reference clock for configuring baudrate. */ \
  271. 1000000, /* 1 Mbits/s. */ \
  272. usartDatabits8, /* 8 databits. */ \
  273. true, /* Master mode. */ \
  274. false, /* Send least significant bit first. */ \
  275. usartClockMode0, /* Clock idle low, sample on rising edge. */ \
  276. false, /* Not USART PRS input mode. */ \
  277. usartPrsRxCh0, /* PRS channel 0. */ \
  278. false /* No AUTOTX mode. */ \
  279. }
  280. #else
  281. #define USART_INITSYNC_DEFAULT \
  282. { usartEnable, /* Enable RX/TX when init completed. */ \
  283. 0, /* Use current configured reference clock for configuring baudrate. */ \
  284. 1000000, /* 1 Mbits/s. */ \
  285. usartDatabits8, /* 8 databits. */ \
  286. true, /* Master mode. */ \
  287. false, /* Send least significant bit first. */ \
  288. usartClockMode0 /* Clock idle low, sample on rising edge. */ \
  289. }
  290. #endif
  291. /** IrDA mode init structure. Inherited from asynchronous mode init structure */
  292. typedef struct
  293. {
  294. /** General Async initialization structure. */
  295. USART_InitAsync_TypeDef async;
  296. /** Set to invert Rx signal before IrDA demodulator. */
  297. bool irRxInv;
  298. /** Set to enable filter on IrDA demodulator. */
  299. bool irFilt;
  300. /** Configure the pulse width generated by the IrDA modulator as a fraction
  301. * of the configured USART bit period. */
  302. USART_IrDAPw_Typedef irPw;
  303. /** Enable the PRS channel selected by irPrsSel as input to IrDA module
  304. * instead of TX. */
  305. bool irPrsEn;
  306. /** A PRS can be used as input to the pulse modulator instead of TX.
  307. * This value selects the channel to use. */
  308. USART_IrDAPrsSel_Typedef irPrsSel;
  309. } USART_InitIrDA_TypeDef;
  310. /** Default config for IrDA mode init structure. */
  311. #define USART_INITIRDA_DEFAULT \
  312. { \
  313. { usartEnable, /* Enable RX/TX when init completed. */ \
  314. 0, /* Use current configured reference clock for configuring baudrate. */ \
  315. 115200, /* 115200 bits/s. */ \
  316. usartOVS16, /* 16x oversampling. */ \
  317. usartDatabits8, /* 8 databits. */ \
  318. usartEvenParity, /* Even parity. */ \
  319. usartStopbits1 /* 1 stopbit. */ \
  320. }, \
  321. false, /* Rx invert disabled. */ \
  322. false, /* Filtering disabled. */ \
  323. usartIrDAPwTHREE, /* Pulse width is set to ONE. */ \
  324. false, /* Routing to PRS is disabled. */ \
  325. usartIrDAPrsCh0 /* PRS channel 0. */ \
  326. }
  327. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  328. /** I2S mode init structure. Inherited from synchronous mode init structure */
  329. typedef struct
  330. {
  331. /** General Sync initialization structure. */
  332. USART_InitSync_TypeDef sync;
  333. /** I2S mode. */
  334. USART_I2sFormat_TypeDef format;
  335. /** Delay on I2S data. Set to add a one-cycle delay between a transition
  336. * on the word-clock and the start of the I2S word.
  337. * Should be set for standard I2S format. */
  338. bool delay;
  339. /** Separate DMA Request For Left/Right Data. */
  340. bool dmaSplit;
  341. /** Justification of I2S data within the frame */
  342. USART_I2sJustify_TypeDef justify;
  343. /** Stero or Mono, set to true for mono. */
  344. bool mono;
  345. } USART_InitI2s_TypeDef;
  346. /** Default config for I2S mode init structure. */
  347. #define USART_INITI2S_DEFAULT \
  348. { \
  349. { usartEnableTx, /* Enable TX when init completed. */ \
  350. 0, /* Use current configured reference clock for configuring baudrate. */ \
  351. 1000000, /* Baudrate 1M bits/s. */ \
  352. usartDatabits16, /* 16 databits. */ \
  353. true, /* Operate as I2S master. */ \
  354. true, /* Most significant bit first. */ \
  355. usartClockMode0 /* Clock idle low, sample on rising edge. */ \
  356. }, \
  357. usartI2sFormatW16D16, /* 16-bit word, 16-bit data */ \
  358. true, /* Delay on I2S data. */ \
  359. false, /* No DMA split. */ \
  360. usartI2sJustifyLeft, /* Data is left-justified within the frame */ \
  361. false /* Stereo mode. */ \
  362. }
  363. #endif
  364. /*******************************************************************************
  365. ***************************** PROTOTYPES **********************************
  366. ******************************************************************************/
  367. void USART_BaudrateAsyncSet(USART_TypeDef *usart,
  368. uint32_t refFreq,
  369. uint32_t baudrate,
  370. USART_OVS_TypeDef ovs);
  371. uint32_t USART_BaudrateCalc(uint32_t refFreq,
  372. uint32_t clkdiv,
  373. bool syncmode,
  374. USART_OVS_TypeDef ovs);
  375. uint32_t USART_BaudrateGet(USART_TypeDef *usart);
  376. void USART_BaudrateSyncSet(USART_TypeDef *usart,
  377. uint32_t refFreq,
  378. uint32_t baudrate);
  379. void USART_Enable(USART_TypeDef *usart, USART_Enable_TypeDef enable);
  380. void USART_InitAsync(USART_TypeDef *usart, USART_InitAsync_TypeDef *init);
  381. void USART_InitSync(USART_TypeDef *usart, USART_InitSync_TypeDef *init);
  382. void USART_InitIrDA(USART_InitIrDA_TypeDef *init);
  383. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  384. void USART_InitI2s(USART_TypeDef *usart, USART_InitI2s_TypeDef *init);
  385. #endif
  386. /***************************************************************************//**
  387. * @brief
  388. * Clear one or more pending USART interrupts.
  389. *
  390. * @param[in] usart
  391. * Pointer to USART/UART peripheral register block.
  392. *
  393. * @param[in] flags
  394. * Pending USART/UART interrupt source(s) to clear. Use one or more valid
  395. * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
  396. ******************************************************************************/
  397. static __INLINE void USART_IntClear(USART_TypeDef *usart, uint32_t flags)
  398. {
  399. usart->IFC = flags;
  400. }
  401. /***************************************************************************//**
  402. * @brief
  403. * Disable one or more USART interrupts.
  404. *
  405. * @param[in] usart
  406. * Pointer to USART/UART peripheral register block.
  407. *
  408. * @param[in] flags
  409. * USART/UART interrupt source(s) to disable. Use one or more valid
  410. * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
  411. ******************************************************************************/
  412. static __INLINE void USART_IntDisable(USART_TypeDef *usart, uint32_t flags)
  413. {
  414. usart->IEN &= ~(flags);
  415. }
  416. /***************************************************************************//**
  417. * @brief
  418. * Enable one or more USART interrupts.
  419. *
  420. * @note
  421. * Depending on the use, a pending interrupt may already be set prior to
  422. * enabling the interrupt. Consider using USART_IntClear() prior to enabling
  423. * if such a pending interrupt should be ignored.
  424. *
  425. * @param[in] usart
  426. * Pointer to USART/UART peripheral register block.
  427. *
  428. * @param[in] flags
  429. * USART/UART interrupt source(s) to enable. Use one or more valid
  430. * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
  431. ******************************************************************************/
  432. static __INLINE void USART_IntEnable(USART_TypeDef *usart, uint32_t flags)
  433. {
  434. usart->IEN |= flags;
  435. }
  436. /***************************************************************************//**
  437. * @brief
  438. * Get pending USART interrupt flags.
  439. *
  440. * @note
  441. * The event bits are not cleared by the use of this function.
  442. *
  443. * @param[in] usart
  444. * Pointer to USART/UART peripheral register block.
  445. *
  446. * @return
  447. * USART/UART interrupt source(s) pending. Returns one or more valid
  448. * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
  449. ******************************************************************************/
  450. static __INLINE uint32_t USART_IntGet(USART_TypeDef *usart)
  451. {
  452. return usart->IF;
  453. }
  454. /***************************************************************************//**
  455. * @brief
  456. * Get enabled and pending USART interrupt flags.
  457. * Useful for handling more interrupt sources in the same interrupt handler.
  458. *
  459. * @param[in] usart
  460. * Pointer to USART/UART peripheral register block.
  461. *
  462. * @note
  463. * Interrupt flags are not cleared by the use of this function.
  464. *
  465. * @return
  466. * Pending and enabled USART interrupt sources.
  467. * The return value is the bitwise AND combination of
  468. * - the OR combination of enabled interrupt sources in USARTx_IEN_nnn
  469. * register (USARTx_IEN_nnn) and
  470. * - the OR combination of valid interrupt flags of the USART module
  471. * (USARTx_IF_nnn).
  472. ******************************************************************************/
  473. static __INLINE uint32_t USART_IntGetEnabled(USART_TypeDef *usart)
  474. {
  475. uint32_t tmp;
  476. /* Store USARTx->IEN in temporary variable in order to define explicit order
  477. * of volatile accesses. */
  478. tmp = usart->IEN;
  479. /* Bitwise AND of pending and enabled interrupts */
  480. return usart->IF & tmp;
  481. }
  482. /***************************************************************************//**
  483. * @brief
  484. * Set one or more pending USART interrupts from SW.
  485. *
  486. * @param[in] usart
  487. * Pointer to USART/UART peripheral register block.
  488. *
  489. * @param[in] flags
  490. * USART/UART interrupt source(s) to set to pending. Use one or more valid
  491. * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
  492. ******************************************************************************/
  493. static __INLINE void USART_IntSet(USART_TypeDef *usart, uint32_t flags)
  494. {
  495. usart->IFS = flags;
  496. }
  497. void USART_Reset(USART_TypeDef *usart);
  498. uint8_t USART_Rx(USART_TypeDef *usart);
  499. uint16_t USART_RxDouble(USART_TypeDef *usart);
  500. uint32_t USART_RxDoubleExt(USART_TypeDef *usart);
  501. uint16_t USART_RxExt(USART_TypeDef *usart);
  502. void USART_Tx(USART_TypeDef *usart, uint8_t data);
  503. void USART_TxDouble(USART_TypeDef *usart, uint16_t data);
  504. void USART_TxDoubleExt(USART_TypeDef *usart, uint32_t data);
  505. void USART_TxExt(USART_TypeDef *usart, uint16_t data);
  506. /** @} (end addtogroup USART) */
  507. /** @} (end addtogroup EFM32_Library) */
  508. #ifdef __cplusplus
  509. }
  510. #endif
  511. #endif /* __EFM32_USART_H */