1 /*
2  *  Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 //*****************************************************************************
34 //
35 //  uart.c
36 //
37 //  Driver for the UART.
38 //
39 //*****************************************************************************
40 
41 //*****************************************************************************
42 //
43 //! \addtogroup UART_api
44 //! @{
45 //
46 //*****************************************************************************
47 
48 #include "inc/hw_ints.h"
49 #include "inc/hw_memmap.h"
50 #include "inc/hw_types.h"
51 #include "inc/hw_uart.h"
52 #include "debug.h"
53 #include "interrupt.h"
54 #include "uart.h"
55 
56 
57 //*****************************************************************************
58 //
59 // A mapping of UART base address to interupt number.
60 //
61 //*****************************************************************************
62 static const unsigned long g_ppulUARTIntMap[][2] =
63 {
64     { UARTA0_BASE, INT_UARTA0 },
65     { UARTA1_BASE, INT_UARTA1 },
66 };
67 
68 //*****************************************************************************
69 //
70 //! \internal
71 //! Checks a UART base address.
72 //!
73 //! \param ulBase is the base address of the UART port.
74 //!
75 //! This function determines if a UART port base address is valid.
76 //!
77 //! \return Returns \b true if the base address is valid and \b false
78 //! otherwise.
79 //
80 //*****************************************************************************
81 #ifdef DEBUG
82 static tBoolean
UARTBaseValid(unsigned long ulBase)83 UARTBaseValid(unsigned long ulBase)
84 {
85     return((ulBase == UARTA0_BASE) || (ulBase == UARTA1_BASE));
86 }
87 #endif
88 
89 //*****************************************************************************
90 //
91 //! \internal
92 //! Gets the UART interrupt number.
93 //!
94 //! \param ulBase is the base address of the UART port.
95 //!
96 //! Given a UART base address, returns the corresponding interrupt number.
97 //!
98 //! \return Returns a UART interrupt number, or -1 if \e ulBase is invalid.
99 //
100 //*****************************************************************************
101 static long
UARTIntNumberGet(unsigned long ulBase)102 UARTIntNumberGet(unsigned long ulBase)
103 {
104     unsigned long ulIdx;
105 
106     //
107     // Loop through the table that maps UART base addresses to interrupt
108     // numbers.
109     //
110     for(ulIdx = 0; ulIdx < (sizeof(g_ppulUARTIntMap) /
111                             sizeof(g_ppulUARTIntMap[0])); ulIdx++)
112     {
113         //
114         // See if this base address matches.
115         //
116         if(g_ppulUARTIntMap[ulIdx][0] == ulBase)
117         {
118             //
119             // Return the corresponding interrupt number.
120             //
121             return(g_ppulUARTIntMap[ulIdx][1]);
122         }
123     }
124 
125     //
126     // The base address could not be found, so return an error.
127     //
128     return(-1);
129 }
130 
131 //*****************************************************************************
132 //
133 //! Sets the type of parity.
134 //!
135 //! \param ulBase is the base address of the UART port.
136 //! \param ulParity specifies the type of parity to use.
137 //!
138 //! This function sets the type of parity to use for transmitting and expect
139 //! when receiving.  The \e ulParity parameter must be one of
140 //! \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD,
141 //! \b UART_CONFIG_PAR_ONE, or \b UART_CONFIG_PAR_ZERO.  The last two allow
142 //! direct control of the parity bit; it is always either one or zero based on
143 //! the mode.
144 //!
145 //! \return None.
146 //
147 //*****************************************************************************
148 void
UARTParityModeSet(unsigned long ulBase,unsigned long ulParity)149 UARTParityModeSet(unsigned long ulBase, unsigned long ulParity)
150 {
151     //
152     // Check the arguments.
153     //
154     ASSERT(UARTBaseValid(ulBase));
155     ASSERT((ulParity == UART_CONFIG_PAR_NONE) ||
156            (ulParity == UART_CONFIG_PAR_EVEN) ||
157            (ulParity == UART_CONFIG_PAR_ODD) ||
158            (ulParity == UART_CONFIG_PAR_ONE) ||
159            (ulParity == UART_CONFIG_PAR_ZERO));
160 
161     //
162     // Set the parity mode.
163     //
164     HWREG(ulBase + UART_O_LCRH) = ((HWREG(ulBase + UART_O_LCRH) &
165                                     ~(UART_LCRH_SPS | UART_LCRH_EPS |
166                                       UART_LCRH_PEN)) | ulParity);
167 }
168 
169 //*****************************************************************************
170 //
171 //! Gets the type of parity currently being used.
172 //!
173 //! \param ulBase is the base address of the UART port.
174 //!
175 //! This function gets the type of parity used for transmitting data and
176 //! expected when receiving data.
177 //!
178 //! \return Returns the current parity settings, specified as one of
179 //! \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD,
180 //! \b UART_CONFIG_PAR_ONE, or \b UART_CONFIG_PAR_ZERO.
181 //
182 //*****************************************************************************
183 unsigned long
UARTParityModeGet(unsigned long ulBase)184 UARTParityModeGet(unsigned long ulBase)
185 {
186     //
187     // Check the arguments.
188     //
189     ASSERT(UARTBaseValid(ulBase));
190 
191     //
192     // Return the current parity setting.
193     //
194     return(HWREG(ulBase + UART_O_LCRH) &
195            (UART_LCRH_SPS | UART_LCRH_EPS | UART_LCRH_PEN));
196 }
197 
198 //*****************************************************************************
199 //
200 //! Sets the FIFO level at which interrupts are generated.
201 //!
202 //! \param ulBase is the base address of the UART port.
203 //! \param ulTxLevel is the transmit FIFO interrupt level, specified as one of
204 //! \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8, \b UART_FIFO_TX4_8,
205 //! \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
206 //! \param ulRxLevel is the receive FIFO interrupt level, specified as one of
207 //! \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8, \b UART_FIFO_RX4_8,
208 //! \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
209 //!
210 //! This function sets the FIFO level at which transmit and receive interrupts
211 //! are generated.
212 //!
213 //! \return None.
214 //
215 //*****************************************************************************
216 void
UARTFIFOLevelSet(unsigned long ulBase,unsigned long ulTxLevel,unsigned long ulRxLevel)217 UARTFIFOLevelSet(unsigned long ulBase, unsigned long ulTxLevel,
218                  unsigned long ulRxLevel)
219 {
220     //
221     // Check the arguments.
222     //
223     ASSERT(UARTBaseValid(ulBase));
224     ASSERT((ulTxLevel == UART_FIFO_TX1_8) ||
225            (ulTxLevel == UART_FIFO_TX2_8) ||
226            (ulTxLevel == UART_FIFO_TX4_8) ||
227            (ulTxLevel == UART_FIFO_TX6_8) ||
228            (ulTxLevel == UART_FIFO_TX7_8));
229     ASSERT((ulRxLevel == UART_FIFO_RX1_8) ||
230            (ulRxLevel == UART_FIFO_RX2_8) ||
231            (ulRxLevel == UART_FIFO_RX4_8) ||
232            (ulRxLevel == UART_FIFO_RX6_8) ||
233            (ulRxLevel == UART_FIFO_RX7_8));
234 
235     //
236     // Set the FIFO interrupt levels.
237     //
238     HWREG(ulBase + UART_O_IFLS) = ulTxLevel | ulRxLevel;
239 }
240 
241 //*****************************************************************************
242 //
243 //! Gets the FIFO level at which interrupts are generated.
244 //!
245 //! \param ulBase is the base address of the UART port.
246 //! \param pulTxLevel is a pointer to storage for the transmit FIFO level,
247 //! returned as one of \b UART_FIFO_TX1_8, \b UART_FIFO_TX2_8,
248 //! \b UART_FIFO_TX4_8, \b UART_FIFO_TX6_8, or \b UART_FIFO_TX7_8.
249 //! \param pulRxLevel is a pointer to storage for the receive FIFO level,
250 //! returned as one of \b UART_FIFO_RX1_8, \b UART_FIFO_RX2_8,
251 //! \b UART_FIFO_RX4_8, \b UART_FIFO_RX6_8, or \b UART_FIFO_RX7_8.
252 //!
253 //! This function gets the FIFO level at which transmit and receive interrupts
254 //! are generated.
255 //!
256 //! \return None.
257 //
258 //*****************************************************************************
259 void
UARTFIFOLevelGet(unsigned long ulBase,unsigned long * pulTxLevel,unsigned long * pulRxLevel)260 UARTFIFOLevelGet(unsigned long ulBase, unsigned long *pulTxLevel,
261                  unsigned long *pulRxLevel)
262 {
263     unsigned long ulTemp;
264 
265     //
266     // Check the arguments.
267     //
268     ASSERT(UARTBaseValid(ulBase));
269 
270     //
271     // Read the FIFO level register.
272     //
273     ulTemp = HWREG(ulBase + UART_O_IFLS);
274 
275     //
276     // Extract the transmit and receive FIFO levels.
277     //
278     *pulTxLevel = ulTemp & UART_IFLS_TX_M;
279     *pulRxLevel = ulTemp & UART_IFLS_RX_M;
280 }
281 
282 //*****************************************************************************
283 //
284 //! Sets the configuration of a UART.
285 //!
286 //! \param ulBase is the base address of the UART port.
287 //! \param ulUARTClk is the rate of the clock supplied to the UART module.
288 //! \param ulBaud is the desired baud rate.
289 //! \param ulConfig is the data format for the port (number of data bits,
290 //! number of stop bits, and parity).
291 //!
292 //! This function configures the UART for operation in the specified data
293 //! format.  The baud rate is provided in the \e ulBaud parameter and the data
294 //! format in the \e ulConfig parameter.
295 //!
296 //! The \e ulConfig parameter is the logical OR of three values: the number of
297 //! data bits, the number of stop bits, and the parity.  \b UART_CONFIG_WLEN_8,
298 //! \b UART_CONFIG_WLEN_7, \b UART_CONFIG_WLEN_6, and \b UART_CONFIG_WLEN_5
299 //! select from eight to five data bits per byte (respectively).
300 //! \b UART_CONFIG_STOP_ONE and \b UART_CONFIG_STOP_TWO select one or two stop
301 //! bits (respectively).  \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN,
302 //! \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE, and \b UART_CONFIG_PAR_ZERO
303 //! select the parity mode (no parity bit, even parity bit, odd parity bit,
304 //! parity bit always one, and parity bit always zero, respectively).
305 //!
306 //! The peripheral clock frequency is returned by PRCMPeripheralClockGet().
307 //!
308 //!
309 //! \return None.
310 //
311 //*****************************************************************************
312 void
UARTConfigSetExpClk(unsigned long ulBase,unsigned long ulUARTClk,unsigned long ulBaud,unsigned long ulConfig)313 UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
314                     unsigned long ulBaud, unsigned long ulConfig)
315 {
316     unsigned long ulDiv;
317 
318     //
319     // Check the arguments.
320     //
321     ASSERT(UARTBaseValid(ulBase));
322     ASSERT(ulBaud != 0);
323 
324     //
325     // Stop the UART.
326     //
327     UARTDisable(ulBase);
328 
329     //
330     // Is the required baud rate greater than the maximum rate supported
331     // without the use of high speed mode?
332     //
333     if((ulBaud * 16) > ulUARTClk)
334     {
335         //
336         // Enable high speed mode.
337         //
338         HWREG(ulBase + UART_O_CTL) |= UART_CTL_HSE;
339 
340         //
341         // Half the supplied baud rate to compensate for enabling high speed
342         // mode.  This allows the following code to be common to both cases.
343         //
344         ulBaud /= 2;
345     }
346     else
347     {
348         //
349         // Disable high speed mode.
350         //
351         HWREG(ulBase + UART_O_CTL) &= ~(UART_CTL_HSE);
352     }
353 
354     //
355     // Compute the fractional baud rate divider.
356     //
357     ulDiv = (((ulUARTClk * 8) / ulBaud) + 1) / 2;
358 
359     //
360     // Set the baud rate.
361     //
362     HWREG(ulBase + UART_O_IBRD) = ulDiv / 64;
363     HWREG(ulBase + UART_O_FBRD) = ulDiv % 64;
364 
365     //
366     // Set parity, data length, and number of stop bits.
367     //
368     HWREG(ulBase + UART_O_LCRH) = ulConfig;
369 
370     //
371     // Clear the flags register.
372     //
373     HWREG(ulBase + UART_O_FR) = 0;
374 
375     //
376     // Start the UART.
377     //
378     UARTEnable(ulBase);
379 }
380 
381 //*****************************************************************************
382 //
383 //! Gets the current configuration of a UART.
384 //!
385 //! \param ulBase is the base address of the UART port.
386 //! \param ulUARTClk is the rate of the clock supplied to the UART module.
387 //! \param pulBaud is a pointer to storage for the baud rate.
388 //! \param pulConfig is a pointer to storage for the data format.
389 //!
390 //! The baud rate and data format for the UART is determined, given an
391 //! explicitly provided peripheral clock (hence the ExpClk suffix).  The
392 //! returned baud rate is the actual baud rate; it may not be the exact baud
393 //! rate requested or an ``official'' baud rate.  The data format returned in
394 //! \e pulConfig is enumerated the same as the \e ulConfig parameter of
395 //! UARTConfigSetExpClk().
396 //!
397 //! The peripheral clock frequency is returned by PRCMPeripheralClockGet().
398 //!
399 //!
400 //! \return None.
401 //
402 //*****************************************************************************
403 void
UARTConfigGetExpClk(unsigned long ulBase,unsigned long ulUARTClk,unsigned long * pulBaud,unsigned long * pulConfig)404 UARTConfigGetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
405                     unsigned long *pulBaud, unsigned long *pulConfig)
406 {
407     unsigned long ulInt, ulFrac;
408 
409     //
410     // Check the arguments.
411     //
412     ASSERT(UARTBaseValid(ulBase));
413 
414     //
415     // Compute the baud rate.
416     //
417     ulInt = HWREG(ulBase + UART_O_IBRD);
418     ulFrac = HWREG(ulBase + UART_O_FBRD);
419     *pulBaud = (ulUARTClk * 4) / ((64 * ulInt) + ulFrac);
420 
421     //
422     // See if high speed mode enabled.
423     //
424     if(HWREG(ulBase + UART_O_CTL) & UART_CTL_HSE)
425     {
426         //
427         // High speed mode is enabled so the actual baud rate is actually
428         // double what was just calculated.
429         //
430         *pulBaud *= 2;
431     }
432 
433     //
434     // Get the parity, data length, and number of stop bits.
435     //
436     *pulConfig = (HWREG(ulBase + UART_O_LCRH) &
437                   (UART_LCRH_SPS | UART_LCRH_WLEN_M | UART_LCRH_STP2 |
438                    UART_LCRH_EPS | UART_LCRH_PEN));
439 }
440 
441 //*****************************************************************************
442 //
443 //! Enables transmitting and receiving.
444 //!
445 //! \param ulBase is the base address of the UART port.
446 //!
447 //! This function sets the UARTEN, TXE, and RXE bits, and enables the transmit
448 //! and receive FIFOs.
449 //!
450 //! \return None.
451 //
452 //*****************************************************************************
453 void
UARTEnable(unsigned long ulBase)454 UARTEnable(unsigned long ulBase)
455 {
456     //
457     // Check the arguments.
458     //
459     ASSERT(UARTBaseValid(ulBase));
460 
461     //
462     // Enable the FIFO.
463     //
464     HWREG(ulBase + UART_O_LCRH) |= UART_LCRH_FEN;
465 
466     //
467     // Enable RX, TX, and the UART.
468     //
469     HWREG(ulBase + UART_O_CTL) |= (UART_CTL_UARTEN | UART_CTL_TXE |
470                                    UART_CTL_RXE);
471 }
472 
473 //*****************************************************************************
474 //
475 //! Disables transmitting and receiving.
476 //!
477 //! \param ulBase is the base address of the UART port.
478 //!
479 //! This function clears the UARTEN, TXE, and RXE bits, waits for the end of
480 //! transmission of the current character, and flushes the transmit FIFO.
481 //!
482 //! \return None.
483 //
484 //*****************************************************************************
485 void
UARTDisable(unsigned long ulBase)486 UARTDisable(unsigned long ulBase)
487 {
488     //
489     // Check the arguments.
490     //
491     ASSERT(UARTBaseValid(ulBase));
492 
493     //
494     // Wait for end of TX.
495     //
496     while(HWREG(ulBase + UART_O_FR) & UART_FR_BUSY)
497     {
498     }
499 
500     //
501     // Disable the FIFO.
502     //
503     HWREG(ulBase + UART_O_LCRH) &= ~(UART_LCRH_FEN);
504 
505     //
506     // Disable the UART.
507     //
508     HWREG(ulBase + UART_O_CTL) &= ~(UART_CTL_UARTEN | UART_CTL_TXE |
509                                     UART_CTL_RXE);
510 }
511 
512 //*****************************************************************************
513 //
514 //! Enables the transmit and receive FIFOs.
515 //!
516 //! \param ulBase is the base address of the UART port.
517 //!
518 //! This functions enables the transmit and receive FIFOs in the UART.
519 //!
520 //! \return None.
521 //
522 //*****************************************************************************
523 void
UARTFIFOEnable(unsigned long ulBase)524 UARTFIFOEnable(unsigned long ulBase)
525 {
526     //
527     // Check the arguments.
528     //
529     ASSERT(UARTBaseValid(ulBase));
530 
531     //
532     // Enable the FIFO.
533     //
534     HWREG(ulBase + UART_O_LCRH) |= UART_LCRH_FEN;
535 }
536 
537 //*****************************************************************************
538 //
539 //! Disables the transmit and receive FIFOs.
540 //!
541 //! \param ulBase is the base address of the UART port.
542 //!
543 //! This functions disables the transmit and receive FIFOs in the UART.
544 //!
545 //! \return None.
546 //
547 //*****************************************************************************
548 void
UARTFIFODisable(unsigned long ulBase)549 UARTFIFODisable(unsigned long ulBase)
550 {
551     //
552     // Check the arguments.
553     //
554     ASSERT(UARTBaseValid(ulBase));
555 
556     //
557     // Disable the FIFO.
558     //
559     HWREG(ulBase + UART_O_LCRH) &= ~(UART_LCRH_FEN);
560 }
561 
562 //*****************************************************************************
563 //
564 //! Sets the states of the RTS modem control signals.
565 //!
566 //! \param ulBase is the base address of the UART port.
567 //! \param ulControl is a bit-mapped flag indicating which modem control bits
568 //! should be set.
569 //!
570 //! This function sets the states of the RTS modem handshake outputs
571 //! from the UART.
572 //!
573 //! The \e ulControl parameter is the logical OR of any of the following:
574 //!
575 //! - \b UART_OUTPUT_RTS - The Modem Control RTS signal
576 //!
577 //! \note The availability of hardware modem handshake signals varies with the
578 //!  part and UART in use.  Please consult the datasheet for the part
579 //! you are using to determine whether this support is available.
580 //!
581 //! \return None.
582 //
583 //*****************************************************************************
584 void
UARTModemControlSet(unsigned long ulBase,unsigned long ulControl)585 UARTModemControlSet(unsigned long ulBase, unsigned long ulControl)
586 {
587     unsigned long ulTemp;
588 
589     //
590     // Check the arguments.
591     //
592 
593     ASSERT(ulBase == UARTA1_BASE);
594     ASSERT((ulControl & ~(UART_OUTPUT_RTS)) == 0);
595 
596     //
597     // Set the appropriate modem control output bits.
598     //
599     ulTemp = HWREG(ulBase + UART_O_CTL);
600     ulTemp |= (ulControl & (UART_OUTPUT_RTS));
601     HWREG(ulBase + UART_O_CTL) = ulTemp;
602 }
603 
604 //*****************************************************************************
605 //
606 //! Clears the states of the RTS modem control signals.
607 //!
608 //! \param ulBase is the base address of the UART port.
609 //! \param ulControl is a bit-mapped flag indicating which modem control bits
610 //! should be set.
611 //!
612 //! This function clears the states of the RTS modem handshake outputs
613 //! from the UART.
614 //!
615 //! The \e ulControl parameter is the logical OR of any of the following:
616 //!
617 //! - \b UART_OUTPUT_RTS - The Modem Control RTS signal
618 //!
619 //! \note The availability of hardware modem handshake signals varies with the
620 //!  part and UART in use.  Please consult the datasheet for the part
621 //! you are using to determine whether this support is available.
622 //!
623 //! \return None.
624 //
625 //*****************************************************************************
626 void
UARTModemControlClear(unsigned long ulBase,unsigned long ulControl)627 UARTModemControlClear(unsigned long ulBase, unsigned long ulControl)
628 {
629     unsigned long ulTemp;
630 
631     //
632     // Check the arguments.
633     //
634     ASSERT(ulBase == UARTA1_BASE);
635     ASSERT((ulControl & ~(UART_OUTPUT_RTS)) == 0);
636 
637     //
638     // Set the appropriate modem control output bits.
639     //
640     ulTemp = HWREG(ulBase + UART_O_CTL);
641     ulTemp &= ~(ulControl & (UART_OUTPUT_RTS));
642     HWREG(ulBase + UART_O_CTL) = ulTemp;
643 }
644 
645 //*****************************************************************************
646 //
647 //! Gets the states of the RTS modem control signals.
648 //!
649 //! \param ulBase is the base address of the UART port.
650 //!
651 //! This function returns the current states of each of the UART modem
652 //! control signal, RTS.
653 //!
654 //! \note The availability of hardware modem handshake signals varies with the
655 //!  part and UART in use.  Please consult the datasheet for the part
656 //! you are using to determine whether this support is available.
657 //!
658 //! \return Returns the states of the handshake output signal.
659 //
660 //*****************************************************************************
661 unsigned long
UARTModemControlGet(unsigned long ulBase)662 UARTModemControlGet(unsigned long ulBase)
663 {
664     //
665     // Check the arguments.
666     //
667     ASSERT(ulBase == UARTA1_BASE);
668 
669     return(HWREG(ulBase + UART_O_CTL) & (UART_OUTPUT_RTS));
670 }
671 
672 //*****************************************************************************
673 //
674 //! Gets the states of the CTS modem status signal.
675 //!
676 //! \param ulBase is the base address of the UART port.
677 //!
678 //! This function returns the current states of the UART modem status signal,
679 //! CTS.
680 //!
681 //! \note The availability of hardware modem handshake signals varies with the
682 //!  part and UART in use.  Please consult the datasheet for the part
683 //! you are using to determine whether this support is available.
684 //!
685 //! \return Returns the states of the handshake output signal
686 //
687 //*****************************************************************************
688 unsigned long
UARTModemStatusGet(unsigned long ulBase)689 UARTModemStatusGet(unsigned long ulBase)
690 {
691     //
692     // Check the arguments.
693     //
694 
695     ASSERT(ulBase == UARTA1_BASE);
696 
697     return(HWREG(ulBase + UART_O_FR) & (UART_INPUT_CTS));
698 }
699 
700 //*****************************************************************************
701 //
702 //! Sets the UART hardware flow control mode to be used.
703 //!
704 //! \param ulBase is the base address of the UART port.
705 //! \param ulMode indicates the flow control modes to be used.  This parameter
706 //! is a logical OR combination of values \b UART_FLOWCONTROL_TX and
707 //! \b UART_FLOWCONTROL_RX to enable hardware transmit (CTS) and receive (RTS)
708 //! flow control or \b UART_FLOWCONTROL_NONE to disable hardware flow control.
709 //!
710 //! This function sets the required hardware flow control modes.  If \e ulMode
711 //! contains flag \b UART_FLOWCONTROL_TX, data is only transmitted if the
712 //! incoming CTS signal is asserted. If \e ulMode contains flag
713 //! \b UART_FLOWCONTROL_RX, the RTS output is controlled by the hardware and is
714 //! asserted only when there is space available in the receive FIFO.  If no
715 //! hardware flow control is required, \b UART_FLOWCONTROL_NONE should be
716 //! passed.
717 //!
718 //! \note The availability of hardware flow control varies with the
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
UARTFlowControlSet(unsigned long ulBase,unsigned long ulMode)726 UARTFlowControlSet(unsigned long ulBase, unsigned long ulMode)
727 {
728     //
729     // Check the arguments.
730     //
731 
732     ASSERT(UARTBaseValid(ulBase));
733     ASSERT((ulMode & ~(UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX)) == 0);
734 
735     //
736     // Set the flow control mode as requested.
737     //
738     HWREG(ulBase + UART_O_CTL) = ((HWREG(ulBase + UART_O_CTL) &
739                                  ~(UART_FLOWCONTROL_TX |
740                                    UART_FLOWCONTROL_RX)) | ulMode);
741 }
742 
743 //*****************************************************************************
744 //
745 //! Returns the UART hardware flow control mode currently in use.
746 //!
747 //! \param ulBase is the base address of the UART port.
748 //!
749 //! This function returns the current hardware flow control mode.
750 //!
751 //! \note The availability of hardware flow control varies with the
752 //! part and UART in use.  Please consult the datasheet for the part you are
753 //! using to determine whether this support is available.
754 //!
755 //! \return Returns the current flow control mode in use.  This is a
756 //! logical OR combination of values \b UART_FLOWCONTROL_TX if transmit
757 //! (CTS) flow control is enabled and \b UART_FLOWCONTROL_RX if receive (RTS)
758 //! flow control is in use.  If hardware flow control is disabled,
759 //! \b UART_FLOWCONTROL_NONE is returned.
760 //
761 //*****************************************************************************
762 unsigned long
UARTFlowControlGet(unsigned long ulBase)763 UARTFlowControlGet(unsigned long ulBase)
764 {
765     //
766     // Check the arguments.
767     //
768 
769     ASSERT(UARTBaseValid(ulBase));
770 
771     return(HWREG(ulBase + UART_O_CTL) & (UART_FLOWCONTROL_TX |
772                                          UART_FLOWCONTROL_RX));
773 }
774 
775 //*****************************************************************************
776 //
777 //! Sets the operating mode for the UART transmit interrupt.
778 //!
779 //! \param ulBase is the base address of the UART port.
780 //! \param ulMode is the operating mode for the transmit interrupt.  It may be
781 //! \b UART_TXINT_MODE_EOT to trigger interrupts when the transmitter is idle
782 //! or \b UART_TXINT_MODE_FIFO to trigger based on the current transmit FIFO
783 //! level.
784 //!
785 //! This function allows the mode of the UART transmit interrupt to be set.  By
786 //! default, the transmit interrupt is asserted when the FIFO level falls past
787 //! a threshold set via a call to UARTFIFOLevelSet().  Alternatively, if this
788 //! function is called with \e ulMode set to \b UART_TXINT_MODE_EOT, the
789 //! transmit interrupt is asserted once the transmitter is completely idle -
790 //! the transmit FIFO is empty and all bits, including any stop bits, have
791 //! cleared the transmitter.
792 //!
793 //! \note The availability of end-of-transmission mode varies with the
794 //!  part in use.  Please consult the datasheet for the part you are
795 //! using to determine whether this support is available.
796 //!
797 //! \return None.
798 //
799 //*****************************************************************************
800 void
UARTTxIntModeSet(unsigned long ulBase,unsigned long ulMode)801 UARTTxIntModeSet(unsigned long ulBase, unsigned long ulMode)
802 {
803     //
804     // Check the arguments.
805     //
806     ASSERT(UARTBaseValid(ulBase));
807     ASSERT((ulMode == UART_TXINT_MODE_EOT) ||
808            (ulMode == UART_TXINT_MODE_FIFO));
809 
810     //
811     // Set or clear the EOT bit of the UART control register as appropriate.
812     //
813     HWREG(ulBase + UART_O_CTL) = ((HWREG(ulBase + UART_O_CTL) &
814                                  ~(UART_TXINT_MODE_EOT |
815                                    UART_TXINT_MODE_FIFO)) | ulMode);
816 }
817 
818 //*****************************************************************************
819 //
820 //! Returns the current operating mode for the UART transmit interrupt.
821 //!
822 //! \param ulBase is the base address of the UART port.
823 //!
824 //! This function returns the current operating mode for the UART transmit
825 //! interrupt.  The return value is \b UART_TXINT_MODE_EOT if the transmit
826 //! interrupt is currently set to be asserted once the transmitter is
827 //! completely idle - the transmit FIFO is empty and all bits, including any
828 //! stop bits, have cleared the transmitter.  The return value is
829 //! \b UART_TXINT_MODE_FIFO if the interrupt is set to be asserted based upon
830 //! the level of the transmit FIFO.
831 //!
832 //! \note The availability of end-of-transmission mode varies with the
833 //!  part in use.  Please consult the datasheet for the part you are
834 //! using to determine whether this support is available.
835 //!
836 //! \return Returns \b UART_TXINT_MODE_FIFO or \b UART_TXINT_MODE_EOT.
837 //
838 //*****************************************************************************
839 unsigned long
UARTTxIntModeGet(unsigned long ulBase)840 UARTTxIntModeGet(unsigned long ulBase)
841 {
842     //
843     // Check the arguments.
844     //
845     ASSERT(UARTBaseValid(ulBase));
846 
847     //
848     // Return the current transmit interrupt mode.
849     //
850     return(HWREG(ulBase + UART_O_CTL) & (UART_TXINT_MODE_EOT |
851                                          UART_TXINT_MODE_FIFO));
852 }
853 
854 //*****************************************************************************
855 //
856 //! Determines if there are any characters in the receive FIFO.
857 //!
858 //! \param ulBase is the base address of the UART port.
859 //!
860 //! This function returns a flag indicating whether or not there is data
861 //! available in the receive FIFO.
862 //!
863 //! \return Returns \b true if there is data in the receive FIFO or \b false
864 //! if there is no data in the receive FIFO.
865 //
866 //*****************************************************************************
867 tBoolean
UARTCharsAvail(unsigned long ulBase)868 UARTCharsAvail(unsigned long ulBase)
869 {
870     //
871     // Check the arguments.
872     //
873     ASSERT(UARTBaseValid(ulBase));
874 
875     //
876     // Return the availability of characters.
877     //
878     return((HWREG(ulBase + UART_O_FR) & UART_FR_RXFE) ? false : true);
879 }
880 
881 //*****************************************************************************
882 //
883 //! Determines if there is any space in the transmit FIFO.
884 //!
885 //! \param ulBase is the base address of the UART port.
886 //!
887 //! This function returns a flag indicating whether or not there is space
888 //! available in the transmit FIFO.
889 //!
890 //! \return Returns \b true if there is space available in the transmit FIFO
891 //! or \b false if there is no space available in the transmit FIFO.
892 //
893 //*****************************************************************************
894 tBoolean
UARTSpaceAvail(unsigned long ulBase)895 UARTSpaceAvail(unsigned long ulBase)
896 {
897     //
898     // Check the arguments.
899     //
900     ASSERT(UARTBaseValid(ulBase));
901 
902     //
903     // Return the availability of space.
904     //
905     return((HWREG(ulBase + UART_O_FR) & UART_FR_TXFF) ? false : true);
906 }
907 
908 //*****************************************************************************
909 //
910 //! Receives a character from the specified port.
911 //!
912 //! \param ulBase is the base address of the UART port.
913 //!
914 //! This function gets a character from the receive FIFO for the specified
915 //! port.
916 //!
917 //!
918 //! \return Returns the character read from the specified port, cast as a
919 //! \e long.  A \b -1 is returned if there are no characters present in the
920 //! receive FIFO.  The UARTCharsAvail() function should be called before
921 //! attempting to call this function.
922 //
923 //*****************************************************************************
924 long
UARTCharGetNonBlocking(unsigned long ulBase)925 UARTCharGetNonBlocking(unsigned long ulBase)
926 {
927     //
928     // Check the arguments.
929     //
930     ASSERT(UARTBaseValid(ulBase));
931 
932     //
933     // See if there are any characters in the receive FIFO.
934     //
935     if(!(HWREG(ulBase + UART_O_FR) & UART_FR_RXFE))
936     {
937         //
938         // Read and return the next character.
939         //
940         return(HWREG(ulBase + UART_O_DR));
941     }
942     else
943     {
944         //
945         // There are no characters, so return a failure.
946         //
947         return(-1);
948     }
949 }
950 
951 //*****************************************************************************
952 //
953 //! Waits for a character from the specified port.
954 //!
955 //! \param ulBase is the base address of the UART port.
956 //!
957 //! This function gets a character from the receive FIFO for the specified
958 //! port.  If there are no characters available, this function waits until a
959 //! character is received before returning.
960 //!
961 //! \return Returns the character read from the specified port, cast as a
962 //! \e long.
963 //
964 //*****************************************************************************
965 long
UARTCharGet(unsigned long ulBase)966 UARTCharGet(unsigned long ulBase)
967 {
968     //
969     // Check the arguments.
970     //
971     ASSERT(UARTBaseValid(ulBase));
972 
973     //
974     // Wait until a char is available.
975     //
976     while(HWREG(ulBase + UART_O_FR) & UART_FR_RXFE)
977     {
978     }
979 
980     //
981     // Now get the char.
982     //
983     return(HWREG(ulBase + UART_O_DR));
984 }
985 
986 //*****************************************************************************
987 //
988 //! Sends a character to the specified port.
989 //!
990 //! \param ulBase is the base address of the UART port.
991 //! \param ucData is the character to be transmitted.
992 //!
993 //! This function writes the character \e ucData to the transmit FIFO for the
994 //! specified port.  This function does not block, so if there is no space
995 //! available, then a \b false is returned, and the application must retry the
996 //! function later.
997 //!
998 //! \return Returns \b true if the character was successfully placed in the
999 //! transmit FIFO or \b false if there was no space available in the transmit
1000 //! FIFO.
1001 //
1002 //*****************************************************************************
1003 tBoolean
UARTCharPutNonBlocking(unsigned long ulBase,unsigned char ucData)1004 UARTCharPutNonBlocking(unsigned long ulBase, unsigned char ucData)
1005 {
1006     //
1007     // Check the arguments.
1008     //
1009     ASSERT(UARTBaseValid(ulBase));
1010 
1011     //
1012     // See if there is space in the transmit FIFO.
1013     //
1014     if(!(HWREG(ulBase + UART_O_FR) & UART_FR_TXFF))
1015     {
1016         //
1017         // Write this character to the transmit FIFO.
1018         //
1019         HWREG(ulBase + UART_O_DR) = ucData;
1020 
1021         //
1022         // Success.
1023         //
1024         return(true);
1025     }
1026     else
1027     {
1028         //
1029         // There is no space in the transmit FIFO, so return a failure.
1030         //
1031         return(false);
1032     }
1033 }
1034 
1035 //*****************************************************************************
1036 //
1037 //! Waits to send a character from the specified port.
1038 //!
1039 //! \param ulBase is the base address of the UART port.
1040 //! \param ucData is the character to be transmitted.
1041 //!
1042 //! This function sends the character \e ucData to the transmit FIFO for the
1043 //! specified port.  If there is no space available in the transmit FIFO, this
1044 //! function waits until there is space available before returning.
1045 //!
1046 //! \return None.
1047 //
1048 //*****************************************************************************
1049 void
UARTCharPut(unsigned long ulBase,unsigned char ucData)1050 UARTCharPut(unsigned long ulBase, unsigned char ucData)
1051 {
1052     //
1053     // Check the arguments.
1054     //
1055     ASSERT(UARTBaseValid(ulBase));
1056 
1057     //
1058     // Wait until space is available.
1059     //
1060     while(HWREG(ulBase + UART_O_FR) & UART_FR_TXFF)
1061     {
1062     }
1063 
1064     //
1065     // Send the char.
1066     //
1067     HWREG(ulBase + UART_O_DR) = ucData;
1068 }
1069 
1070 //*****************************************************************************
1071 //
1072 //! Causes a BREAK to be sent.
1073 //!
1074 //! \param ulBase is the base address of the UART port.
1075 //! \param bBreakState controls the output level.
1076 //!
1077 //! Calling this function with \e bBreakState set to \b true asserts a break
1078 //! condition on the UART.  Calling this function with \e bBreakState set to
1079 //! \b false removes the break condition.  For proper transmission of a break
1080 //! command, the break must be asserted for at least two complete frames.
1081 //!
1082 //! \return None.
1083 //
1084 //*****************************************************************************
1085 void
UARTBreakCtl(unsigned long ulBase,tBoolean bBreakState)1086 UARTBreakCtl(unsigned long ulBase, tBoolean bBreakState)
1087 {
1088     //
1089     // Check the arguments.
1090     //
1091     ASSERT(UARTBaseValid(ulBase));
1092 
1093     //
1094     // Set the break condition as requested.
1095     //
1096     HWREG(ulBase + UART_O_LCRH) =
1097         (bBreakState ?
1098          (HWREG(ulBase + UART_O_LCRH) | UART_LCRH_BRK) :
1099          (HWREG(ulBase + UART_O_LCRH) & ~(UART_LCRH_BRK)));
1100 }
1101 
1102 //*****************************************************************************
1103 //
1104 //! Determines whether the UART transmitter is busy or not.
1105 //!
1106 //! \param ulBase is the base address of the UART port.
1107 //!
1108 //! Allows the caller to determine whether all transmitted bytes have cleared
1109 //! the transmitter hardware.  If \b false is returned, the transmit FIFO is
1110 //! empty and all bits of the last transmitted character, including all stop
1111 //! bits, have left the hardware shift register.
1112 //!
1113 //! \return Returns \b true if the UART is transmitting or \b false if all
1114 //! transmissions are complete.
1115 //
1116 //*****************************************************************************
1117 tBoolean
UARTBusy(unsigned long ulBase)1118 UARTBusy(unsigned long ulBase)
1119 {
1120     //
1121     // Check the argument.
1122     //
1123     ASSERT(UARTBaseValid(ulBase));
1124 
1125     //
1126     // Determine if the UART is busy.
1127     //
1128     return((HWREG(ulBase + UART_O_FR) & UART_FR_BUSY) ? true : false);
1129 }
1130 
1131 //*****************************************************************************
1132 //
1133 //! Registers an interrupt handler for a UART interrupt.
1134 //!
1135 //! \param ulBase is the base address of the UART port.
1136 //! \param pfnHandler is a pointer to the function to be called when the
1137 //! UART interrupt occurs.
1138 //!
1139 //! This function does the actual registering of the interrupt handler.  This
1140 //! function enables the global interrupt in the interrupt controller; specific
1141 //! UART interrupts must be enabled via UARTIntEnable().  It is the interrupt
1142 //! handler's responsibility to clear the interrupt source.
1143 //!
1144 //! \sa IntRegister() for important information about registering interrupt
1145 //! handlers.
1146 //!
1147 //! \return None.
1148 //
1149 //*****************************************************************************
1150 void
UARTIntRegister(unsigned long ulBase,void (* pfnHandler)(void))1151 UARTIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
1152 {
1153     unsigned long ulInt;
1154 
1155     //
1156     // Check the arguments.
1157     //
1158     ASSERT(UARTBaseValid(ulBase));
1159 
1160     //
1161     // Determine the interrupt number based on the UART port.
1162     //
1163 
1164     ulInt = UARTIntNumberGet(ulBase);
1165 
1166     //
1167     // Register the interrupt handler.
1168     //
1169     IntRegister(ulInt, pfnHandler);
1170 
1171     //
1172     // Enable the UART interrupt.
1173     //
1174     IntEnable(ulInt);
1175 }
1176 
1177 //*****************************************************************************
1178 //
1179 //! Unregisters an interrupt handler for a UART interrupt.
1180 //!
1181 //! \param ulBase is the base address of the UART port.
1182 //!
1183 //! This function does the actual unregistering of the interrupt handler.  It
1184 //! clears the handler to be called when a UART interrupt occurs.  This
1185 //! function also masks off the interrupt in the interrupt controller so that
1186 //! the interrupt handler no longer is called.
1187 //!
1188 //! \sa IntRegister() for important information about registering interrupt
1189 //! handlers.
1190 //!
1191 //! \return None.
1192 //
1193 //*****************************************************************************
1194 void
UARTIntUnregister(unsigned long ulBase)1195 UARTIntUnregister(unsigned long ulBase)
1196 {
1197     unsigned long ulInt;
1198 
1199     //
1200     // Check the arguments.
1201     //
1202     ASSERT(UARTBaseValid(ulBase));
1203 
1204     //
1205     // Determine the interrupt number based on the UART port.
1206     //
1207     ulInt = UARTIntNumberGet(ulBase);
1208 
1209     //
1210     // Disable the interrupt.
1211     //
1212     IntDisable(ulInt);
1213 
1214     //
1215     // Unregister the interrupt handler.
1216     //
1217     IntUnregister(ulInt);
1218 }
1219 
1220 //*****************************************************************************
1221 //
1222 //! Enables individual UART interrupt sources.
1223 //!
1224 //! \param ulBase is the base address of the UART port.
1225 //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
1226 //!
1227 //! This function enables the indicated UART interrupt sources.  Only the
1228 //! sources that are enabled can be reflected to the processor interrupt;
1229 //! disabled sources have no effect on the processor.
1230 //!
1231 //! The \e ulIntFlags parameter is the logical OR of any of the following:
1232 //!
1233 //! - \b UART_INT_OE - Overrun Error interrupt
1234 //! - \b UART_INT_BE - Break Error interrupt
1235 //! - \b UART_INT_PE - Parity Error interrupt
1236 //! - \b UART_INT_FE - Framing Error interrupt
1237 //! - \b UART_INT_RT - Receive Timeout interrupt
1238 //! - \b UART_INT_TX - Transmit interrupt
1239 //! - \b UART_INT_RX - Receive interrupt
1240 //! - \b UART_INT_CTS - CTS interrupt
1241 //!
1242 //! \return None.
1243 //
1244 //*****************************************************************************
1245 void
UARTIntEnable(unsigned long ulBase,unsigned long ulIntFlags)1246 UARTIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
1247 {
1248     //
1249     // Check the arguments.
1250     //
1251     ASSERT(UARTBaseValid(ulBase));
1252 
1253     //
1254     // Enable the specified interrupts.
1255     //
1256     HWREG(ulBase + UART_O_IM) |= ulIntFlags;
1257 }
1258 
1259 //*****************************************************************************
1260 //
1261 //! Disables individual UART interrupt sources.
1262 //!
1263 //! \param ulBase is the base address of the UART port.
1264 //! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
1265 //!
1266 //! This function disables the indicated UART interrupt sources.  Only the
1267 //! sources that are enabled can be reflected to the processor interrupt;
1268 //! disabled sources have no effect on the processor.
1269 //!
1270 //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
1271 //! parameter to UARTIntEnable().
1272 //!
1273 //! \return None.
1274 //
1275 //*****************************************************************************
1276 void
UARTIntDisable(unsigned long ulBase,unsigned long ulIntFlags)1277 UARTIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
1278 {
1279     //
1280     // Check the arguments.
1281     //
1282     ASSERT(UARTBaseValid(ulBase));
1283 
1284     //
1285     // Disable the specified interrupts.
1286     //
1287     HWREG(ulBase + UART_O_IM) &= ~(ulIntFlags);
1288 }
1289 
1290 //*****************************************************************************
1291 //
1292 //! Gets the current interrupt status.
1293 //!
1294 //! \param ulBase is the base address of the UART port.
1295 //! \param bMasked is \b false if the raw interrupt status is required and
1296 //! \b true if the masked interrupt status is required.
1297 //!
1298 //! This function returns the interrupt status for the specified UART.  Either
1299 //! the raw interrupt status or the status of interrupts that are allowed to
1300 //! reflect to the processor can be returned.
1301 //!
1302 //! \return Returns the current interrupt status, enumerated as a bit field of
1303 //! values described in UARTIntEnable().
1304 //
1305 //*****************************************************************************
1306 unsigned long
UARTIntStatus(unsigned long ulBase,tBoolean bMasked)1307 UARTIntStatus(unsigned long ulBase, tBoolean bMasked)
1308 {
1309     //
1310     // Check the arguments.
1311     //
1312     ASSERT(UARTBaseValid(ulBase));
1313 
1314     //
1315     // Return either the interrupt status or the raw interrupt status as
1316     // requested.
1317     //
1318     if(bMasked)
1319     {
1320         return(HWREG(ulBase + UART_O_MIS));
1321     }
1322     else
1323     {
1324         return(HWREG(ulBase + UART_O_RIS));
1325     }
1326 }
1327 
1328 //*****************************************************************************
1329 //
1330 //! Clears UART interrupt sources.
1331 //!
1332 //! \param ulBase is the base address of the UART port.
1333 //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
1334 //!
1335 //! The specified UART interrupt sources are cleared, so that they no longer
1336 //! assert.  This function must be called in the interrupt handler to keep the
1337 //! interrupt from being recognized again immediately upon exit.
1338 //!
1339 //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
1340 //! parameter to UARTIntEnable().
1341 //!
1342 //! \note Because there is a write buffer in the Cortex-M3 processor, it may
1343 //! take several clock cycles before the interrupt source is actually cleared.
1344 //! Therefore, it is recommended that the interrupt source be cleared early in
1345 //! the interrupt handler (as opposed to the very last action) to avoid
1346 //! returning from the interrupt handler before the interrupt source is
1347 //! actually cleared.  Failure to do so may result in the interrupt handler
1348 //! being immediately reentered (because the interrupt controller still sees
1349 //! the interrupt source asserted).
1350 //!
1351 //! \return None.
1352 //
1353 //*****************************************************************************
1354 void
UARTIntClear(unsigned long ulBase,unsigned long ulIntFlags)1355 UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags)
1356 {
1357     //
1358     // Check the arguments.
1359     //
1360     ASSERT(UARTBaseValid(ulBase));
1361 
1362     //
1363     // Clear the requested interrupt sources.
1364     //
1365     HWREG(ulBase + UART_O_ICR) = ulIntFlags;
1366 }
1367 
1368 //*****************************************************************************
1369 //
1370 //! Enable UART DMA operation.
1371 //!
1372 //! \param ulBase is the base address of the UART port.
1373 //! \param ulDMAFlags is a bit mask of the DMA features to enable.
1374 //!
1375 //! The specified UART DMA features are enabled.  The UART can be
1376 //! configured to use DMA for transmit or receive, and to disable
1377 //! receive if an error occurs.  The \e ulDMAFlags parameter is the
1378 //! logical OR of any of the following values:
1379 //!
1380 //! - UART_DMA_RX - enable DMA for receive
1381 //! - UART_DMA_TX - enable DMA for transmit
1382 //! - UART_DMA_ERR_RXSTOP - disable DMA receive on UART error
1383 //!
1384 //! \note The uDMA controller must also be set up before DMA can be used
1385 //! with the UART.
1386 //!
1387 //! \return None.
1388 //
1389 //*****************************************************************************
1390 void
UARTDMAEnable(unsigned long ulBase,unsigned long ulDMAFlags)1391 UARTDMAEnable(unsigned long ulBase, unsigned long ulDMAFlags)
1392 {
1393     //
1394     // Check the arguments.
1395     //
1396     ASSERT(UARTBaseValid(ulBase));
1397 
1398     //
1399     // Set the requested bits in the UART DMA control register.
1400     //
1401     HWREG(ulBase + UART_O_DMACTL) |= ulDMAFlags;
1402 }
1403 
1404 //*****************************************************************************
1405 //
1406 //! Disable UART DMA operation.
1407 //!
1408 //! \param ulBase is the base address of the UART port.
1409 //! \param ulDMAFlags is a bit mask of the DMA features to disable.
1410 //!
1411 //! This function is used to disable UART DMA features that were enabled
1412 //! by UARTDMAEnable().  The specified UART DMA features are disabled.  The
1413 //! \e ulDMAFlags parameter is the logical OR of any of the following values:
1414 //!
1415 //! - UART_DMA_RX - disable DMA for receive
1416 //! - UART_DMA_TX - disable DMA for transmit
1417 //! - UART_DMA_ERR_RXSTOP - do not disable DMA receive on UART error
1418 //!
1419 //! \return None.
1420 //
1421 //*****************************************************************************
1422 void
UARTDMADisable(unsigned long ulBase,unsigned long ulDMAFlags)1423 UARTDMADisable(unsigned long ulBase, unsigned long ulDMAFlags)
1424 {
1425     //
1426     // Check the arguments.
1427     //
1428     ASSERT(UARTBaseValid(ulBase));
1429 
1430     //
1431     // Clear the requested bits in the UART DMA control register.
1432     //
1433     HWREG(ulBase + UART_O_DMACTL) &= ~ulDMAFlags;
1434 }
1435 
1436 //*****************************************************************************
1437 //
1438 //! Gets current receiver errors.
1439 //!
1440 //! \param ulBase is the base address of the UART port.
1441 //!
1442 //! This function returns the current state of each of the 4 receiver error
1443 //! sources.  The returned errors are equivalent to the four error bits
1444 //! returned via the previous call to UARTCharGet() or UARTCharGetNonBlocking()
1445 //! with the exception that the overrun error is set immediately the overrun
1446 //! occurs rather than when a character is next read.
1447 //!
1448 //! \return Returns a logical OR combination of the receiver error flags,
1449 //! \b UART_RXERROR_FRAMING, \b UART_RXERROR_PARITY, \b UART_RXERROR_BREAK
1450 //! and \b UART_RXERROR_OVERRUN.
1451 //
1452 //*****************************************************************************
1453 unsigned long
UARTRxErrorGet(unsigned long ulBase)1454 UARTRxErrorGet(unsigned long ulBase)
1455 {
1456     //
1457     // Check the arguments.
1458     //
1459     ASSERT(UARTBaseValid(ulBase));
1460 
1461     //
1462     // Return the current value of the receive status register.
1463     //
1464     return(HWREG(ulBase + UART_O_RSR) & 0x0000000F);
1465 }
1466 
1467 //*****************************************************************************
1468 //
1469 //! Clears all reported receiver errors.
1470 //!
1471 //! \param ulBase is the base address of the UART port.
1472 //!
1473 //! This function is used to clear all receiver error conditions reported via
1474 //! UARTRxErrorGet().  If using the overrun, framing error, parity error or
1475 //! break interrupts, this function must be called after clearing the interrupt
1476 //! to ensure that later errors of the same type trigger another interrupt.
1477 //!
1478 //! \return None.
1479 //
1480 //*****************************************************************************
1481 void
UARTRxErrorClear(unsigned long ulBase)1482 UARTRxErrorClear(unsigned long ulBase)
1483 {
1484     //
1485     // Check the arguments.
1486     //
1487     ASSERT(UARTBaseValid(ulBase));
1488 
1489     //
1490     // Any write to the Error Clear Register will clear all bits which are
1491     // currently set.
1492     //
1493     HWREG(ulBase + UART_O_ECR) = 0;
1494 }
1495 
1496 //*****************************************************************************
1497 //
1498 // Close the Doxygen group.
1499 //! @}
1500 //
1501 //*****************************************************************************
1502