uart.c 61 KB

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