uart.c 63 KB

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