uart.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. //*****************************************************************************
  2. //
  3. // uart.c - Driver for the UART.
  4. //
  5. // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup uart_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_memmap.h"
  49. #include "inc/hw_sysctl.h"
  50. #include "inc/hw_types.h"
  51. #include "inc/hw_uart.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/interrupt.h"
  54. #include "driverlib/uart.h"
  55. //*****************************************************************************
  56. //
  57. // The system clock divider defining the maximum baud rate supported by the
  58. // UART.
  59. //
  60. //*****************************************************************************
  61. #define UART_CLK_DIVIDER 8
  62. //*****************************************************************************
  63. //
  64. // A mapping of UART base address to interrupt number.
  65. //
  66. //*****************************************************************************
  67. static const uint32_t g_ppui32UARTIntMap[][2] =
  68. {
  69. { UART0_BASE, INT_UART0_TM4C123 },
  70. { UART1_BASE, INT_UART1_TM4C123 },
  71. { UART2_BASE, INT_UART2_TM4C123 },
  72. { UART3_BASE, INT_UART3_TM4C123 },
  73. { UART4_BASE, INT_UART4_TM4C123 },
  74. { UART5_BASE, INT_UART5_TM4C123 },
  75. { UART6_BASE, INT_UART6_TM4C123 },
  76. { UART7_BASE, INT_UART7_TM4C123 },
  77. };
  78. static const uint_fast8_t g_ui8UARTIntMapRows =
  79. sizeof(g_ppui32UARTIntMap) / sizeof(g_ppui32UARTIntMap[0]);
  80. static const uint32_t g_ppui32UARTIntMapSnowflake[][2] =
  81. {
  82. { UART0_BASE, INT_UART0_TM4C129 },
  83. { UART1_BASE, INT_UART1_TM4C129 },
  84. { UART2_BASE, INT_UART2_TM4C129 },
  85. { UART3_BASE, INT_UART3_TM4C129 },
  86. { UART4_BASE, INT_UART4_TM4C129 },
  87. { UART5_BASE, INT_UART5_TM4C129 },
  88. { UART6_BASE, INT_UART6_TM4C129 },
  89. { UART7_BASE, INT_UART7_TM4C129 },
  90. };
  91. static const uint_fast8_t g_ui8UARTIntMapRowsSnowflake =
  92. sizeof(g_ppui32UARTIntMapSnowflake) /
  93. sizeof(g_ppui32UARTIntMapSnowflake[0]);
  94. //*****************************************************************************
  95. //
  96. //! \internal
  97. //! Checks a UART base address.
  98. //!
  99. //! \param ui32Base is the base address of the UART port.
  100. //!
  101. //! This function determines if a UART port base address is valid.
  102. //!
  103. //! \return Returns \b true if the base address is valid and \b false
  104. //! otherwise.
  105. //
  106. //*****************************************************************************
  107. #ifdef DEBUG
  108. static bool
  109. _UARTBaseValid(uint32_t ui32Base)
  110. {
  111. return((ui32Base == UART0_BASE) || (ui32Base == UART1_BASE) ||
  112. (ui32Base == UART2_BASE) || (ui32Base == UART3_BASE) ||
  113. (ui32Base == UART4_BASE) || (ui32Base == UART5_BASE) ||
  114. (ui32Base == UART6_BASE) || (ui32Base == UART7_BASE));
  115. }
  116. #endif
  117. //*****************************************************************************
  118. //
  119. //! \internal
  120. //! Gets the UART interrupt number.
  121. //!
  122. //! \param ui32Base is the base address of the UART port.
  123. //!
  124. //! Given a UART base address, this function returns the corresponding
  125. //! interrupt number.
  126. //!
  127. //! \return Returns a UART interrupt number, or 0 if \e ui32Base is invalid.
  128. //
  129. //*****************************************************************************
  130. static uint32_t
  131. _UARTIntNumberGet(uint32_t ui32Base)
  132. {
  133. uint_fast8_t ui8Idx, ui8Rows;
  134. const uint32_t (*ppui32UARTIntMap)[2];
  135. //
  136. // Default interrupt map.
  137. //
  138. ppui32UARTIntMap = g_ppui32UARTIntMap;
  139. ui8Rows = g_ui8UARTIntMapRows;
  140. if(CLASS_IS_TM4C129)
  141. {
  142. ppui32UARTIntMap = g_ppui32UARTIntMapSnowflake;
  143. ui8Rows = g_ui8UARTIntMapRowsSnowflake;
  144. }
  145. //
  146. // Loop through the table that maps UART base addresses to interrupt
  147. // numbers.
  148. //
  149. for(ui8Idx = 0; ui8Idx < ui8Rows; ui8Idx++)
  150. {
  151. //
  152. // See if this base address matches.
  153. //
  154. if(ppui32UARTIntMap[ui8Idx][0] == ui32Base)
  155. {
  156. //
  157. // Return the corresponding interrupt number.
  158. //
  159. return(ppui32UARTIntMap[ui8Idx][1]);
  160. }
  161. }
  162. //
  163. // The base address could not be found, so return an error.
  164. //
  165. return(0);
  166. }
  167. //*****************************************************************************
  168. //
  169. //! Sets the type of parity.
  170. //!
  171. //! \param ui32Base is the base address of the UART port.
  172. //! \param ui32Parity specifies the type of parity to use.
  173. //!
  174. //! This function configures the type of parity to use for transmitting and
  175. //! expect when receiving. The \e ui32Parity parameter must be one of
  176. //! \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD,
  177. //! \b UART_CONFIG_PAR_ONE, or \b UART_CONFIG_PAR_ZERO. The last two
  178. //! parameters allow direct control of the parity bit; it is always either one
  179. //! or zero based on the mode.
  180. //!
  181. //! \return None.
  182. //
  183. //*****************************************************************************
  184. void
  185. UARTParityModeSet(uint32_t ui32Base, uint32_t ui32Parity)
  186. {
  187. //
  188. // Check the arguments.
  189. //
  190. ASSERT(_UARTBaseValid(ui32Base));
  191. ASSERT((ui32Parity == UART_CONFIG_PAR_NONE) ||
  192. (ui32Parity == UART_CONFIG_PAR_EVEN) ||
  193. (ui32Parity == UART_CONFIG_PAR_ODD) ||
  194. (ui32Parity == UART_CONFIG_PAR_ONE) ||
  195. (ui32Parity == UART_CONFIG_PAR_ZERO));
  196. //
  197. // Set the parity mode.
  198. //
  199. HWREG(ui32Base + UART_O_LCRH) = ((HWREG(ui32Base + UART_O_LCRH) &
  200. ~(UART_LCRH_SPS | UART_LCRH_EPS |
  201. UART_LCRH_PEN)) | ui32Parity);
  202. }
  203. //*****************************************************************************
  204. //
  205. //! Gets the type of parity currently being used.
  206. //!
  207. //! \param ui32Base is the base address of the UART port.
  208. //!
  209. //! This function gets the type of parity used for transmitting data and
  210. //! expected when receiving data.
  211. //!
  212. //! \return Returns the current parity settings, specified as one of
  213. //! \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD,
  214. //! \b UART_CONFIG_PAR_ONE, or \b UART_CONFIG_PAR_ZERO.
  215. //
  216. //*****************************************************************************
  217. uint32_t
  218. UARTParityModeGet(uint32_t ui32Base)
  219. {
  220. //
  221. // Check the arguments.
  222. //
  223. ASSERT(_UARTBaseValid(ui32Base));
  224. //
  225. // Return the current parity setting.
  226. //
  227. return(HWREG(ui32Base + UART_O_LCRH) &
  228. (UART_LCRH_SPS | UART_LCRH_EPS | UART_LCRH_PEN));
  229. }
  230. //*****************************************************************************
  231. //
  232. //! Sets the FIFO level at which interrupts are generated.
  233. //!
  234. //! \param ui32Base is the base address of the UART port.
  235. //! \param ui32TxLevel is the transmit FIFO interrupt level, specified as one
  236. //! of \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8, \b UART_FIFO_TX4_8,
  237. //! \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
  238. //! \param ui32RxLevel is the receive FIFO interrupt level, specified as one of
  239. //! \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8, \b UART_FIFO_RX4_8,
  240. //! \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
  241. //!
  242. //! This function configures the FIFO level at which transmit and receive
  243. //! interrupts are generated.
  244. //!
  245. //! \return None.
  246. //
  247. //*****************************************************************************
  248. void
  249. UARTFIFOLevelSet(uint32_t ui32Base, uint32_t ui32TxLevel,
  250. uint32_t ui32RxLevel)
  251. {
  252. //
  253. // Check the arguments.
  254. //
  255. ASSERT(_UARTBaseValid(ui32Base));
  256. ASSERT((ui32TxLevel == UART_FIFO_TX1_8) ||
  257. (ui32TxLevel == UART_FIFO_TX2_8) ||
  258. (ui32TxLevel == UART_FIFO_TX4_8) ||
  259. (ui32TxLevel == UART_FIFO_TX6_8) ||
  260. (ui32TxLevel == UART_FIFO_TX7_8));
  261. ASSERT((ui32RxLevel == UART_FIFO_RX1_8) ||
  262. (ui32RxLevel == UART_FIFO_RX2_8) ||
  263. (ui32RxLevel == UART_FIFO_RX4_8) ||
  264. (ui32RxLevel == UART_FIFO_RX6_8) ||
  265. (ui32RxLevel == UART_FIFO_RX7_8));
  266. //
  267. // Set the FIFO interrupt levels.
  268. //
  269. HWREG(ui32Base + UART_O_IFLS) = ui32TxLevel | ui32RxLevel;
  270. }
  271. //*****************************************************************************
  272. //
  273. //! Gets the FIFO level at which interrupts are generated.
  274. //!
  275. //! \param ui32Base is the base address of the UART port.
  276. //! \param pui32TxLevel is a pointer to storage for the transmit FIFO level,
  277. //! returned as one of \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8,
  278. //! \b UART_FIFO_TX4_8, \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
  279. //! \param pui32RxLevel is a pointer to storage for the receive FIFO level,
  280. //! returned as one of \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8,
  281. //! \b UART_FIFO_RX4_8, \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
  282. //!
  283. //! This function gets the FIFO level at which transmit and receive interrupts
  284. //! are generated.
  285. //!
  286. //! \return None.
  287. //
  288. //*****************************************************************************
  289. void
  290. UARTFIFOLevelGet(uint32_t ui32Base, uint32_t *pui32TxLevel,
  291. uint32_t *pui32RxLevel)
  292. {
  293. uint32_t ui32Temp;
  294. //
  295. // Check the arguments.
  296. //
  297. ASSERT(_UARTBaseValid(ui32Base));
  298. //
  299. // Read the FIFO level register.
  300. //
  301. ui32Temp = HWREG(ui32Base + UART_O_IFLS);
  302. //
  303. // Extract the transmit and receive FIFO levels.
  304. //
  305. *pui32TxLevel = ui32Temp & UART_IFLS_TX_M;
  306. *pui32RxLevel = ui32Temp & UART_IFLS_RX_M;
  307. }
  308. //*****************************************************************************
  309. //
  310. //! Sets the configuration of a UART.
  311. //!
  312. //! \param ui32Base is the base address of the UART port.
  313. //! \param ui32UARTClk is the rate of the clock supplied to the UART module.
  314. //! \param ui32Baud is the desired baud rate.
  315. //! \param ui32Config is the data format for the port (number of data bits,
  316. //! number of stop bits, and parity).
  317. //!
  318. //! This function configures the UART for operation in the specified data
  319. //! format. The baud rate is provided in the \e ui32Baud parameter and the
  320. //! data format in the \e ui32Config parameter.
  321. //!
  322. //! The \e ui32Config parameter is the logical OR of three values: the number
  323. //! of data bits, the number of stop bits, and the parity.
  324. //! \b UART_CONFIG_WLEN_8, \b UART_CONFIG_WLEN_7, \b UART_CONFIG_WLEN_6, and
  325. //! \b UART_CONFIG_WLEN_5 select from eight to five data bits per byte
  326. //! (respectively). \b UART_CONFIG_STOP_ONE and \b UART_CONFIG_STOP_TWO select
  327. //! one or two stop bits (respectively). \b UART_CONFIG_PAR_NONE,
  328. //! \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE,
  329. //! and \b UART_CONFIG_PAR_ZERO select the parity mode (no parity bit, even
  330. //! parity bit, odd parity bit, parity bit always one, and parity bit always
  331. //! zero, respectively).
  332. //!
  333. //! The peripheral clock is the same as the processor clock. The frequency of
  334. //! the system clock is the value returned by SysCtlClockGet(), or it can be
  335. //! explicitly hard coded if it is constant and known (to save the
  336. //! code/execution overhead of a call to SysCtlClockGet()).
  337. //!
  338. //! For Tiva parts that have the ability to specify the UART baud clock
  339. //! source (via UARTClockSourceSet()), the peripheral clock can be changed to
  340. //! PIOSC. In this case, the peripheral clock should be specified as
  341. //! 16,000,000 (the nominal rate of PIOSC).
  342. //!
  343. //! \return None.
  344. //
  345. //*****************************************************************************
  346. void
  347. UARTConfigSetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  348. uint32_t ui32Baud, uint32_t ui32Config)
  349. {
  350. uint32_t ui32Div;
  351. //
  352. // Check the arguments.
  353. //
  354. ASSERT(_UARTBaseValid(ui32Base));
  355. ASSERT(ui32Baud != 0);
  356. ASSERT(ui32UARTClk >= (ui32Baud * UART_CLK_DIVIDER));
  357. //
  358. // Stop the UART.
  359. //
  360. UARTDisable(ui32Base);
  361. //
  362. // Is the required baud rate greater than the maximum rate supported
  363. // without the use of high speed mode?
  364. //
  365. if((ui32Baud * 16) > ui32UARTClk)
  366. {
  367. //
  368. // Enable high speed mode.
  369. //
  370. HWREG(ui32Base + UART_O_CTL) |= UART_CTL_HSE;
  371. //
  372. // Half the supplied baud rate to compensate for enabling high speed
  373. // mode. This allows the following code to be common to both cases.
  374. //
  375. ui32Baud /= 2;
  376. }
  377. else
  378. {
  379. //
  380. // Disable high speed mode.
  381. //
  382. HWREG(ui32Base + UART_O_CTL) &= ~(UART_CTL_HSE);
  383. }
  384. //
  385. // Compute the fractional baud rate divider.
  386. //
  387. ui32Div = (((ui32UARTClk * 8) / ui32Baud) + 1) / 2;
  388. //
  389. // Set the baud rate.
  390. //
  391. HWREG(ui32Base + UART_O_IBRD) = ui32Div / 64;
  392. HWREG(ui32Base + UART_O_FBRD) = ui32Div % 64;
  393. //
  394. // Set parity, data length, and number of stop bits.
  395. //
  396. HWREG(ui32Base + UART_O_LCRH) = ui32Config;
  397. //
  398. // Clear the flags register.
  399. //
  400. HWREG(ui32Base + UART_O_FR) = 0;
  401. //
  402. // Start the UART.
  403. //
  404. UARTEnable(ui32Base);
  405. }
  406. //*****************************************************************************
  407. //
  408. //! Gets the current configuration of a UART.
  409. //!
  410. //! \param ui32Base is the base address of the UART port.
  411. //! \param ui32UARTClk is the rate of the clock supplied to the UART module.
  412. //! \param pui32Baud is a pointer to storage for the baud rate.
  413. //! \param pui32Config is a pointer to storage for the data format.
  414. //!
  415. //! This function determines the baud rate and data format for the UART, given
  416. //! an explicitly provided peripheral clock (hence the ExpClk suffix). The
  417. //! returned baud rate is the actual baud rate; it may not be the exact baud
  418. //! rate requested or an ``official'' baud rate. The data format returned in
  419. //! \e pui32Config is enumerated the same as the \e ui32Config parameter of
  420. //! UARTConfigSetExpClk().
  421. //!
  422. //! The peripheral clock is the same as the processor clock. The frequency of
  423. //! the system clock is the value returned by SysCtlClockGet(), or it can be
  424. //! explicitly hard coded if it is constant and known (to save the
  425. //! code/execution overhead of a call to SysCtlClockGet()).
  426. //!
  427. //! For Tiva parts that have the ability to specify the UART baud clock
  428. //! source (via UARTClockSourceSet()), the peripheral clock can be changed to
  429. //! PIOSC. In this case, the peripheral clock should be specified as
  430. //! 16,000,000 (the nominal rate of PIOSC).
  431. //!
  432. //! \return None.
  433. //
  434. //*****************************************************************************
  435. void
  436. UARTConfigGetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  437. uint32_t *pui32Baud, uint32_t *pui32Config)
  438. {
  439. uint32_t ui32Int, ui32Frac;
  440. //
  441. // Check the arguments.
  442. //
  443. ASSERT(_UARTBaseValid(ui32Base));
  444. //
  445. // Compute the baud rate.
  446. //
  447. ui32Int = HWREG(ui32Base + UART_O_IBRD);
  448. ui32Frac = HWREG(ui32Base + UART_O_FBRD);
  449. *pui32Baud = (ui32UARTClk * 4) / ((64 * ui32Int) + ui32Frac);
  450. //
  451. // See if high speed mode enabled.
  452. //
  453. if(HWREG(ui32Base + UART_O_CTL) & UART_CTL_HSE)
  454. {
  455. //
  456. // High speed mode is enabled so the actual baud rate is actually
  457. // double what was just calculated.
  458. //
  459. *pui32Baud *= 2;
  460. }
  461. //
  462. // Get the parity, data length, and number of stop bits.
  463. //
  464. *pui32Config = (HWREG(ui32Base + UART_O_LCRH) &
  465. (UART_LCRH_SPS | UART_LCRH_WLEN_M | UART_LCRH_STP2 |
  466. UART_LCRH_EPS | UART_LCRH_PEN));
  467. }
  468. //*****************************************************************************
  469. //
  470. //! Enables transmitting and receiving.
  471. //!
  472. //! \param ui32Base is the base address of the UART port.
  473. //!
  474. //! This function enables the UART and its transmit and receive FIFOs.
  475. //!
  476. //! \return None.
  477. //
  478. //*****************************************************************************
  479. void
  480. UARTEnable(uint32_t ui32Base)
  481. {
  482. //
  483. // Check the arguments.
  484. //
  485. ASSERT(_UARTBaseValid(ui32Base));
  486. //
  487. // Enable the FIFO.
  488. //
  489. HWREG(ui32Base + UART_O_LCRH) |= UART_LCRH_FEN;
  490. //
  491. // Enable RX, TX, and the UART.
  492. //
  493. HWREG(ui32Base + UART_O_CTL) |= (UART_CTL_UARTEN | UART_CTL_TXE |
  494. UART_CTL_RXE);
  495. }
  496. //*****************************************************************************
  497. //
  498. //! Disables transmitting and receiving.
  499. //!
  500. //! \param ui32Base is the base address of the UART port.
  501. //!
  502. //! This function disables the UART, waits for the end of transmission of the
  503. //! current character, and flushes the transmit FIFO.
  504. //!
  505. //! \return None.
  506. //
  507. //*****************************************************************************
  508. void
  509. UARTDisable(uint32_t ui32Base)
  510. {
  511. //
  512. // Check the arguments.
  513. //
  514. ASSERT(_UARTBaseValid(ui32Base));
  515. //
  516. // Wait for end of TX.
  517. //
  518. while(HWREG(ui32Base + UART_O_FR) & UART_FR_BUSY)
  519. {
  520. }
  521. //
  522. // Disable the FIFO.
  523. //
  524. HWREG(ui32Base + UART_O_LCRH) &= ~(UART_LCRH_FEN);
  525. //
  526. // Disable the UART.
  527. //
  528. HWREG(ui32Base + UART_O_CTL) &= ~(UART_CTL_UARTEN | UART_CTL_TXE |
  529. UART_CTL_RXE);
  530. }
  531. //*****************************************************************************
  532. //
  533. //! Enables the transmit and receive FIFOs.
  534. //!
  535. //! \param ui32Base is the base address of the UART port.
  536. //!
  537. //! This functions enables the transmit and receive FIFOs in the UART.
  538. //!
  539. //! \return None.
  540. //
  541. //*****************************************************************************
  542. void
  543. UARTFIFOEnable(uint32_t ui32Base)
  544. {
  545. //
  546. // Check the arguments.
  547. //
  548. ASSERT(_UARTBaseValid(ui32Base));
  549. //
  550. // Enable the FIFO.
  551. //
  552. HWREG(ui32Base + UART_O_LCRH) |= UART_LCRH_FEN;
  553. }
  554. //*****************************************************************************
  555. //
  556. //! Disables the transmit and receive FIFOs.
  557. //!
  558. //! \param ui32Base is the base address of the UART port.
  559. //!
  560. //! This function disables the transmit and receive FIFOs in the UART.
  561. //!
  562. //! \return None.
  563. //
  564. //*****************************************************************************
  565. void
  566. UARTFIFODisable(uint32_t ui32Base)
  567. {
  568. //
  569. // Check the arguments.
  570. //
  571. ASSERT(_UARTBaseValid(ui32Base));
  572. //
  573. // Disable the FIFO.
  574. //
  575. HWREG(ui32Base + UART_O_LCRH) &= ~(UART_LCRH_FEN);
  576. }
  577. //*****************************************************************************
  578. //
  579. //! Enables SIR (IrDA) mode on the specified UART.
  580. //!
  581. //! \param ui32Base is the base address of the UART port.
  582. //! \param bLowPower indicates if SIR Low Power Mode is to be used.
  583. //!
  584. //! This function enables SIR (IrDA) mode on the UART. If the \e bLowPower
  585. //! flag is set, then SIR low power mode will be selected as well. This
  586. //! function only has an effect if the UART has not been enabled by a call to
  587. //! UARTEnable(). The call UARTEnableSIR() must be made before a call to
  588. //! UARTConfigSetExpClk() because the UARTConfigSetExpClk() function calls the
  589. //! UARTEnable() function. Another option is to call UARTDisable() followed by
  590. //! UARTEnableSIR() and then enable the UART by calling UARTEnable().
  591. //!
  592. //! \note The availability of SIR (IrDA) operation varies with the Tiva
  593. //! part in use. Please consult the datasheet for the part you are using to
  594. //! determine whether this support is available.
  595. //!
  596. //! \return None.
  597. //
  598. //*****************************************************************************
  599. void
  600. UARTEnableSIR(uint32_t ui32Base, bool bLowPower)
  601. {
  602. //
  603. // Check the arguments.
  604. //
  605. ASSERT(_UARTBaseValid(ui32Base));
  606. //
  607. // Enable SIR and SIRLP (if appropriate).
  608. //
  609. if(bLowPower)
  610. {
  611. HWREG(ui32Base + UART_O_CTL) |= (UART_CTL_SIREN | UART_CTL_SIRLP);
  612. }
  613. else
  614. {
  615. HWREG(ui32Base + UART_O_CTL) |= (UART_CTL_SIREN);
  616. }
  617. }
  618. //*****************************************************************************
  619. //
  620. //! Disables SIR (IrDA) mode on the specified UART.
  621. //!
  622. //! \param ui32Base is the base address of the UART port.
  623. //!
  624. //! This function disables SIR(IrDA) mode on the UART. This function only has
  625. //! an effect if the UART has not been enabled by a call to UARTEnable(). The
  626. //! call UARTEnableSIR() must be made before a call to UARTConfigSetExpClk()
  627. //! because the UARTConfigSetExpClk() function calls the UARTEnable() function.
  628. //! Another option is to call UARTDisable() followed by UARTEnableSIR() and
  629. //! then enable the UART by calling UARTEnable().
  630. //!
  631. //! \note The availability of SIR (IrDA) operation varies with the Tiva
  632. //! part in use. Please consult the datasheet for the part you are using to
  633. //! determine whether this support is available.
  634. //!
  635. //! \return None.
  636. //
  637. //*****************************************************************************
  638. void
  639. UARTDisableSIR(uint32_t ui32Base)
  640. {
  641. //
  642. // Check the arguments.
  643. //
  644. ASSERT(_UARTBaseValid(ui32Base));
  645. //
  646. // Disable SIR and SIRLP (if appropriate).
  647. //
  648. HWREG(ui32Base + UART_O_CTL) &= ~(UART_CTL_SIREN | UART_CTL_SIRLP);
  649. }
  650. //*****************************************************************************
  651. //
  652. //! Enables ISO7816 smart card mode on the specified UART.
  653. //!
  654. //! \param ui32Base is the base address of the UART port.
  655. //!
  656. //! This function enables the SMART control bit for the ISO7816 smart card mode
  657. //! on the UART. This call also sets 8-bit word length and even parity as
  658. //! required by ISO7816.
  659. //!
  660. //! \note The availability of ISO7816 smart card mode varies with the Tiva
  661. //! part and UART in use. Please consult the datasheet for the part you are
  662. //! using to determine whether this support is available.
  663. //!
  664. //! \return None.
  665. //
  666. //*****************************************************************************
  667. void
  668. UARTSmartCardEnable(uint32_t ui32Base)
  669. {
  670. uint32_t ui32Val;
  671. //
  672. // Check the arguments.
  673. //
  674. ASSERT(_UARTBaseValid(ui32Base));
  675. //
  676. // Set 8-bit word length, even parity, 2 stop bits (note that although the
  677. // STP2 bit is ignored when in smartcard mode, this code lets the caller
  678. // read back the actual setting in use).
  679. //
  680. ui32Val = HWREG(ui32Base + UART_O_LCRH);
  681. ui32Val &= ~(UART_LCRH_SPS | UART_LCRH_EPS | UART_LCRH_PEN |
  682. UART_LCRH_WLEN_M);
  683. ui32Val |= UART_LCRH_WLEN_8 | UART_LCRH_PEN | UART_LCRH_EPS |
  684. UART_LCRH_STP2;
  685. HWREG(ui32Base + UART_O_LCRH) = ui32Val;
  686. //
  687. // Enable SMART mode.
  688. //
  689. HWREG(ui32Base + UART_O_CTL) |= UART_CTL_SMART;
  690. }
  691. //*****************************************************************************
  692. //
  693. //! Disables ISO7816 smart card mode on the specified UART.
  694. //!
  695. //! \param ui32Base is the base address of the UART port.
  696. //!
  697. //! This function clears the SMART (ISO7816 smart card) bit in the UART
  698. //! control register.
  699. //!
  700. //! \note The availability of ISO7816 smart card mode varies with the Tiva
  701. //! part and UART in use. Please consult the datasheet for the part you are
  702. //! using to determine whether this support is available.
  703. //!
  704. //! \return None.
  705. //
  706. //*****************************************************************************
  707. void
  708. UARTSmartCardDisable(uint32_t ui32Base)
  709. {
  710. //
  711. // Check the arguments.
  712. //
  713. ASSERT(_UARTBaseValid(ui32Base));
  714. //
  715. // Disable the SMART bit.
  716. //
  717. HWREG(ui32Base + UART_O_CTL) &= ~UART_CTL_SMART;
  718. }
  719. //*****************************************************************************
  720. //
  721. //! Sets the states of the DTR and/or RTS modem control signals.
  722. //!
  723. //! \param ui32Base is the base address of the UART port.
  724. //! \param ui32Control is a bit-mapped flag indicating which modem control bits
  725. //! should be set.
  726. //!
  727. //! This function configures the states of the DTR or RTS modem handshake
  728. //! outputs from the UART.
  729. //!
  730. //! The \e ui32Control parameter is the logical OR of any of the following:
  731. //!
  732. //! - \b UART_OUTPUT_DTR - The modem control DTR signal
  733. //! - \b UART_OUTPUT_RTS - The modem control RTS signal
  734. //!
  735. //! \note The availability of hardware modem handshake signals varies with the
  736. //! Tiva part and UART in use. Please consult the datasheet for the part
  737. //! you are using to determine whether this support is available.
  738. //!
  739. //! \return None.
  740. //
  741. //*****************************************************************************
  742. void
  743. UARTModemControlSet(uint32_t ui32Base, uint32_t ui32Control)
  744. {
  745. uint32_t ui32Temp;
  746. //
  747. // Check the arguments.
  748. //
  749. ASSERT(ui32Base == UART1_BASE);
  750. ASSERT((ui32Control & ~(UART_OUTPUT_RTS | UART_OUTPUT_DTR)) == 0);
  751. //
  752. // Set the appropriate modem control output bits.
  753. //
  754. ui32Temp = HWREG(ui32Base + UART_O_CTL);
  755. ui32Temp |= (ui32Control & (UART_OUTPUT_RTS | UART_OUTPUT_DTR));
  756. HWREG(ui32Base + UART_O_CTL) = ui32Temp;
  757. }
  758. //*****************************************************************************
  759. //
  760. //! Clears the states of the DTR and/or RTS modem control signals.
  761. //!
  762. //! \param ui32Base is the base address of the UART port.
  763. //! \param ui32Control is a bit-mapped flag indicating which modem control bits
  764. //! should be set.
  765. //!
  766. //! This function clears the states of the DTR or RTS modem handshake outputs
  767. //! from the UART.
  768. //!
  769. //! The \e ui32Control parameter is the logical OR of any of the following:
  770. //!
  771. //! - \b UART_OUTPUT_DTR - The modem control DTR signal
  772. //! - \b UART_OUTPUT_RTS - The modem control RTS signal
  773. //!
  774. //! \note The availability of hardware modem handshake signals varies with the
  775. //! Tiva part and UART in use. Please consult the datasheet for the part
  776. //! you are using to determine whether this support is available.
  777. //!
  778. //! \return None.
  779. //
  780. //*****************************************************************************
  781. void
  782. UARTModemControlClear(uint32_t ui32Base, uint32_t ui32Control)
  783. {
  784. uint32_t ui32Temp;
  785. //
  786. // Check the arguments.
  787. //
  788. ASSERT(ui32Base == UART1_BASE);
  789. ASSERT((ui32Control & ~(UART_OUTPUT_RTS | UART_OUTPUT_DTR)) == 0);
  790. //
  791. // Set the appropriate modem control output bits.
  792. //
  793. ui32Temp = HWREG(ui32Base + UART_O_CTL);
  794. ui32Temp &= ~(ui32Control & (UART_OUTPUT_RTS | UART_OUTPUT_DTR));
  795. HWREG(ui32Base + UART_O_CTL) = ui32Temp;
  796. }
  797. //*****************************************************************************
  798. //
  799. //! Gets the states of the DTR and RTS modem control signals.
  800. //!
  801. //! \param ui32Base is the base address of the UART port.
  802. //!
  803. //! This function returns the current states of each of the two UART modem
  804. //! control signals, DTR and RTS.
  805. //!
  806. //! \note The availability of hardware modem handshake signals varies with the
  807. //! Tiva part and UART in use. Please consult the datasheet for the part
  808. //! you are using to determine whether this support is available.
  809. //!
  810. //! \return Returns the states of the handshake output signals. This value is
  811. //! a logical OR combination of values \b UART_OUTPUT_RTS and
  812. //! \b UART_OUTPUT_DTR where the presence of each flag indicates that the
  813. //! associated signal is asserted.
  814. //
  815. //*****************************************************************************
  816. uint32_t
  817. UARTModemControlGet(uint32_t ui32Base)
  818. {
  819. //
  820. // Check the arguments.
  821. //
  822. ASSERT(ui32Base == UART1_BASE);
  823. return(HWREG(ui32Base + UART_O_CTL) & (UART_OUTPUT_RTS | UART_OUTPUT_DTR));
  824. }
  825. //*****************************************************************************
  826. //
  827. //! Gets the states of the RI, DCD, DSR and CTS modem status signals.
  828. //!
  829. //! \param ui32Base is the base address of the UART port.
  830. //!
  831. //! This function returns the current states of each of the four UART modem
  832. //! status signals, RI, DCD, DSR and CTS.
  833. //!
  834. //! \note The availability of hardware modem handshake signals varies with the
  835. //! Tiva part and UART in use. Please consult the datasheet for the part
  836. //! you are using to determine whether this support is available.
  837. //!
  838. //! \return Returns the states of the handshake output signals. This value
  839. //! is a logical OR combination of values \b UART_INPUT_RI,
  840. //! \b UART_INPUT_DCD, \b UART_INPUT_CTS and \b UART_INPUT_DSR where the
  841. //! presence of each flag indicates that the associated signal is asserted.
  842. //
  843. //*****************************************************************************
  844. uint32_t
  845. UARTModemStatusGet(uint32_t ui32Base)
  846. {
  847. //
  848. // Check the arguments.
  849. //
  850. ASSERT(ui32Base == UART1_BASE);
  851. return(HWREG(ui32Base + UART_O_FR) & (UART_INPUT_RI | UART_INPUT_DCD |
  852. UART_INPUT_CTS | UART_INPUT_DSR));
  853. }
  854. //*****************************************************************************
  855. //
  856. //! Sets the UART hardware flow control mode to be used.
  857. //!
  858. //! \param ui32Base is the base address of the UART port.
  859. //! \param ui32Mode indicates the flow control modes to be used. This
  860. //! parameter is a logical OR combination of values \b UART_FLOWCONTROL_TX and
  861. //! \b UART_FLOWCONTROL_RX to enable hardware transmit (CTS) and receive (RTS)
  862. //! flow control or \b UART_FLOWCONTROL_NONE to disable hardware flow control.
  863. //!
  864. //! This function configures the required hardware flow control modes. If
  865. //! \e ui32Mode contains flag \b UART_FLOWCONTROL_TX, data is only transmitted
  866. //! if the incoming CTS signal is asserted. If \e ui32Mode contains flag
  867. //! \b UART_FLOWCONTROL_RX, the RTS output is controlled by the hardware and is
  868. //! asserted only when there is space available in the receive FIFO. If no
  869. //! hardware flow control is required, \b UART_FLOWCONTROL_NONE should be
  870. //! passed.
  871. //!
  872. //! \note The availability of hardware flow control varies with the Tiva
  873. //! part and UART in use. Please consult the datasheet for the part you are
  874. //! using to determine whether this support is available.
  875. //!
  876. //! \return None.
  877. //
  878. //*****************************************************************************
  879. void
  880. UARTFlowControlSet(uint32_t ui32Base, uint32_t ui32Mode)
  881. {
  882. //
  883. // Check the arguments.
  884. //
  885. ASSERT(_UARTBaseValid(ui32Base));
  886. ASSERT((ui32Mode & ~(UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX)) == 0);
  887. //
  888. // Set the flow control mode as requested.
  889. //
  890. HWREG(ui32Base + UART_O_CTL) = ((HWREG(ui32Base + UART_O_CTL) &
  891. ~(UART_FLOWCONTROL_TX |
  892. UART_FLOWCONTROL_RX)) | ui32Mode);
  893. }
  894. //*****************************************************************************
  895. //
  896. //! Returns the UART hardware flow control mode currently in use.
  897. //!
  898. //! \param ui32Base is the base address of the UART port.
  899. //!
  900. //! This function returns the current hardware flow control mode.
  901. //!
  902. //! \note The availability of hardware flow control varies with the Tiva
  903. //! part and UART in use. Please consult the datasheet for the part you are
  904. //! using to determine whether this support is available.
  905. //!
  906. //! \return Returns the current flow control mode in use. This value is a
  907. //! logical OR combination of values \b UART_FLOWCONTROL_TX if transmit
  908. //! (CTS) flow control is enabled and \b UART_FLOWCONTROL_RX if receive (RTS)
  909. //! flow control is in use. If hardware flow control is disabled,
  910. //! \b UART_FLOWCONTROL_NONE is returned.
  911. //
  912. //*****************************************************************************
  913. uint32_t
  914. UARTFlowControlGet(uint32_t ui32Base)
  915. {
  916. //
  917. // Check the arguments.
  918. //
  919. ASSERT(_UARTBaseValid(ui32Base));
  920. return(HWREG(ui32Base + UART_O_CTL) & (UART_FLOWCONTROL_TX |
  921. UART_FLOWCONTROL_RX));
  922. }
  923. //*****************************************************************************
  924. //
  925. //! Sets the operating mode for the UART transmit interrupt.
  926. //!
  927. //! \param ui32Base is the base address of the UART port.
  928. //! \param ui32Mode is the operating mode for the transmit interrupt. It may
  929. //! be \b UART_TXINT_MODE_EOT to trigger interrupts when the transmitter is
  930. //! idle or \b UART_TXINT_MODE_FIFO to trigger based on the current transmit
  931. //! FIFO level.
  932. //!
  933. //! This function allows the mode of the UART transmit interrupt to be set. By
  934. //! default, the transmit interrupt is asserted when the FIFO level falls past
  935. //! a threshold set via a call to UARTFIFOLevelSet(). Alternatively, if this
  936. //! function is called with \e ui32Mode set to \b UART_TXINT_MODE_EOT, the
  937. //! transmit interrupt is asserted once the transmitter is completely idle -
  938. //! the transmit FIFO is empty and all bits, including any stop bits, have
  939. //! cleared the transmitter.
  940. //!
  941. //! \note The availability of end-of-transmission mode varies with the
  942. //! Tiva part in use. Please consult the datasheet for the part you are
  943. //! using to determine whether this support is available.
  944. //!
  945. //! \return None.
  946. //
  947. //*****************************************************************************
  948. void
  949. UARTTxIntModeSet(uint32_t ui32Base, uint32_t ui32Mode)
  950. {
  951. //
  952. // Check the arguments.
  953. //
  954. ASSERT(_UARTBaseValid(ui32Base));
  955. ASSERT((ui32Mode == UART_TXINT_MODE_EOT) ||
  956. (ui32Mode == UART_TXINT_MODE_FIFO));
  957. //
  958. // Set or clear the EOT bit of the UART control register as appropriate.
  959. //
  960. HWREG(ui32Base + UART_O_CTL) = ((HWREG(ui32Base + UART_O_CTL) &
  961. ~(UART_TXINT_MODE_EOT |
  962. UART_TXINT_MODE_FIFO)) | ui32Mode);
  963. }
  964. //*****************************************************************************
  965. //
  966. //! Returns the current operating mode for the UART transmit interrupt.
  967. //!
  968. //! \param ui32Base is the base address of the UART port.
  969. //!
  970. //! This function returns the current operating mode for the UART transmit
  971. //! interrupt. The return value is \b UART_TXINT_MODE_EOT if the transmit
  972. //! interrupt is currently configured to be asserted once the transmitter is
  973. //! completely idle - the transmit FIFO is empty and all bits, including any
  974. //! stop bits, have cleared the transmitter. The return value is
  975. //! \b UART_TXINT_MODE_FIFO if the interrupt is configured to be asserted based
  976. //! on the level of the transmit FIFO.
  977. //!
  978. //! \note The availability of end-of-transmission mode varies with the
  979. //! Tiva part in use. Please consult the datasheet for the part you are
  980. //! using to determine whether this support is available.
  981. //!
  982. //! \return Returns \b UART_TXINT_MODE_FIFO or \b UART_TXINT_MODE_EOT.
  983. //
  984. //*****************************************************************************
  985. uint32_t
  986. UARTTxIntModeGet(uint32_t ui32Base)
  987. {
  988. //
  989. // Check the arguments.
  990. //
  991. ASSERT(_UARTBaseValid(ui32Base));
  992. //
  993. // Return the current transmit interrupt mode.
  994. //
  995. return(HWREG(ui32Base + UART_O_CTL) & (UART_TXINT_MODE_EOT |
  996. UART_TXINT_MODE_FIFO));
  997. }
  998. //*****************************************************************************
  999. //
  1000. //! Determines if there are any characters in the receive FIFO.
  1001. //!
  1002. //! \param ui32Base is the base address of the UART port.
  1003. //!
  1004. //! This function returns a flag indicating whether or not there is data
  1005. //! available in the receive FIFO.
  1006. //!
  1007. //! \return Returns \b true if there is data in the receive FIFO or \b false
  1008. //! if there is no data in the receive FIFO.
  1009. //
  1010. //*****************************************************************************
  1011. bool
  1012. UARTCharsAvail(uint32_t ui32Base)
  1013. {
  1014. //
  1015. // Check the arguments.
  1016. //
  1017. ASSERT(_UARTBaseValid(ui32Base));
  1018. //
  1019. // Return the availability of characters.
  1020. //
  1021. return((HWREG(ui32Base + UART_O_FR) & UART_FR_RXFE) ? false : true);
  1022. }
  1023. //*****************************************************************************
  1024. //
  1025. //! Determines if there is any space in the transmit FIFO.
  1026. //!
  1027. //! \param ui32Base is the base address of the UART port.
  1028. //!
  1029. //! This function returns a flag indicating whether or not there is space
  1030. //! available in the transmit FIFO.
  1031. //!
  1032. //! \return Returns \b true if there is space available in the transmit FIFO
  1033. //! or \b false if there is no space available in the transmit FIFO.
  1034. //
  1035. //*****************************************************************************
  1036. bool
  1037. UARTSpaceAvail(uint32_t ui32Base)
  1038. {
  1039. //
  1040. // Check the arguments.
  1041. //
  1042. ASSERT(_UARTBaseValid(ui32Base));
  1043. //
  1044. // Return the availability of space.
  1045. //
  1046. return((HWREG(ui32Base + UART_O_FR) & UART_FR_TXFF) ? false : true);
  1047. }
  1048. //*****************************************************************************
  1049. //
  1050. //! Receives a character from the specified port.
  1051. //!
  1052. //! \param ui32Base is the base address of the UART port.
  1053. //!
  1054. //! This function gets a character from the receive FIFO for the specified
  1055. //! port.
  1056. //!
  1057. //! \return Returns the character read from the specified port, cast as a
  1058. //! \e int32_t. A \b -1 is returned if there are no characters present in the
  1059. //! receive FIFO. The UARTCharsAvail() function should be called before
  1060. //! attempting to call this function.
  1061. //
  1062. //*****************************************************************************
  1063. int32_t
  1064. UARTCharGetNonBlocking(uint32_t ui32Base)
  1065. {
  1066. //
  1067. // Check the arguments.
  1068. //
  1069. ASSERT(_UARTBaseValid(ui32Base));
  1070. //
  1071. // See if there are any characters in the receive FIFO.
  1072. //
  1073. if(!(HWREG(ui32Base + UART_O_FR) & UART_FR_RXFE))
  1074. {
  1075. //
  1076. // Read and return the next character.
  1077. //
  1078. return(HWREG(ui32Base + UART_O_DR));
  1079. }
  1080. else
  1081. {
  1082. //
  1083. // There are no characters, so return a failure.
  1084. //
  1085. return(-1);
  1086. }
  1087. }
  1088. //*****************************************************************************
  1089. //
  1090. //! Waits for a character from the specified port.
  1091. //!
  1092. //! \param ui32Base is the base address of the UART port.
  1093. //!
  1094. //! This function gets a character from the receive FIFO for the specified
  1095. //! port. If there are no characters available, this function waits until a
  1096. //! character is received before returning.
  1097. //!
  1098. //! \return Returns the character read from the specified port, cast as a
  1099. //! \e int32_t.
  1100. //
  1101. //*****************************************************************************
  1102. int32_t
  1103. UARTCharGet(uint32_t ui32Base)
  1104. {
  1105. //
  1106. // Check the arguments.
  1107. //
  1108. ASSERT(_UARTBaseValid(ui32Base));
  1109. //
  1110. // Wait until a char is available.
  1111. //
  1112. while(HWREG(ui32Base + UART_O_FR) & UART_FR_RXFE)
  1113. {
  1114. }
  1115. //
  1116. // Now get the char.
  1117. //
  1118. return(HWREG(ui32Base + UART_O_DR));
  1119. }
  1120. //*****************************************************************************
  1121. //
  1122. //! Sends a character to the specified port.
  1123. //!
  1124. //! \param ui32Base is the base address of the UART port.
  1125. //! \param ucData is the character to be transmitted.
  1126. //!
  1127. //! This function writes the character \e ucData to the transmit FIFO for the
  1128. //! specified port. This function does not block, so if there is no space
  1129. //! available, then a \b false is returned and the application must retry the
  1130. //! function later.
  1131. //!
  1132. //! \return Returns \b true if the character was successfully placed in the
  1133. //! transmit FIFO or \b false if there was no space available in the transmit
  1134. //! FIFO.
  1135. //
  1136. //*****************************************************************************
  1137. bool
  1138. UARTCharPutNonBlocking(uint32_t ui32Base, unsigned char ucData)
  1139. {
  1140. //
  1141. // Check the arguments.
  1142. //
  1143. ASSERT(_UARTBaseValid(ui32Base));
  1144. //
  1145. // See if there is space in the transmit FIFO.
  1146. //
  1147. if(!(HWREG(ui32Base + UART_O_FR) & UART_FR_TXFF))
  1148. {
  1149. //
  1150. // Write this character to the transmit FIFO.
  1151. //
  1152. HWREG(ui32Base + UART_O_DR) = ucData;
  1153. //
  1154. // Success.
  1155. //
  1156. return(true);
  1157. }
  1158. else
  1159. {
  1160. //
  1161. // There is no space in the transmit FIFO, so return a failure.
  1162. //
  1163. return(false);
  1164. }
  1165. }
  1166. //*****************************************************************************
  1167. //
  1168. //! Waits to send a character from the specified port.
  1169. //!
  1170. //! \param ui32Base is the base address of the UART port.
  1171. //! \param ucData is the character to be transmitted.
  1172. //!
  1173. //! This function sends the character \e ucData to the transmit FIFO for the
  1174. //! specified port. If there is no space available in the transmit FIFO, this
  1175. //! function waits until there is space available before returning.
  1176. //!
  1177. //! \return None.
  1178. //
  1179. //*****************************************************************************
  1180. void
  1181. UARTCharPut(uint32_t ui32Base, unsigned char ucData)
  1182. {
  1183. //
  1184. // Check the arguments.
  1185. //
  1186. ASSERT(_UARTBaseValid(ui32Base));
  1187. //
  1188. // Wait until space is available.
  1189. //
  1190. while(HWREG(ui32Base + UART_O_FR) & UART_FR_TXFF)
  1191. {
  1192. }
  1193. //
  1194. // Send the char.
  1195. //
  1196. HWREG(ui32Base + UART_O_DR) = ucData;
  1197. }
  1198. //*****************************************************************************
  1199. //
  1200. //! Causes a BREAK to be sent.
  1201. //!
  1202. //! \param ui32Base is the base address of the UART port.
  1203. //! \param bBreakState controls the output level.
  1204. //!
  1205. //! Calling this function with \e bBreakState set to \b true asserts a break
  1206. //! condition on the UART. Calling this function with \e bBreakState set to
  1207. //! \b false removes the break condition. For proper transmission of a break
  1208. //! command, the break must be asserted for at least two complete frames.
  1209. //!
  1210. //! \return None.
  1211. //
  1212. //*****************************************************************************
  1213. void
  1214. UARTBreakCtl(uint32_t ui32Base, bool bBreakState)
  1215. {
  1216. //
  1217. // Check the arguments.
  1218. //
  1219. ASSERT(_UARTBaseValid(ui32Base));
  1220. //
  1221. // Set the break condition as requested.
  1222. //
  1223. HWREG(ui32Base + UART_O_LCRH) =
  1224. (bBreakState ?
  1225. (HWREG(ui32Base + UART_O_LCRH) | UART_LCRH_BRK) :
  1226. (HWREG(ui32Base + UART_O_LCRH) & ~(UART_LCRH_BRK)));
  1227. }
  1228. //*****************************************************************************
  1229. //
  1230. //! Determines whether the UART transmitter is busy or not.
  1231. //!
  1232. //! \param ui32Base is the base address of the UART port.
  1233. //!
  1234. //! This function allows the caller to determine whether all transmitted bytes
  1235. //! have cleared the transmitter hardware. If \b false is returned, the
  1236. //! transmit FIFO is empty and all bits of the last transmitted character,
  1237. //! including all stop bits, have left the hardware shift register.
  1238. //!
  1239. //! \return Returns \b true if the UART is transmitting or \b false if all
  1240. //! transmissions are complete.
  1241. //
  1242. //*****************************************************************************
  1243. bool
  1244. UARTBusy(uint32_t ui32Base)
  1245. {
  1246. //
  1247. // Check the argument.
  1248. //
  1249. ASSERT(_UARTBaseValid(ui32Base));
  1250. //
  1251. // Determine if the UART is busy.
  1252. //
  1253. return((HWREG(ui32Base + UART_O_FR) & UART_FR_BUSY) ? true : false);
  1254. }
  1255. //*****************************************************************************
  1256. //
  1257. //! Registers an interrupt handler for a UART interrupt.
  1258. //!
  1259. //! \param ui32Base is the base address of the UART port.
  1260. //! \param pfnHandler is a pointer to the function to be called when the
  1261. //! UART interrupt occurs.
  1262. //!
  1263. //! This function does the actual registering of the interrupt handler. This
  1264. //! function enables the global interrupt in the interrupt controller; specific
  1265. //! UART interrupts must be enabled via UARTIntEnable(). It is the interrupt
  1266. //! handler's responsibility to clear the interrupt source.
  1267. //!
  1268. //! \sa IntRegister() for important information about registering interrupt
  1269. //! handlers.
  1270. //!
  1271. //! \return None.
  1272. //
  1273. //*****************************************************************************
  1274. void
  1275. UARTIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  1276. {
  1277. uint32_t ui32Int;
  1278. //
  1279. // Check the arguments.
  1280. //
  1281. ASSERT(_UARTBaseValid(ui32Base));
  1282. //
  1283. // Determine the interrupt number based on the UART port.
  1284. //
  1285. ui32Int = _UARTIntNumberGet(ui32Base);
  1286. ASSERT(ui32Int != 0);
  1287. //
  1288. // Register the interrupt handler.
  1289. //
  1290. IntRegister(ui32Int, pfnHandler);
  1291. //
  1292. // Enable the UART interrupt.
  1293. //
  1294. IntEnable(ui32Int);
  1295. }
  1296. //*****************************************************************************
  1297. //
  1298. //! Unregisters an interrupt handler for a UART interrupt.
  1299. //!
  1300. //! \param ui32Base is the base address of the UART port.
  1301. //!
  1302. //! This function does the actual unregistering of the interrupt handler. It
  1303. //! clears the handler to be called when a UART interrupt occurs. This
  1304. //! function also masks off the interrupt in the interrupt controller so that
  1305. //! the interrupt handler no longer is called.
  1306. //!
  1307. //! \sa IntRegister() for important information about registering interrupt
  1308. //! handlers.
  1309. //!
  1310. //! \return None.
  1311. //
  1312. //*****************************************************************************
  1313. void
  1314. UARTIntUnregister(uint32_t ui32Base)
  1315. {
  1316. uint32_t ui32Int;
  1317. //
  1318. // Check the arguments.
  1319. //
  1320. ASSERT(_UARTBaseValid(ui32Base));
  1321. //
  1322. // Determine the interrupt number based on the UART port.
  1323. //
  1324. ui32Int = _UARTIntNumberGet(ui32Base);
  1325. ASSERT(ui32Int != 0);
  1326. //
  1327. // Disable the interrupt.
  1328. //
  1329. IntDisable(ui32Int);
  1330. //
  1331. // Unregister the interrupt handler.
  1332. //
  1333. IntUnregister(ui32Int);
  1334. }
  1335. //*****************************************************************************
  1336. //
  1337. //! Enables individual UART interrupt sources.
  1338. //!
  1339. //! \param ui32Base is the base address of the UART port.
  1340. //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
  1341. //!
  1342. //! This function enables the indicated UART interrupt sources. Only the
  1343. //! sources that are enabled can be reflected to the processor interrupt;
  1344. //! disabled sources have no effect on the processor.
  1345. //!
  1346. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  1347. //!
  1348. //! - \b UART_INT_9BIT - 9-bit Address Match interrupt
  1349. //! - \b UART_INT_OE - Overrun Error interrupt
  1350. //! - \b UART_INT_BE - Break Error interrupt
  1351. //! - \b UART_INT_PE - Parity Error interrupt
  1352. //! - \b UART_INT_FE - Framing Error interrupt
  1353. //! - \b UART_INT_RT - Receive Timeout interrupt
  1354. //! - \b UART_INT_TX - Transmit interrupt
  1355. //! - \b UART_INT_RX - Receive interrupt
  1356. //! - \b UART_INT_DSR - DSR interrupt
  1357. //! - \b UART_INT_DCD - DCD interrupt
  1358. //! - \b UART_INT_CTS - CTS interrupt
  1359. //! - \b UART_INT_RI - RI interrupt
  1360. //!
  1361. //! \return None.
  1362. //
  1363. //*****************************************************************************
  1364. void
  1365. UARTIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1366. {
  1367. //
  1368. // Check the arguments.
  1369. //
  1370. ASSERT(_UARTBaseValid(ui32Base));
  1371. //
  1372. // Enable the specified interrupts.
  1373. //
  1374. HWREG(ui32Base + UART_O_IM) |= ui32IntFlags;
  1375. }
  1376. //*****************************************************************************
  1377. //
  1378. //! Disables individual UART interrupt sources.
  1379. //!
  1380. //! \param ui32Base is the base address of the UART port.
  1381. //! \param ui32IntFlags is the bit mask of the interrupt sources to be
  1382. //! disabled.
  1383. //!
  1384. //! This function disables the indicated UART interrupt sources. Only the
  1385. //! sources that are enabled can be reflected to the processor interrupt;
  1386. //! disabled sources have no effect on the processor.
  1387. //!
  1388. //! The \e ui32IntFlags parameter has the same definition as the
  1389. //! \e ui32IntFlags parameter to UARTIntEnable().
  1390. //!
  1391. //! \return None.
  1392. //
  1393. //*****************************************************************************
  1394. void
  1395. UARTIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1396. {
  1397. //
  1398. // Check the arguments.
  1399. //
  1400. ASSERT(_UARTBaseValid(ui32Base));
  1401. //
  1402. // Disable the specified interrupts.
  1403. //
  1404. HWREG(ui32Base + UART_O_IM) &= ~(ui32IntFlags);
  1405. }
  1406. //*****************************************************************************
  1407. //
  1408. //! Gets the current interrupt status.
  1409. //!
  1410. //! \param ui32Base is the base address of the UART port.
  1411. //! \param bMasked is \b false if the raw interrupt status is required and
  1412. //! \b true if the masked interrupt status is required.
  1413. //!
  1414. //! This function returns the interrupt status for the specified UART. Either
  1415. //! the raw interrupt status or the status of interrupts that are allowed to
  1416. //! reflect to the processor can be returned.
  1417. //!
  1418. //! \return Returns the current interrupt status, enumerated as a bit field of
  1419. //! values described in UARTIntEnable().
  1420. //
  1421. //*****************************************************************************
  1422. uint32_t
  1423. UARTIntStatus(uint32_t ui32Base, bool bMasked)
  1424. {
  1425. //
  1426. // Check the arguments.
  1427. //
  1428. ASSERT(_UARTBaseValid(ui32Base));
  1429. //
  1430. // Return either the interrupt status or the raw interrupt status as
  1431. // requested.
  1432. //
  1433. if(bMasked)
  1434. {
  1435. return(HWREG(ui32Base + UART_O_MIS));
  1436. }
  1437. else
  1438. {
  1439. return(HWREG(ui32Base + UART_O_RIS));
  1440. }
  1441. }
  1442. //*****************************************************************************
  1443. //
  1444. //! Clears UART interrupt sources.
  1445. //!
  1446. //! \param ui32Base is the base address of the UART port.
  1447. //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
  1448. //!
  1449. //! The specified UART interrupt sources are cleared, so that they no longer
  1450. //! assert. This function must be called in the interrupt handler to keep the
  1451. //! interrupt from being triggered again immediately upon exit.
  1452. //!
  1453. //! The \e ui32IntFlags parameter has the same definition as the
  1454. //! \e ui32IntFlags parameter to UARTIntEnable().
  1455. //!
  1456. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1457. //! take several clock cycles before the interrupt source is actually cleared.
  1458. //! Therefore, it is recommended that the interrupt source be cleared early in
  1459. //! the interrupt handler (as opposed to the very last action) to avoid
  1460. //! returning from the interrupt handler before the interrupt source is
  1461. //! actually cleared. Failure to do so may result in the interrupt handler
  1462. //! being immediately reentered (because the interrupt controller still sees
  1463. //! the interrupt source asserted).
  1464. //!
  1465. //! \return None.
  1466. //
  1467. //*****************************************************************************
  1468. void
  1469. UARTIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  1470. {
  1471. //
  1472. // Check the arguments.
  1473. //
  1474. ASSERT(_UARTBaseValid(ui32Base));
  1475. //
  1476. // Clear the requested interrupt sources.
  1477. //
  1478. HWREG(ui32Base + UART_O_ICR) = ui32IntFlags;
  1479. }
  1480. //*****************************************************************************
  1481. //
  1482. //! Enable UART uDMA operation.
  1483. //!
  1484. //! \param ui32Base is the base address of the UART port.
  1485. //! \param ui32DMAFlags is a bit mask of the uDMA features to enable.
  1486. //!
  1487. //! The specified UART uDMA features are enabled. The UART can be
  1488. //! configured to use uDMA for transmit or receive and to disable
  1489. //! receive if an error occurs. The \e ui32DMAFlags parameter is the
  1490. //! logical OR of any of the following values:
  1491. //!
  1492. //! - \b UART_DMA_RX - enable uDMA for receive
  1493. //! - \b UART_DMA_TX - enable uDMA for transmit
  1494. //! - \b UART_DMA_ERR_RXSTOP - disable uDMA receive on UART error
  1495. //!
  1496. //! \note The uDMA controller must also be set up before DMA can be used
  1497. //! with the UART.
  1498. //!
  1499. //! \return None.
  1500. //
  1501. //*****************************************************************************
  1502. void
  1503. UARTDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags)
  1504. {
  1505. //
  1506. // Check the arguments.
  1507. //
  1508. ASSERT(_UARTBaseValid(ui32Base));
  1509. //
  1510. // Set the requested bits in the UART uDMA control register.
  1511. //
  1512. HWREG(ui32Base + UART_O_DMACTL) |= ui32DMAFlags;
  1513. }
  1514. //*****************************************************************************
  1515. //
  1516. //! Disable UART uDMA operation.
  1517. //!
  1518. //! \param ui32Base is the base address of the UART port.
  1519. //! \param ui32DMAFlags is a bit mask of the uDMA features to disable.
  1520. //!
  1521. //! This function is used to disable UART uDMA features that were enabled
  1522. //! by UARTDMAEnable(). The specified UART uDMA features are disabled. The
  1523. //! \e ui32DMAFlags parameter is the logical OR of any of the following values:
  1524. //!
  1525. //! - \b UART_DMA_RX - disable uDMA for receive
  1526. //! - \b UART_DMA_TX - disable uDMA for transmit
  1527. //! - \b UART_DMA_ERR_RXSTOP - do not disable uDMA receive on UART error
  1528. //!
  1529. //! \return None.
  1530. //
  1531. //*****************************************************************************
  1532. void
  1533. UARTDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags)
  1534. {
  1535. //
  1536. // Check the arguments.
  1537. //
  1538. ASSERT(_UARTBaseValid(ui32Base));
  1539. //
  1540. // Clear the requested bits in the UART uDMA control register.
  1541. //
  1542. HWREG(ui32Base + UART_O_DMACTL) &= ~ui32DMAFlags;
  1543. }
  1544. //*****************************************************************************
  1545. //
  1546. //! Gets current receiver errors.
  1547. //!
  1548. //! \param ui32Base is the base address of the UART port.
  1549. //!
  1550. //! This function returns the current state of each of the 4 receiver error
  1551. //! sources. The returned errors are equivalent to the four error bits
  1552. //! returned via the previous call to UARTCharGet() or UARTCharGetNonBlocking()
  1553. //! with the exception that the overrun error is set immediately when the
  1554. //! overrun occurs rather than when a character is next read.
  1555. //!
  1556. //! \return Returns a logical OR combination of the receiver error flags,
  1557. //! \b UART_RXERROR_FRAMING, \b UART_RXERROR_PARITY, \b UART_RXERROR_BREAK
  1558. //! and \b UART_RXERROR_OVERRUN.
  1559. //
  1560. //*****************************************************************************
  1561. uint32_t
  1562. UARTRxErrorGet(uint32_t ui32Base)
  1563. {
  1564. //
  1565. // Check the arguments.
  1566. //
  1567. ASSERT(_UARTBaseValid(ui32Base));
  1568. //
  1569. // Return the current value of the receive status register.
  1570. //
  1571. return(HWREG(ui32Base + UART_O_RSR) & 0x0000000F);
  1572. }
  1573. //*****************************************************************************
  1574. //
  1575. //! Clears all reported receiver errors.
  1576. //!
  1577. //! \param ui32Base is the base address of the UART port.
  1578. //!
  1579. //! This function is used to clear all receiver error conditions reported via
  1580. //! UARTRxErrorGet(). If using the overrun, framing error, parity error or
  1581. //! break interrupts, this function must be called after clearing the interrupt
  1582. //! to ensure that later errors of the same type trigger another interrupt.
  1583. //!
  1584. //! \return None.
  1585. //
  1586. //*****************************************************************************
  1587. void
  1588. UARTRxErrorClear(uint32_t ui32Base)
  1589. {
  1590. //
  1591. // Check the arguments.
  1592. //
  1593. ASSERT(_UARTBaseValid(ui32Base));
  1594. //
  1595. // Any write to the Error Clear Register clears all bits which are
  1596. // currently set.
  1597. //
  1598. HWREG(ui32Base + UART_O_ECR) = 0;
  1599. }
  1600. //*****************************************************************************
  1601. //
  1602. //! Sets the baud clock source for the specified UART.
  1603. //!
  1604. //! \param ui32Base is the base address of the UART port.
  1605. //! \param ui32Source is the baud clock source for the UART.
  1606. //!
  1607. //! This function allows the baud clock source for the UART to be selected.
  1608. //! The possible clock source are the system clock (\b UART_CLOCK_SYSTEM) or
  1609. //! the precision internal oscillator (\b UART_CLOCK_PIOSC).
  1610. //!
  1611. //! Changing the baud clock source changes the baud rate generated by the
  1612. //! UART. Therefore, the baud rate should be reconfigured after any change to
  1613. //! the baud clock source.
  1614. //!
  1615. //! \note The ability to specify the UART baud clock source varies with the
  1616. //! Tiva part in use. Please consult the datasheet for the part you are
  1617. //! using to determine whether this support is available.
  1618. //!
  1619. //! \return None.
  1620. //
  1621. //*****************************************************************************
  1622. void
  1623. UARTClockSourceSet(uint32_t ui32Base, uint32_t ui32Source)
  1624. {
  1625. //
  1626. // Check the arguments.
  1627. //
  1628. ASSERT(_UARTBaseValid(ui32Base));
  1629. ASSERT((ui32Source == UART_CLOCK_SYSTEM) ||
  1630. (ui32Source == UART_CLOCK_PIOSC));
  1631. //
  1632. // Set the UART clock source.
  1633. //
  1634. HWREG(ui32Base + UART_O_CC) = ui32Source;
  1635. }
  1636. //*****************************************************************************
  1637. //
  1638. //! Gets the baud clock source for the specified UART.
  1639. //!
  1640. //! \param ui32Base is the base address of the UART port.
  1641. //!
  1642. //! This function returns the baud clock source for the specified UART. The
  1643. //! possible baud clock source are the system clock (\b UART_CLOCK_SYSTEM) or
  1644. //! the precision internal oscillator (\b UART_CLOCK_PIOSC).
  1645. //!
  1646. //! \note The ability to specify the UART baud clock source varies with the
  1647. //! Tiva part in use. Please consult the datasheet for the part you are
  1648. //! using to determine whether this support is available.
  1649. //!
  1650. //! \return None.
  1651. //
  1652. //*****************************************************************************
  1653. uint32_t
  1654. UARTClockSourceGet(uint32_t ui32Base)
  1655. {
  1656. //
  1657. // Check the arguments.
  1658. //
  1659. ASSERT(_UARTBaseValid(ui32Base));
  1660. //
  1661. // Return the UART clock source.
  1662. //
  1663. return(HWREG(ui32Base + UART_O_CC));
  1664. }
  1665. //*****************************************************************************
  1666. //
  1667. //! Enables 9-bit mode on the specified UART.
  1668. //!
  1669. //! \param ui32Base is the base address of the UART port.
  1670. //!
  1671. //! This function enables the 9-bit operational mode of the UART.
  1672. //!
  1673. //! \note The availability of 9-bit mode varies with the Tiva part in use.
  1674. //! Please consult the datasheet for the part you are using to determine
  1675. //! whether this support is available.
  1676. //!
  1677. //! \return None.
  1678. //
  1679. //*****************************************************************************
  1680. void
  1681. UART9BitEnable(uint32_t ui32Base)
  1682. {
  1683. //
  1684. // Check the arguments.
  1685. //
  1686. ASSERT(_UARTBaseValid(ui32Base));
  1687. //
  1688. // Enable 9-bit mode.
  1689. //
  1690. HWREG(ui32Base + UART_O_9BITADDR) |= UART_9BITADDR_9BITEN;
  1691. }
  1692. //*****************************************************************************
  1693. //
  1694. //! Disables 9-bit mode on the specified UART.
  1695. //!
  1696. //! \param ui32Base is the base address of the UART port.
  1697. //!
  1698. //! This function disables the 9-bit operational mode of the UART.
  1699. //!
  1700. //! \note The availability of 9-bit mode varies with the Tiva part in use.
  1701. //! Please consult the datasheet for the part you are using to determine
  1702. //! whether this support is available.
  1703. //!
  1704. //! \return None.
  1705. //
  1706. //*****************************************************************************
  1707. void
  1708. UART9BitDisable(uint32_t ui32Base)
  1709. {
  1710. //
  1711. // Check the arguments.
  1712. //
  1713. ASSERT(_UARTBaseValid(ui32Base));
  1714. //
  1715. // Disable 9-bit mode.
  1716. //
  1717. HWREG(ui32Base + UART_O_9BITADDR) &= ~UART_9BITADDR_9BITEN;
  1718. }
  1719. //*****************************************************************************
  1720. //
  1721. //! Sets the device address(es) for 9-bit mode.
  1722. //!
  1723. //! \param ui32Base is the base address of the UART port.
  1724. //! \param ui8Addr is the device address.
  1725. //! \param ui8Mask is the device address mask.
  1726. //!
  1727. //! This function configures the device address or range of device addresses
  1728. //! that respond to requests on the 9-bit UART port. The received address is
  1729. //! masked with the mask and then compared against the given address, allowing
  1730. //! either a single address (if \b ui8Mask is 0xff) or a set of addresses to be
  1731. //! matched.
  1732. //!
  1733. //! \note The availability of 9-bit mode varies with the Tiva part in use.
  1734. //! Please consult the datasheet for the part you are using to determine
  1735. //! whether this support is available.
  1736. //!
  1737. //! \return None.
  1738. //
  1739. //*****************************************************************************
  1740. void
  1741. UART9BitAddrSet(uint32_t ui32Base, uint8_t ui8Addr,
  1742. uint8_t ui8Mask)
  1743. {
  1744. //
  1745. // Check the arguments.
  1746. //
  1747. ASSERT(_UARTBaseValid(ui32Base));
  1748. //
  1749. // Set the address and mask.
  1750. //
  1751. HWREG(ui32Base + UART_O_9BITADDR) = ui8Addr << UART_9BITADDR_ADDR_S;
  1752. HWREG(ui32Base + UART_O_9BITAMASK) = ui8Mask << UART_9BITAMASK_MASK_S;
  1753. }
  1754. //*****************************************************************************
  1755. //
  1756. //! Sends an address character from the specified port when operating in 9-bit
  1757. //! mode.
  1758. //!
  1759. //! \param ui32Base is the base address of the UART port.
  1760. //! \param ui8Addr is the address to be transmitted.
  1761. //!
  1762. //! This function waits until all data has been sent from the specified port
  1763. //! and then sends the given address as an address byte. It then waits until
  1764. //! the address byte has been transmitted before returning.
  1765. //!
  1766. //! The normal data functions (UARTCharPut(), UARTCharPutNonBlocking(),
  1767. //! UARTCharGet(), and UARTCharGetNonBlocking()) are used to send and receive
  1768. //! data characters in 9-bit mode.
  1769. //!
  1770. //! \note The availability of 9-bit mode varies with the Tiva part in use.
  1771. //! Please consult the datasheet for the part you are using to determine
  1772. //! whether this support is available.
  1773. //!
  1774. //! \return None.
  1775. //
  1776. //*****************************************************************************
  1777. void
  1778. UART9BitAddrSend(uint32_t ui32Base, uint8_t ui8Addr)
  1779. {
  1780. uint32_t ui32LCRH;
  1781. //
  1782. // Check the arguments.
  1783. //
  1784. ASSERT(_UARTBaseValid(ui32Base));
  1785. //
  1786. // Wait until the FIFO is empty and the UART is not busy.
  1787. //
  1788. while((HWREG(ui32Base + UART_O_FR) & (UART_FR_TXFE | UART_FR_BUSY)) !=
  1789. UART_FR_TXFE)
  1790. {
  1791. }
  1792. //
  1793. // Force the address/data bit to 1 to indicate this is an address byte.
  1794. //
  1795. ui32LCRH = HWREG(ui32Base + UART_O_LCRH);
  1796. HWREG(ui32Base + UART_O_LCRH) = ((ui32LCRH & ~UART_LCRH_EPS) |
  1797. UART_LCRH_SPS | UART_LCRH_PEN);
  1798. //
  1799. // Send the address.
  1800. //
  1801. HWREG(ui32Base + UART_O_DR) = ui8Addr;
  1802. //
  1803. // Wait until the address has been sent.
  1804. //
  1805. while((HWREG(ui32Base + UART_O_FR) & (UART_FR_TXFE | UART_FR_BUSY)) !=
  1806. UART_FR_TXFE)
  1807. {
  1808. }
  1809. //
  1810. // Restore the address/data setting.
  1811. //
  1812. HWREG(ui32Base + UART_O_LCRH) = ui32LCRH;
  1813. }
  1814. //*****************************************************************************
  1815. //
  1816. // Close the Doxygen group.
  1817. //! @}
  1818. //
  1819. //*****************************************************************************