uart.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. //###########################################################################
  2. //
  3. // FILE: uart.c
  4. //
  5. // TITLE: Stellaris style wrapper driver for C28x SCI peripheral.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. //*****************************************************************************
  43. //
  44. //! \addtogroup uart_api
  45. //! @{
  46. //
  47. //*****************************************************************************
  48. #include <stdbool.h>
  49. #include <stdint.h>
  50. #include "inc/hw_ints.h"
  51. #include "inc/hw_memmap.h"
  52. #include "inc/hw_types.h"
  53. #include "inc/hw_uart.h"
  54. #include "driverlib/debug.h"
  55. #include "driverlib/interrupt.h"
  56. #include "driverlib/uart.h"
  57. //*****************************************************************************
  58. //
  59. //! \internal
  60. //! Checks a UART base address.
  61. //!
  62. //! \param ui32Base is the base address of the UART port.
  63. //!
  64. //! This function determines if a UART port base address is valid.
  65. //!
  66. //! \return Returns \b true if the base address is valid and \b false
  67. //! otherwise.
  68. //
  69. //*****************************************************************************
  70. #ifdef DEBUG
  71. static bool
  72. UARTBaseValid(uint32_t ui32Base)
  73. {
  74. return((ui32Base == UARTA_BASE) || (ui32Base == UARTB_BASE) ||
  75. (ui32Base == UARTC_BASE) || (ui32Base == UARTD_BASE));
  76. }
  77. #endif
  78. //*****************************************************************************
  79. //
  80. //! Sets the type of parity.
  81. //!
  82. //! \param ui32Base is the base address of the UART port.
  83. //! \param ui32Parity specifies the type of parity to use.
  84. //!
  85. //! Sets the type of parity to use for transmitting and expect when receiving.
  86. //! The \e ui32Parity parameter must be one of \b UART_CONFIG_PAR_NONE,
  87. //! \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE,
  88. //! or \b UART_CONFIG_PAR_ZERO. The last two allow direct control of the
  89. //! parity bit; it is always either one or zero based on the mode.
  90. //!
  91. //! \return None.
  92. //
  93. //*****************************************************************************
  94. void
  95. UARTParityModeSet(uint32_t ui32Base, uint32_t ui32Parity)
  96. {
  97. //
  98. // Check the arguments.
  99. //
  100. ASSERT(UARTBaseValid(ui32Base));
  101. ASSERT((ui32Parity == UART_CONFIG_PAR_NONE) ||
  102. (ui32Parity == UART_CONFIG_PAR_EVEN) ||
  103. (ui32Parity == UART_CONFIG_PAR_ODD) ||
  104. (ui32Parity == UART_CONFIG_PAR_ONE) ||
  105. (ui32Parity == UART_CONFIG_PAR_ZERO));
  106. //
  107. // Set the parity mode.
  108. //
  109. HWREGB(ui32Base + UART_O_CCR) = ((HWREGB(ui32Base + UART_O_CCR) &
  110. ~(UART_CONFIG_PAR_MASK)) | ui32Parity);
  111. }
  112. //*****************************************************************************
  113. //
  114. //! Gets the type of parity currently being used.
  115. //!
  116. //! \param ui32Base is the base address of the UART port.
  117. //!
  118. //! This function gets the type of parity used for transmitting data and
  119. //! expected when receiving data.
  120. //!
  121. //! \return Returns the current parity settings, specified as one of
  122. //! \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD,
  123. //! \b UART_CONFIG_PAR_ONE, or \b UART_CONFIG_PAR_ZERO.
  124. //
  125. //*****************************************************************************
  126. uint32_t
  127. UARTParityModeGet(uint32_t ui32Base)
  128. {
  129. //
  130. // Check the arguments.
  131. //
  132. ASSERT(UARTBaseValid(ui32Base));
  133. //
  134. // Return the current parity setting.
  135. //
  136. return(HWREGB(ui32Base + UART_O_CCR) &
  137. (UART_CONFIG_PAR_MASK));
  138. }
  139. //*****************************************************************************
  140. //
  141. //! Sets the FIFO level at which interrupts are generated.
  142. //!
  143. //! \param ui32Base is the base address of the UART port.
  144. //! \param ui32TxLevel is the transmit FIFO interrupt level, specified as one of
  145. //! \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8, \b UART_FIFO_TX4_8,
  146. //! \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
  147. //! \param ui32RxLevel is the receive FIFO interrupt level, specified as one of
  148. //! \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8, \b UART_FIFO_RX4_8,
  149. //! \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
  150. //!
  151. //! This function sets the FIFO level at which transmit and receive interrupts
  152. //! are generated.
  153. //!
  154. //! \return None.
  155. //
  156. //*****************************************************************************
  157. void
  158. UARTFIFOIntLevelSet(uint32_t ui32Base, uint32_t ui32TxLevel,
  159. uint32_t ui32RxLevel)
  160. {
  161. //
  162. // Check the arguments.
  163. //
  164. ASSERT(UARTBaseValid(ui32Base));
  165. ASSERT((ui32TxLevel == UART_FIFO_TX1_8) ||
  166. (ui32TxLevel == UART_FIFO_TX2_8) ||
  167. (ui32TxLevel == UART_FIFO_TX4_8) ||
  168. (ui32TxLevel == UART_FIFO_TX6_8));
  169. ASSERT((ui32RxLevel == UART_FIFO_RX1_8) ||
  170. (ui32RxLevel == UART_FIFO_RX2_8) ||
  171. (ui32RxLevel == UART_FIFO_RX4_8) ||
  172. (ui32RxLevel == UART_FIFO_RX6_8));
  173. //
  174. // Set the FIFO interrupt levels.
  175. //
  176. HWREGH(ui32Base + UART_O_FFTX) = (HWREGH(ui32Base + UART_O_FFTX)& (~UART_FFTX_TXFFIL_M)) | ui32TxLevel ;
  177. HWREGH(ui32Base + UART_O_FFRX) = (HWREGH(ui32Base + UART_O_FFRX)& (~UART_FFRX_RXFFIL_M)) | ui32RxLevel ;
  178. }
  179. //*****************************************************************************
  180. //
  181. //! Gets the FIFO level at which interrupts are generated.
  182. //!
  183. //! \param ui32Base is the base address of the UART port.
  184. //! \param pui32TxLevel is a pointer to storage for the transmit FIFO level,
  185. //! returned as one of \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8,
  186. //! \b UART_FIFO_TX4_8, \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
  187. //! \param pui32RxLevel is a pointer to storage for the receive FIFO level,
  188. //! returned as one of \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8,
  189. //! \b UART_FIFO_RX4_8, \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
  190. //!
  191. //! This function gets the FIFO level at which transmit and receive interrupts
  192. //! are generated.
  193. //!
  194. //! \return None.
  195. //
  196. //*****************************************************************************
  197. void
  198. UARTFIFOIntLevelGet(uint32_t ui32Base, uint32_t *pui32TxLevel,
  199. uint32_t *pui32RxLevel)
  200. {
  201. //
  202. // Check the arguments.
  203. //
  204. ASSERT(UARTBaseValid(ui32Base));
  205. //
  206. // Extract the transmit and receive FIFO levels.
  207. //
  208. *pui32TxLevel = HWREGH(ui32Base + UART_O_FFTX) & UART_FFTX_TXFFIL_M;
  209. *pui32RxLevel = HWREGH(ui32Base + UART_O_FFRX) & UART_FFRX_RXFFIL_M;
  210. }
  211. //*****************************************************************************
  212. //
  213. //! Gets the FIFO level at which interrupts are generated.
  214. //!
  215. //! \param ui32Base is the base address of the UART port.
  216. //! \param pui32TxLevel is a pointer to storage for the transmit FIFO level,
  217. //! returned as one of \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8,
  218. //! \b UART_FIFO_TX4_8, \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
  219. //! \param pui32RxLevel is a pointer to storage for the receive FIFO level,
  220. //! returned as one of \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8,
  221. //! \b UART_FIFO_RX4_8, \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
  222. //!
  223. //! This function gets the FIFO level at which transmit and receive interrupts
  224. //! are generated.
  225. //!
  226. //! \return None.
  227. //
  228. //*****************************************************************************
  229. void
  230. UARTFIFOLevelGet(uint32_t ui32Base, uint32_t *pui32TxLevel,
  231. uint32_t *pui32RxLevel)
  232. {
  233. //
  234. // Check the arguments.
  235. //
  236. ASSERT(UARTBaseValid(ui32Base));
  237. //
  238. // Extract the transmit and receive FIFO levels.
  239. //
  240. *pui32TxLevel = (HWREGH(ui32Base + UART_O_FFTX) & UART_FFTX_TXFFST_M) >> UART_FFTX_TXFFST_S;
  241. *pui32RxLevel = (HWREGH(ui32Base + UART_O_FFRX) & UART_FFRX_RXFFST_M) >> UART_FFRX_RXFFST_S;
  242. }
  243. //*****************************************************************************
  244. //
  245. //! Sets the configuration of a UART.
  246. //!
  247. //! \param ui32Base is the base address of the UART port.
  248. //! \param ui32UARTClk is the rate of the clock supplied to the UART module.
  249. //! \param ui32Baud is the desired baud rate.
  250. //! \param ui32Config is the data format for the port (number of data bits,
  251. //! number of stop bits, and parity).
  252. //!
  253. //! This function configures the UART for operation in the specified data
  254. //! format. The baud rate is provided in the \e ui32Baud parameter and the data
  255. //! format in the \e ui32Config parameter.
  256. //!
  257. //! The \e ui32Config parameter is the logical OR of three values: the number of
  258. //! data bits, the number of stop bits, and the parity. \b UART_CONFIG_WLEN_8,
  259. //! \b UART_CONFIG_WLEN_7, \b UART_CONFIG_WLEN_6, and \b UART_CONFIG_WLEN_5
  260. //! select from eight to five data bits per byte (respectively).
  261. //! \b UART_CONFIG_STOP_ONE and \b UART_CONFIG_STOP_TWO select one or two stop
  262. //! bits (respectively). \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN,
  263. //! \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE, and \b UART_CONFIG_PAR_ZERO
  264. //! select the parity mode (no parity bit, even parity bit, odd parity bit,
  265. //! parity bit always one, and parity bit always zero, respectively).
  266. //!
  267. //! The peripheral clock will be the same as the processor clock. This will be
  268. //! the value returned by SysCtlClockGet(), or it can be explicitly hard coded
  269. //! if it is constant and known (to save the code/execution overhead of a call
  270. //! to SysCtlClockGet()).
  271. //!
  272. //! This function replaces the original UARTConfigSet() API and performs the
  273. //! same actions. A macro is provided in <tt>uart.h</tt> to map the original
  274. //! API to this API.
  275. //!
  276. //! \return None.
  277. //
  278. //*****************************************************************************
  279. //Changed for C28x
  280. void
  281. UARTConfigSetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  282. uint32_t ui32Baud, uint32_t ui32Config)
  283. {
  284. uint32_t ui32Div;
  285. //
  286. // Check the arguments.
  287. //
  288. ASSERT(UARTBaseValid(ui32Base));
  289. ASSERT(ui32Baud != 0);
  290. // ASSERT(ui32UARTClk >= (ui32Baud * UART_CLK_DIVIDER));
  291. //
  292. // Stop the UART.
  293. //
  294. UARTDisable(ui32Base);
  295. //
  296. // Is the required baud rate greater than the maximum rate supported?
  297. //
  298. if((ui32Baud * 16) > ui32UARTClk)
  299. {
  300. //
  301. // Baud Rate Not supported with current clock
  302. //
  303. return;
  304. }
  305. //
  306. // Compute the baud rate divider.
  307. //
  308. ui32Div = ((ui32UARTClk / (ui32Baud * 8)) - 1);
  309. //
  310. // Set the baud rate.
  311. //
  312. HWREGB(ui32Base + UART_O_HBAUD) = (ui32Div & 0xFF00) >> 8;
  313. HWREGB(ui32Base + UART_O_LBAUD) = ui32Div & 0x00FF;
  314. //
  315. // Set parity, data length, and number of stop bits.
  316. //
  317. HWREGB(ui32Base + UART_O_CCR) = ((HWREGB(ui32Base + UART_O_CCR) &
  318. ~(UART_CONFIG_PAR_MASK | UART_CONFIG_STOP_MASK | UART_CONFIG_WLEN_MASK))
  319. | ui32Config);
  320. //
  321. // Start the UART.
  322. //
  323. UARTEnable(ui32Base);
  324. }
  325. //*****************************************************************************
  326. //
  327. //! Gets the current configuration of a UART.
  328. //!
  329. //! \param ui32Base is the base address of the UART port.
  330. //! \param ui32UARTClk is the rate of the clock supplied to the UART module.
  331. //! \param pui32Baud is a pointer to storage for the baud rate.
  332. //! \param pui32Config is a pointer to storage for the data format.
  333. //!
  334. //! The baud rate and data format for the UART is determined, given an
  335. //! explicitly provided peripheral clock (hence the ExpClk suffix). The
  336. //! returned baud rate is the actual baud rate; it may not be the exact baud
  337. //! rate requested or an ``official'' baud rate. The data format returned in
  338. //! \e pui32Config is enumerated the same as the \e ui32Config parameter of
  339. //! UARTConfigSetExpClk().
  340. //!
  341. //! The peripheral clock will be the same as the processor clock. This will be
  342. //! the value returned by SysCtlClockGet(), or it can be explicitly hard coded
  343. //! if it is constant and known (to save the code/execution overhead of a call
  344. //! to SysCtlClockGet()).
  345. //!
  346. //! This function replaces the original UARTConfigGet() API and performs the
  347. //! same actions. A macro is provided in <tt>uart.h</tt> to map the original
  348. //! API to this API.
  349. //!
  350. //! \return None.
  351. //
  352. //*****************************************************************************
  353. void
  354. UARTConfigGetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  355. uint32_t *pui32Baud, uint32_t *pui32Config)
  356. {
  357. //
  358. // Check the arguments.
  359. //
  360. ASSERT(UARTBaseValid(ui32Base));
  361. //
  362. // Compute the baud rate.
  363. //
  364. *pui32Baud = ui32UARTClk / ((1 + (HWREGB(ui32Base + UART_O_HBAUD) << 8 ) | HWREGB(ui32Base + UART_O_LBAUD)) * 8);
  365. //
  366. // Get the parity, data length, and number of stop bits.
  367. //
  368. *pui32Config = HWREGB(ui32Base + UART_O_CCR) &
  369. (UART_CONFIG_PAR_MASK | UART_CONFIG_STOP_MASK | UART_CONFIG_WLEN_MASK);
  370. }
  371. //*****************************************************************************
  372. //
  373. //! Enables transmitting and receiving.
  374. //!
  375. //! \param ui32Base is the base address of the UART port.
  376. //!
  377. //! Sets the UARTEN, TXE, and RXE bits, and enables the transmit and receive
  378. //! FIFOs.
  379. //!
  380. //! \return None.
  381. //
  382. //*****************************************************************************
  383. void
  384. UARTEnable(uint32_t ui32Base)
  385. {
  386. //
  387. // Check the arguments.
  388. //
  389. ASSERT(UARTBaseValid(ui32Base));
  390. //
  391. // Enable RX, TX, and the UART.
  392. //
  393. HWREGB(ui32Base + UART_O_CTL1) |= (UART_CTL1_TXENA | UART_CTL1_RXENA | UART_CTL1_SWRESET);
  394. }
  395. //*****************************************************************************
  396. //
  397. //! Disables transmitting and receiving.
  398. //!
  399. //! \param ui32Base is the base address of the UART port.
  400. //!
  401. //! Clears the UARTEN, TXE, and RXE bits, then waits for the end of
  402. //! transmission of the current character, and flushes the transmit FIFO.
  403. //!
  404. //! \return None.
  405. //
  406. //*****************************************************************************
  407. void
  408. UARTDisable(uint32_t ui32Base)
  409. {
  410. //
  411. // Check the arguments.
  412. //
  413. ASSERT(UARTBaseValid(ui32Base));
  414. //
  415. // Wait for end of TX.
  416. //
  417. while(!(HWREGH(ui32Base + UART_O_CTL2) & UART_CTL2_TXEMPTY))
  418. {
  419. }
  420. //
  421. // Disable the FIFO.
  422. //
  423. HWREGH(ui32Base + UART_O_FFTX) &= ~(UART_FFTX_SCIFFENA);
  424. //
  425. // Disable the UART.
  426. //
  427. HWREGB(ui32Base + UART_O_CTL1) &= ~(UART_CTL1_TXENA | UART_CTL1_RXENA);
  428. }
  429. //*****************************************************************************
  430. //
  431. //! Enables Loop Back Test Mode.
  432. //!
  433. //! \param ui32Base is the base address of the UART port.
  434. //!
  435. //! Sets the SCICCR.LOOPBKENA to enable
  436. //!
  437. //! \return None.
  438. //
  439. //*****************************************************************************
  440. void UARTsetLoopBack(uint32_t ui32Base, bool enable)
  441. {
  442. //
  443. // Check the arguments.
  444. //
  445. ASSERT(UARTBaseValid(ui32Base));
  446. if(enable)
  447. {
  448. //
  449. // Enable LoopBack.
  450. //
  451. HWREGB(ui32Base + UART_O_CCR) |= UART_CCR_LOOPBKENA;
  452. }
  453. else
  454. {
  455. //
  456. // Disable LoopBack.
  457. //
  458. HWREGB(ui32Base + UART_O_CCR) &= ~UART_CCR_LOOPBKENA;
  459. }
  460. }
  461. //*****************************************************************************
  462. //
  463. //! Enables the transmit and receive FIFOs.
  464. //!
  465. //! \param ui32Base is the base address of the UART port.
  466. //!
  467. //! This functions enables the transmit and receive FIFOs in the UART.
  468. //!
  469. //! \return None.
  470. //
  471. //*****************************************************************************
  472. void
  473. UARTFIFOEnable(uint32_t ui32Base)
  474. {
  475. //
  476. // Check the arguments.
  477. //
  478. ASSERT(UARTBaseValid(ui32Base));
  479. //
  480. // Enable the FIFO.
  481. //
  482. HWREGH(ui32Base + UART_O_FFTX) |= UART_FFTX_SCIFFENA;
  483. }
  484. //*****************************************************************************
  485. //
  486. //! Disables the transmit and receive FIFOs.
  487. //!
  488. //! \param ui32Base is the base address of the UART port.
  489. //!
  490. //! This functions disables the transmit and receive FIFOs in the UART.
  491. //!
  492. //! \return None.
  493. //
  494. //*****************************************************************************
  495. void
  496. UARTFIFODisable(uint32_t ui32Base)
  497. {
  498. //
  499. // Check the arguments.
  500. //
  501. ASSERT(UARTBaseValid(ui32Base));
  502. //
  503. // Disable the FIFO.
  504. //
  505. HWREGH(ui32Base + UART_O_FFTX) &= ~UART_FFTX_SCIFFENA;
  506. }
  507. //*****************************************************************************
  508. //
  509. //! Sets the operating mode for the UART transmit interrupt.
  510. //!
  511. //! \param ui32Base is the base address of the UART port.
  512. //! \param ui32Mode is the operating mode for the transmit interrupt. It may be
  513. //! \b UART_TXINT_MODE_EOT to trigger interrupts when the transmitter is idle
  514. //! or \b UART_TXINT_MODE_FIFO to trigger based on the current transmit FIFO
  515. //! level.
  516. //!
  517. //! This function allows the mode of the UART transmit interrupt to be set. By
  518. //! default, the transmit interrupt is asserted when the FIFO level falls past
  519. //! a threshold set via a call to UARTFIFOLevelSet(). Alternatively, if this
  520. //! function is called with \e ui32Mode set to \b UART_TXINT_MODE_EOT, the
  521. //! transmit interrupt will only be asserted once the transmitter is completely
  522. //! idle - the transmit FIFO is empty and all bits, including any stop bits,
  523. //! have cleared the transmitter.
  524. //!
  525. //! \return None.
  526. //
  527. //*****************************************************************************
  528. void
  529. UARTTxIntModeSet(uint32_t ui32Base, uint32_t ui32Mode)
  530. {
  531. //
  532. // Check the arguments.
  533. //
  534. ASSERT(UARTBaseValid(ui32Base));
  535. ASSERT((ui32Mode == UART_TXINT_MODE_EOT) ||
  536. (ui32Mode == UART_TXINT_MODE_FIFO_M));
  537. //
  538. // Set or clear the EOT bit of the UART control register as appropriate.
  539. //
  540. HWREGH(ui32Base + UART_O_FFTX) = ((HWREG(ui32Base + UART_O_FFTX) & ~(UART_TXINT_MODE_FIFO_M)) | ui32Mode);
  541. }
  542. //*****************************************************************************
  543. //
  544. //! Returns the current operating mode for the UART transmit interrupt.
  545. //!
  546. //! \param ui32Base is the base address of the UART port.
  547. //!
  548. //! This function returns the current operating mode for the UART transmit
  549. //! interrupt. The return value will be \b UART_TXINT_MODE_EOT if the
  550. //! transmit interrupt is currently set to be asserted once the transmitter is
  551. //! completely idle - the transmit FIFO is empty and all bits, including any
  552. //! stop bits, have cleared the transmitter. The return value will be \b
  553. //! UART_TXINT_MODE_FIFO if the interrupt is set to be asserted based upon the
  554. //! level of the transmit FIFO.
  555. //!
  556. //! \return Returns \b UART_TXINT_MODE_FIFO or \b UART_TXINT_MODE_EOT.
  557. //
  558. //*****************************************************************************
  559. uint32_t
  560. UARTTxIntModeGet(uint32_t ui32Base)
  561. {
  562. //
  563. // Check the arguments.
  564. //
  565. ASSERT(UARTBaseValid(ui32Base));
  566. //
  567. // Return the current transmit interrupt mode.
  568. //
  569. return(HWREGH(ui32Base + UART_O_FFTX) & UART_TXINT_MODE_FIFO_M);
  570. }
  571. //*****************************************************************************
  572. //
  573. //! Determines if there are any characters in the receive FIFO.
  574. //!
  575. //! \param ui32Base is the base address of the UART port.
  576. //!
  577. //! This function returns a flag indicating whether or not there is data
  578. //! available in the receive FIFO.
  579. //!
  580. //! \return Returns \b true if there is data in the receive FIFO or \b false
  581. //! if there is no data in the receive FIFO.
  582. //
  583. //*****************************************************************************
  584. bool
  585. UARTCharsAvail(uint32_t ui32Base)
  586. {
  587. //
  588. // Check the arguments.
  589. //
  590. ASSERT(UARTBaseValid(ui32Base));
  591. //
  592. // Return the availability of characters.
  593. //
  594. if(HWREGH(ui32Base + UART_O_FFTX) & UART_FFTX_SCIFFENA)
  595. {
  596. return(((HWREGH(ui32Base + UART_O_FFRX) & UART_FFRX_RXFFST_M) >> UART_FFRX_RXFFST_S) ? true : false);
  597. }
  598. else
  599. {
  600. return((HWREGB(ui32Base + UART_O_RXST) & UART_RXST_RXRDY) ? true : false);
  601. }
  602. }
  603. //*****************************************************************************
  604. //
  605. //! Determines if there is any space in the transmit FIFO.
  606. //!
  607. //! \param ui32Base is the base address of the UART port.
  608. //!
  609. //! This function returns a flag indicating whether or not there is space
  610. //! available in the transmit FIFO.
  611. //!
  612. //! \return Returns \b true if there is space available in the transmit FIFO
  613. //! or \b false if there is no space available in the transmit FIFO.
  614. //
  615. //*****************************************************************************
  616. bool
  617. UARTSpaceAvail(uint32_t ui32Base)
  618. {
  619. //
  620. // Check the arguments.
  621. //
  622. ASSERT(UARTBaseValid(ui32Base));
  623. //
  624. // Return the availability of space.
  625. //
  626. return((HWREGB(ui32Base + UART_O_CTL2) & UART_CTL2_TXRDY) ? true : false);
  627. }
  628. //*****************************************************************************
  629. //
  630. //! Receives a character from the specified port.
  631. //!
  632. //! \param ui32Base is the base address of the UART port.
  633. //!
  634. //! Gets a character from the receive FIFO for the specified port.
  635. //!
  636. //! This function replaces the original UARTCharNonBlockingGet() API and
  637. //! performs the same actions. A macro is provided in <tt>uart.h</tt> to map
  638. //! the original API to this API.
  639. //!
  640. //! \return Returns the character read from the specified port, cast as a
  641. //! \e long. A \b -1 is returned if there are no characters present in the
  642. //! receive FIFO. The UARTCharsAvail() function should be called before
  643. //! attempting to call this function.
  644. //
  645. //*****************************************************************************
  646. int32_t
  647. UARTCharGetNonBlocking(uint32_t ui32Base)
  648. {
  649. //
  650. // Check the arguments.
  651. //
  652. ASSERT(UARTBaseValid(ui32Base));
  653. //
  654. // See if there are any characters in the receive FIFO.
  655. //
  656. if(HWREGH(ui32Base + UART_O_FFTX) & UART_FFTX_SCIFFENA)
  657. {
  658. if((HWREGH(ui32Base + UART_O_FFRX) & UART_FFRX_RXFFST_M) >> UART_FFRX_RXFFST_S)
  659. {
  660. //
  661. // Read and return the next character.
  662. //
  663. return(HWREGH(ui32Base + UART_O_RXBUF) & UART_RXBUF_SAR_M);
  664. }
  665. else
  666. {
  667. //
  668. // There are no characters, so return a failure.
  669. //
  670. return(-1);
  671. }
  672. }
  673. else
  674. {
  675. if((HWREGB(ui32Base + UART_O_RXST) & UART_RXST_RXRDY))
  676. {
  677. //
  678. // Read and return the next character.
  679. //
  680. return(HWREGH(ui32Base + UART_O_RXBUF) & UART_RXBUF_SAR_M);
  681. }
  682. else
  683. {
  684. //
  685. // There are no characters, so return a failure.
  686. //
  687. return(-1);
  688. }
  689. }
  690. }
  691. //*****************************************************************************
  692. //
  693. //! Waits for a character from the specified port.
  694. //!
  695. //! \param ui32Base is the base address of the UART port.
  696. //!
  697. //! Gets a character from the receive FIFO for the specified port. If there
  698. //! are no characters available, this function waits until a character is
  699. //! received before returning.
  700. //!
  701. //! \return Returns the character read from the specified port, cast as a
  702. //! \e long.
  703. //
  704. //*****************************************************************************
  705. int32_t
  706. UARTCharGet(uint32_t ui32Base)
  707. {
  708. //
  709. // Check the arguments.
  710. //
  711. ASSERT(UARTBaseValid(ui32Base));
  712. //
  713. // Wait until a char is available.
  714. //
  715. if(HWREGH(ui32Base + UART_O_FFTX) & UART_FFTX_SCIFFENA)
  716. {
  717. while(!((HWREGH(ui32Base + UART_O_FFRX) & UART_FFRX_RXFFST_M) >> UART_FFRX_RXFFST_S))
  718. {
  719. }
  720. }
  721. else
  722. {
  723. while(!(HWREGH(ui32Base + UART_O_RXST) & UART_RXST_RXRDY))
  724. {
  725. }
  726. }
  727. //
  728. // Now get the char.
  729. //
  730. return(HWREGH(ui32Base + UART_O_RXBUF) & UART_RXBUF_SAR_M);
  731. }
  732. //*****************************************************************************
  733. //
  734. //! Sends a character to the specified port.
  735. //!
  736. //! \param ui32Base is the base address of the UART port.
  737. //! \param ucData is the character to be transmitted.
  738. //!
  739. //! Writes the character \e ucData to the transmit FIFO for the specified port.
  740. //! This function does not block, so if there is no space available, then a
  741. //! \b false is returned, and the application must retry the function later.
  742. //!
  743. //! This function replaces the original UARTCharNonBlockingPut() API and
  744. //! performs the same actions. A macro is provided in <tt>uart.h</tt> to map
  745. //! the original API to this API.
  746. //!
  747. //! \return Returns \b true if the character was successfully placed in the
  748. //! transmit FIFO or \b false if there was no space available in the transmit
  749. //! FIFO.
  750. //
  751. //*****************************************************************************
  752. bool
  753. UARTCharPutNonBlocking(uint32_t ui32Base, unsigned char ucData)
  754. {
  755. //
  756. // Check the arguments.
  757. //
  758. ASSERT(UARTBaseValid(ui32Base));
  759. //
  760. // See if there is space in the transmit FIFO.
  761. //
  762. if(HWREGB(ui32Base + UART_O_CTL2) & UART_CTL2_TXRDY)
  763. {
  764. //
  765. // Write this character to the transmit FIFO.
  766. //
  767. HWREGB(ui32Base + UART_O_TXBUF) = ucData;
  768. //
  769. // Success.
  770. //
  771. return(true);
  772. }
  773. else
  774. {
  775. //
  776. // There is no space in the transmit FIFO, so return a failure.
  777. //
  778. return(false);
  779. }
  780. }
  781. //*****************************************************************************
  782. //
  783. //! Waits to send a character from the specified port.
  784. //!
  785. //! \param ui32Base is the base address of the UART port.
  786. //! \param ucData is the character to be transmitted.
  787. //!
  788. //! Sends the character \e ucData to the transmit FIFO for the specified port.
  789. //! If there is no space available in the transmit FIFO, this function waits
  790. //! until there is space available before returning.
  791. //!
  792. //! \return None.
  793. //
  794. //*****************************************************************************
  795. void
  796. UARTCharPut(uint32_t ui32Base, unsigned char ucData)
  797. {
  798. //
  799. // Check the arguments.
  800. //
  801. ASSERT(UARTBaseValid(ui32Base));
  802. //
  803. // Wait until space is available.
  804. //
  805. while(!(HWREGH(ui32Base + UART_O_CTL2) & UART_CTL2_TXRDY))
  806. {
  807. }
  808. //
  809. // Send the char.
  810. //
  811. HWREGB(ui32Base + UART_O_TXBUF) = ucData;
  812. }
  813. //*****************************************************************************
  814. //
  815. //! Determines whether the UART transmitter is busy or not.
  816. //!
  817. //! \param ui32Base is the base address of the UART port.
  818. //!
  819. //! Allows the caller to determine whether all transmitted bytes have cleared
  820. //! the transmitter hardware. If \b false is returned, the transmit FIFO is
  821. //! empty and all bits of the last transmitted character, including all stop
  822. //! bits, have left the hardware shift register.
  823. //!
  824. //! \return Returns \b true if the UART is transmitting or \b false if all
  825. //! transmissions are complete.
  826. //
  827. //*****************************************************************************
  828. bool
  829. UARTBusy(uint32_t ui32Base)
  830. {
  831. //
  832. // Check the argument.
  833. //
  834. ASSERT(UARTBaseValid(ui32Base));
  835. //
  836. // Determine if the UART is busy.
  837. //
  838. return((HWREGB(ui32Base + UART_O_CTL2) & UART_CTL2_TXEMPTY) ? false : true);
  839. }
  840. //*****************************************************************************
  841. //
  842. //! Registers an interrupt handler for a UART RX interrupt.
  843. //!
  844. //! \param ui32Base is the base address of the UART port.
  845. //! \param pfnHandler is a pointer to the function to be called when the
  846. //! UART interrupt occurs.
  847. //!
  848. //! This function does the actual registering of the interrupt handler. This
  849. //! will enable the global interrupt in the interrupt controller; specific UART
  850. //! interrupts must be enabled via UARTIntEnable(). It is the interrupt
  851. //! handler's responsibility to clear the interrupt source.
  852. //!
  853. //! \sa IntRegister() for important information about registering interrupt
  854. //! handlers.
  855. //!
  856. //! \return None.
  857. //
  858. //*****************************************************************************
  859. void
  860. UARTRXIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  861. {
  862. uint32_t ui32Int;
  863. //
  864. // Check the arguments.
  865. //
  866. ASSERT(UARTBaseValid(ui32Base));
  867. //
  868. // Determine the interrupt number based on the UART port.
  869. //
  870. ui32Int = ((ui32Base == UARTA_BASE) ? INT_SCIRXINTA : INT_SCIRXINTB );
  871. //
  872. // Register the interrupt handler.
  873. //
  874. IntRegister(ui32Int, pfnHandler);
  875. //
  876. // Enable the UART interrupt.
  877. //
  878. IntEnable(ui32Int);
  879. }
  880. //*****************************************************************************
  881. //
  882. //! Registers an interrupt handler for a UART TX interrupt.
  883. //!
  884. //! \param ui32Base is the base address of the UART port.
  885. //! \param pfnHandler is a pointer to the function to be called when the
  886. //! UART interrupt occurs.
  887. //!
  888. //! This function does the actual registering of the interrupt handler. This
  889. //! will enable the global interrupt in the interrupt controller; specific UART
  890. //! interrupts must be enabled via UARTIntEnable(). It is the interrupt
  891. //! handler's responsibility to clear the interrupt source.
  892. //!
  893. //! \sa IntRegister() for important information about registering interrupt
  894. //! handlers.
  895. //!
  896. //! \return None.
  897. //
  898. //*****************************************************************************
  899. void
  900. UARTTXIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  901. {
  902. uint32_t ui32Int;
  903. //
  904. // Check the arguments.
  905. //
  906. ASSERT(UARTBaseValid(ui32Base));
  907. //
  908. // Determine the interrupt number based on the UART port.
  909. //
  910. ui32Int = ((ui32Base == UARTA_BASE) ? INT_SCITXINTA : INT_SCITXINTB );
  911. //
  912. // Register the interrupt handler.
  913. //
  914. IntRegister(ui32Int, pfnHandler);
  915. //
  916. // Enable the UART interrupt.
  917. //
  918. IntEnable(ui32Int);
  919. }
  920. //*****************************************************************************
  921. //
  922. //! Unregisters an interrupt handler for a UART RX interrupt.
  923. //!
  924. //! \param ui32Base is the base address of the UART port.
  925. //!
  926. //! This function does the actual unregistering of the interrupt handler. It
  927. //! will clear the handler to be called when a UART interrupt occurs. This
  928. //! will also mask off the interrupt in the interrupt controller so that the
  929. //! interrupt handler no longer is called.
  930. //!
  931. //! \sa IntRegister() for important information about registering interrupt
  932. //! handlers.
  933. //!
  934. //! \return None.
  935. //
  936. //*****************************************************************************
  937. void
  938. UARTRXIntUnregister(uint32_t ui32Base)
  939. {
  940. uint32_t ui32Int;
  941. //
  942. // Check the arguments.
  943. //
  944. ASSERT(UARTBaseValid(ui32Base));
  945. //
  946. // Determine the interrupt number based on the UART port.
  947. //
  948. ui32Int = ((ui32Base == UARTA_BASE) ? INT_SCIRXINTA : INT_SCIRXINTB );
  949. //
  950. // Disable the interrupt.
  951. //
  952. IntDisable(ui32Int);
  953. //
  954. // Unregister the interrupt handler.
  955. //
  956. IntUnregister(ui32Int);
  957. }
  958. //*****************************************************************************
  959. //
  960. //! Unregisters an interrupt handler for a UART TX interrupt.
  961. //!
  962. //! \param ui32Base is the base address of the UART port.
  963. //!
  964. //! This function does the actual unregistering of the interrupt handler. It
  965. //! will clear the handler to be called when a UART interrupt occurs. This
  966. //! will also mask off the interrupt in the interrupt controller so that the
  967. //! interrupt handler no longer is called.
  968. //!
  969. //! \sa IntRegister() for important information about registering interrupt
  970. //! handlers.
  971. //!
  972. //! \return None.
  973. //
  974. //*****************************************************************************
  975. void
  976. UARTTXIntUnregister(uint32_t ui32Base)
  977. {
  978. uint32_t ui32Int;
  979. //
  980. // Check the arguments.
  981. //
  982. ASSERT(UARTBaseValid(ui32Base));
  983. //
  984. // Determine the interrupt number based on the UART port.
  985. //
  986. ui32Int = ((ui32Base == UARTA_BASE) ? INT_SCITXINTA : INT_SCITXINTB );
  987. //
  988. // Disable the interrupt.
  989. //
  990. IntDisable(ui32Int);
  991. //
  992. // Unregister the interrupt handler.
  993. //
  994. IntUnregister(ui32Int);
  995. }
  996. //*****************************************************************************
  997. //
  998. //! Enables individual UART interrupt sources.
  999. //!
  1000. //! \param ui32Base is the base address of the UART port.
  1001. //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
  1002. //!
  1003. //! Enables the indicated UART interrupt sources. Only the sources that are
  1004. //! enabled can be reflected to the processor interrupt; disabled sources have
  1005. //! no effect on the processor.
  1006. //!
  1007. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  1008. //!
  1009. //! - \b UART_INT_OE - Overrun Error interrupt
  1010. //! - \b UART_INT_BE - Break Error interrupt
  1011. //! - \b UART_INT_PE - Parity Error interrupt
  1012. //! - \b UART_INT_FE - Framing Error interrupt
  1013. //! - \b UART_INT_RT - Receive Timeout interrupt
  1014. //! - \b UART_INT_TX - Transmit interrupt
  1015. //! - \b UART_INT_RX - Receive interrupt
  1016. //! - \b UART_INT_DSR - DSR interrupt
  1017. //! - \b UART_INT_DCD - DCD interrupt
  1018. //! - \b UART_INT_CTS - CTS interrupt
  1019. //! - \b UART_INT_RI - RI interrupt
  1020. //!
  1021. //! \return None.
  1022. //
  1023. //*****************************************************************************
  1024. void
  1025. UARTIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1026. {
  1027. //
  1028. // Check the arguments.
  1029. //
  1030. ASSERT(UARTBaseValid(ui32Base));
  1031. //
  1032. // Enable the specified interrupts.
  1033. //
  1034. if(ui32IntFlags & UART_INT_RXERR)
  1035. HWREGB(ui32Base + UART_O_CTL1) |= UART_CTL1_RXERRINTENA;
  1036. if(ui32IntFlags & UART_INT_RXRDY_BRKDT)
  1037. HWREGB(ui32Base + UART_O_CTL2) |= UART_CTL2_RXBKINTENA;
  1038. if(ui32IntFlags & UART_INT_TXRDY)
  1039. HWREGB(ui32Base + UART_O_CTL2) |= UART_CTL2_TXINTENA;
  1040. if(ui32IntFlags & UART_INT_TXFF)
  1041. HWREGB(ui32Base + UART_O_FFTX) |= UART_FFTX_TXFFIENA;
  1042. if(ui32IntFlags & UART_INT_RXFF)
  1043. HWREGB(ui32Base + UART_O_FFRX) |= UART_FFRX_RXFFIENA;
  1044. }
  1045. //*****************************************************************************
  1046. //
  1047. //! Disables individual UART interrupt sources.
  1048. //!
  1049. //! \param ui32Base is the base address of the UART port.
  1050. //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
  1051. //!
  1052. //! Disables the indicated UART interrupt sources. Only the sources that are
  1053. //! enabled can be reflected to the processor interrupt; disabled sources have
  1054. //! no effect on the processor.
  1055. //!
  1056. //! The \e ui32IntFlags parameter has the same definition as the \e ui32IntFlags
  1057. //! parameter to UARTIntEnable().
  1058. //!
  1059. //! \return None.
  1060. //
  1061. //*****************************************************************************
  1062. void
  1063. UARTIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1064. {
  1065. //
  1066. // Check the arguments.
  1067. //
  1068. ASSERT(UARTBaseValid(ui32Base));
  1069. //
  1070. // Disable the specified interrupts.
  1071. //
  1072. if(ui32IntFlags & UART_INT_RXERR)
  1073. HWREGB(ui32Base + UART_O_CTL1) &= ~UART_CTL1_RXERRINTENA;
  1074. if(ui32IntFlags & UART_INT_RXRDY_BRKDT)
  1075. HWREGB(ui32Base + UART_O_CTL2) &= ~UART_CTL2_RXBKINTENA;
  1076. if(ui32IntFlags & UART_INT_TXRDY)
  1077. HWREGB(ui32Base + UART_O_CTL2) &= ~UART_CTL2_TXINTENA;
  1078. if(ui32IntFlags & UART_INT_TXFF)
  1079. HWREGB(ui32Base + UART_O_FFTX) &= ~UART_FFTX_TXFFIENA;
  1080. if(ui32IntFlags & UART_INT_RXFF)
  1081. HWREGB(ui32Base + UART_O_FFRX) &= ~UART_FFRX_RXFFIENA;
  1082. }
  1083. //*****************************************************************************
  1084. //
  1085. //! Gets the current interrupt status.
  1086. //!
  1087. //! \param ui32Base is the base address of the UART port.
  1088. //! \param bMasked is \b false if the raw interrupt status is required and
  1089. //! \b true if the masked interrupt status is required.
  1090. //!
  1091. //! This returns the interrupt status for the specified UART. Either the raw
  1092. //! interrupt status or the status of interrupts that are allowed to reflect to
  1093. //! the processor can be returned.
  1094. //!
  1095. //! \return Returns the current interrupt status, enumerated as a bit field of
  1096. //! values described in UARTIntEnable().
  1097. //
  1098. //*****************************************************************************
  1099. uint32_t
  1100. UARTIntStatus(uint32_t ui32Base, bool bMasked)
  1101. {
  1102. uint32_t temp = 0;
  1103. //
  1104. // Check the arguments.
  1105. //
  1106. ASSERT(UARTBaseValid(ui32Base));
  1107. //
  1108. // Return either the interrupt status or the raw interrupt status as
  1109. // requested.
  1110. //
  1111. if(HWREGB(ui32Base + UART_O_CTL2) & UART_CTL2_TXRDY)
  1112. temp |= UART_INT_TXRDY;
  1113. if(HWREGB(ui32Base + UART_O_RXST) & UART_RXST_RXERROR)
  1114. temp |= UART_INT_RXERR;
  1115. if(HWREGB(ui32Base + UART_O_RXST) & (UART_RXST_RXRDY | UART_RXST_BRKDT))
  1116. temp |= UART_INT_RXRDY_BRKDT;
  1117. if(HWREGB(ui32Base + UART_O_FFTX) & UART_FFTX_TXFFINT)
  1118. temp |= UART_INT_TXFF;
  1119. if(HWREGB(ui32Base + UART_O_FFRX) & UART_FFRX_RXFFINT)
  1120. temp |= UART_INT_RXFF;
  1121. return temp;
  1122. }
  1123. //*****************************************************************************
  1124. //
  1125. //! Clears UART interrupt sources.
  1126. //!
  1127. //! \param ui32Base is the base address of the UART port.
  1128. //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
  1129. //!
  1130. //! The specified UART interrupt sources are cleared, so that they no longer
  1131. //! assert. This function must be called in the interrupt handler to keep the
  1132. //! interrupt from being recognized again immediately upon exit.
  1133. //!
  1134. //! The \e ui32IntFlags parameter has the same definition as the \e ui32IntFlags
  1135. //! parameter to UARTIntEnable().
  1136. //!
  1137. //! \return None.
  1138. //
  1139. //*****************************************************************************
  1140. void
  1141. UARTIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  1142. {
  1143. //
  1144. // Check the arguments.
  1145. //
  1146. ASSERT(UARTBaseValid(ui32Base));
  1147. //
  1148. // Clear the requested interrupt sources.
  1149. //
  1150. if(ui32IntFlags & (UART_INT_RXERR | UART_INT_RXRDY_BRKDT))
  1151. {
  1152. HWREGB(ui32Base + UART_O_CTL1) &= ~UART_CTL1_SWRESET;
  1153. __asm(" nop");
  1154. __asm(" nop");
  1155. __asm(" nop");
  1156. __asm(" nop");
  1157. HWREGB(ui32Base + UART_O_CTL1) |= UART_CTL1_SWRESET;
  1158. }
  1159. if(ui32IntFlags & UART_INT_TXFF)
  1160. HWREGB(ui32Base + UART_O_FFTX) |= UART_FFTX_TXFFINTCLR;
  1161. if(ui32IntFlags & UART_INT_RXFF)
  1162. HWREGB(ui32Base + UART_O_FFRX) |= UART_FFRX_RXFFINTCLR;
  1163. }
  1164. //*****************************************************************************
  1165. //
  1166. //! Gets current receiver errors.
  1167. //!
  1168. //! \param ui32Base is the base address of the UART port.
  1169. //!
  1170. //! This function returns the current state of each of the 4 receiver error
  1171. //! sources. The returned errors are equivalent to the four error bits
  1172. //! returned via the previous call to UARTCharGet() or UARTCharGetNonBlocking()
  1173. //! with the exception that the overrun error is set immediately the overrun
  1174. //! occurs rather than when a character is next read.
  1175. //!
  1176. //! \return Returns a logical OR combination of the receiver error flags,
  1177. //! \b UART_RXERROR_FRAMING, \b UART_RXERROR_PARITY, \b UART_RXERROR_BREAK
  1178. //! and \b UART_RXERROR_OVERRUN.
  1179. //
  1180. //*****************************************************************************
  1181. uint32_t
  1182. UARTRxErrorGet(uint32_t ui32Base)
  1183. {
  1184. //
  1185. // Check the arguments.
  1186. //
  1187. ASSERT(UARTBaseValid(ui32Base));
  1188. //
  1189. // Return the current value of the receive status register.
  1190. //
  1191. return(HWREGH(ui32Base + UART_O_RXST));
  1192. }
  1193. //*****************************************************************************
  1194. //
  1195. //! Clears all reported receiver errors.
  1196. //!
  1197. //! \param ui32Base is the base address of the UART port.
  1198. //!
  1199. //! This function is used to clear all receiver error conditions reported via
  1200. //! UARTRxErrorGet(). If using the overrun, framing error, parity error or
  1201. //! break interrupts, this function must be called after clearing the interrupt
  1202. //! to ensure that later errors of the same type trigger another interrupt.
  1203. //!
  1204. //! \return None.
  1205. //
  1206. //*****************************************************************************
  1207. void
  1208. UARTRxErrorClear(uint32_t ui32Base)
  1209. {
  1210. //
  1211. // Check the arguments.
  1212. //
  1213. ASSERT(UARTBaseValid(ui32Base));
  1214. //
  1215. // To clear all errors a sw reset of the module is required
  1216. //
  1217. HWREGB(ui32Base + UART_O_CTL1) &= ~UART_CTL1_SWRESET;
  1218. __asm(" nop");
  1219. __asm(" nop");
  1220. __asm(" nop");
  1221. __asm(" nop");
  1222. HWREGB(ui32Base + UART_O_CTL1) |= UART_CTL1_SWRESET;
  1223. }
  1224. //*****************************************************************************
  1225. //
  1226. // Close the Doxygen group.
  1227. //! @}
  1228. //
  1229. //*****************************************************************************