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