1
2 /******************************************************************************
3 * Filename: uart.h
4 *
5 * Description: Defines and prototypes for the UART peripheral.
6 *
7 * Copyright (c) 2022-2024 Texas Instruments Incorporated
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1) Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2) Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3) Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36
37 #ifndef __UART_H__
38 #define __UART_H__
39
40 //*****************************************************************************
41 //
42 //! \addtogroup peripheral_group
43 //! @{
44 //! \addtogroup uart_api
45 //! @{
46 //
47 //*****************************************************************************
48
49 #include <stdbool.h>
50 #include <stdint.h>
51 #include "../inc/hw_types.h"
52 #include "../inc/hw_uart.h"
53 #include "../inc/hw_memmap.h"
54 #include "../inc/hw_ints.h"
55 #include "interrupt.h"
56 #include "debug.h"
57
58 //*****************************************************************************
59 //
60 // If building with a C++ compiler, make all of the definitions in this header
61 // have a C binding.
62 //
63 //*****************************************************************************
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 //*****************************************************************************
69 //
70 // Values that can be passed to UARTEnableInt, UARTDisableInt, and UARTClearInt
71 // as the intFlags parameter, and returned from UARTIntStatus.
72 //
73 //*****************************************************************************
74 #define UART_INT_EOT (UART_IMSC_EOT) //!< End Of Transmission Interrupt Mask
75 #define UART_INT_OE (UART_IMSC_OE) //!< Overrun Error Interrupt Mask
76 #define UART_INT_BE (UART_IMSC_BE) //!< Break Error Interrupt Mask
77 #define UART_INT_PE (UART_IMSC_PE) //!< Parity Error Interrupt Mask
78 #define UART_INT_FE (UART_IMSC_FE) //!< Framing Error Interrupt Mask
79 #define UART_INT_RT (UART_IMSC_RT) //!< Receive Timeout Interrupt Mask
80 #define UART_INT_RX (UART_IMSC_RX) //!< Receive Interrupt Mask
81 #define UART_INT_TX (UART_IMSC_TX) //!< Transmit Interrupt Mask
82 #define UART_INT_CTS (UART_IMSC_CTSM) //!< CTS Modem Interrupt Mask
83 #define UART_INT_TXDMADONE (UART_IMSC_TXDMADONE) //!< Tx DMA done interrupt mask
84 #define UART_INT_RXDMADONE (UART_IMSC_RXDMADONE) //!< Rx DMA done interrupt mask
85
86 //*****************************************************************************
87 //
88 // Values that can be passed to UARTConfigSetExpClk as the config parameter
89 // and returned by UARTConfigGetExpClk in the pconfig parameter.
90 //
91 //*****************************************************************************
92 #define UART_CONFIG_WLEN_MASK 0x00000060 //!< Mask for extracting word length
93 #define UART_CONFIG_WLEN_8 0x00000060 //!< 8 bit data
94 #define UART_CONFIG_WLEN_7 0x00000040 //!< 7 bit data
95 #define UART_CONFIG_WLEN_6 0x00000020 //!< 6 bit data
96 #define UART_CONFIG_WLEN_5 0x00000000 //!< 5 bit data
97 #define UART_CONFIG_STOP_MASK 0x00000008 //!< Mask for extracting stop bits
98 #define UART_CONFIG_STOP_ONE 0x00000000 //!< One stop bit
99 #define UART_CONFIG_STOP_TWO 0x00000008 //!< Two stop bits
100 #define UART_CONFIG_PAR_MASK 0x00000086 //!< Mask for extracting parity
101 #define UART_CONFIG_PAR_NONE 0x00000000 //!< No parity
102 #define UART_CONFIG_PAR_EVEN 0x00000006 //!< Even parity
103 #define UART_CONFIG_PAR_ODD 0x00000002 //!< Odd parity
104 #define UART_CONFIG_PAR_ONE 0x00000082 //!< Parity bit is one
105 #define UART_CONFIG_PAR_ZERO 0x00000086 //!< Parity bit is zero
106
107 //*****************************************************************************
108 //
109 // Values that can be passed to UARTSetFifoLevel as the txLevel parameter
110 //
111 //*****************************************************************************
112 #define UART_FIFO_TX2_8 0x00000001 //!< Transmit interrupt at 1/4 Full
113 #define UART_FIFO_TX4_8 0x00000002 //!< Transmit interrupt at 1/2 Full
114 #define UART_FIFO_TX6_8 0x00000003 //!< Transmit interrupt at 3/4 Full
115
116 //*****************************************************************************
117 //
118 // Values that can be passed to UARTSetFifoLevel as the rxLevel parameter
119 //
120 //*****************************************************************************
121 #define UART_FIFO_RX2_8 0x00000008 //!< Receive interrupt at 1/4 Full
122 #define UART_FIFO_RX4_8 0x00000010 //!< Receive interrupt at 1/2 Full
123 #define UART_FIFO_RX6_8 0x00000018 //!< Receive interrupt at 3/4 Full
124
125 //*****************************************************************************
126 //
127 // Values that can be passed to UARTEnableDMA() and UARTDisableDMA().
128 //
129 //*****************************************************************************
130 #define UART_DMA_ERR_RXSTOP 0x00000004 //!< Stop DMA receive if UART error
131 #define UART_DMA_TX 0x00000002 //!< Enable DMA for transmit
132 #define UART_DMA_RX 0x00000001 //!< Enable DMA for receive
133
134 //*****************************************************************************
135 //
136 // Values returned from UARTGetRxError().
137 //
138 //*****************************************************************************
139 #define UART_RXERROR_OVERRUN 0x00000008
140 #define UART_RXERROR_BREAK 0x00000004
141 #define UART_RXERROR_PARITY 0x00000002
142 #define UART_RXERROR_FRAMING 0x00000001
143
144 //*****************************************************************************
145 //
146 // API Functions and prototypes
147 //
148 //*****************************************************************************
149
150 //*****************************************************************************
151 //
152 //! \brief Sets the FIFO level at which interrupts are generated.
153 //!
154 //! This function sets the FIFO level at which transmit and receive interrupts
155 //! are generated.
156 //!
157 //! \param base is the base address of the UART port.
158 //! \param txLevel is the transmit FIFO interrupt level, specified as one of:
159 //! - \ref UART_FIFO_TX2_8
160 //! - \ref UART_FIFO_TX4_8
161 //! - \ref UART_FIFO_TX6_8
162 //! \param rxLevel is the receive FIFO interrupt level, specified as one of:
163 //! - \ref UART_FIFO_RX2_8
164 //! - \ref UART_FIFO_RX4_8
165 //! - \ref UART_FIFO_RX6_8
166 //!
167 //! \return None
168 //
169 //*****************************************************************************
UARTSetFifoLevel(uint32_t base,uint32_t txLevel,uint32_t rxLevel)170 __STATIC_INLINE void UARTSetFifoLevel(uint32_t base, uint32_t txLevel, uint32_t rxLevel)
171 {
172 // Check the arguments.
173 ASSERT((txLevel == UART_FIFO_TX2_8) || (txLevel == UART_FIFO_TX4_8) || (txLevel == UART_FIFO_TX6_8));
174 ASSERT((rxLevel == UART_FIFO_RX2_8) || (rxLevel == UART_FIFO_RX4_8) || (rxLevel == UART_FIFO_RX6_8));
175
176 // Set the FIFO interrupt levels.
177 HWREG(base + UART_O_IFLS) = txLevel | rxLevel;
178 }
179
180 //*****************************************************************************
181 //
182 //! \brief Sets the configuration of a UART.
183 //!
184 //! This function configures the UART for operation in the specified data
185 //! format.
186 //!
187 //! \param base is the base address of the UART port.
188 //! \param UARTClkFreq is the rate of the clock supplied to the UART module.
189 //! \param baudFreq is the desired baud rate.
190 //! - Minimum baud rate: baudFreq >= ceil(UARTClkFreq / 1,048,559.875)
191 //! - Maximum baud rate: baudFreq <= floor(UARTClkFreq / 15.875)
192 //! \param config is the data format for the port.
193 //! The parameter is the bitwise OR of three values:
194 //! - Number of data bits
195 //! - \ref UART_CONFIG_WLEN_8 : 8 data bits per byte.
196 //! - \ref UART_CONFIG_WLEN_7 : 7 data bits per byte.
197 //! - \ref UART_CONFIG_WLEN_6 : 6 data bits per byte.
198 //! - \ref UART_CONFIG_WLEN_5 : 5 data bits per byte.
199 //! - Number of stop bits
200 //! - \ref UART_CONFIG_STOP_ONE : One stop bit.
201 //! - \ref UART_CONFIG_STOP_TWO : Two stop bits.
202 //! - Parity
203 //! - \ref UART_CONFIG_PAR_NONE
204 //! - \ref UART_CONFIG_PAR_EVEN
205 //! - \ref UART_CONFIG_PAR_ODD
206 //! - \ref UART_CONFIG_PAR_ONE
207 //! - \ref UART_CONFIG_PAR_ZERO
208 //!
209 //! \return None
210 //
211 //*****************************************************************************
212 extern void UARTConfigSetExpClk(uint32_t base, uint32_t UARTClkFreq, uint32_t baudFreq, uint32_t config);
213
214 //*****************************************************************************
215 //
216 //! \brief Disables transmitting and receiving.
217 //!
218 //! This function waits until all data in the TX FIFO has been transmitted,
219 //! and then clears the UARTEN, TXE, and RXE bits, and disables the FIFO.
220 //!
221 //! \param base is the base address of the UART port.
222 //!
223 //! \return None
224 //
225 //*****************************************************************************
226 extern void UARTDisable(uint32_t base);
227
228 //*****************************************************************************
229 //
230 //! \brief Enable transmitting and receiving.
231 //!
232 //! This function enable UARTEN, TXE and RXE.
233 //!
234 //! \param base is the base address of the UART port.
235 //!
236 //! \return None
237 //
238 //*****************************************************************************
239 extern void UARTEnable(uint32_t base);
240
241 //*****************************************************************************
242 //
243 //! \brief Enables the transmit and receive FIFOs.
244 //!
245 //! This functions enables the transmit and receive FIFOs in the UART.
246 //!
247 //! \param base is the base address of the UART port.
248 //!
249 //! \return None
250 //
251 //*****************************************************************************
UARTEnableFifo(uint32_t base)252 __STATIC_INLINE void UARTEnableFifo(uint32_t base)
253 {
254 // Enable the FIFO.
255 HWREG(base + UART_O_LCRH) |= UART_LCRH_FEN;
256 }
257
258 //*****************************************************************************
259 //
260 //! \brief Disables the transmit and receive FIFOs.
261 //!
262 //! This functions disables the transmit and receive FIFOs in the UART.
263 //!
264 //! \param base is the base address of the UART port.
265 //!
266 //! \return None
267 //
268 //*****************************************************************************
UARTDisableFIFO(uint32_t base)269 __STATIC_INLINE void UARTDisableFIFO(uint32_t base)
270 {
271 // Disable the FIFO.
272 HWREG(base + UART_O_LCRH) &= ~(UART_LCRH_FEN);
273 }
274
275 //*****************************************************************************
276 //
277 //! \brief Determines if there are any characters in the receive FIFO.
278 //!
279 //! This function returns a flag indicating whether or not there is data
280 //! available in the receive FIFO.
281 //!
282 //! \param base is the base address of the UART port.
283 //!
284 //! \return Returns status of the receive FIFO.
285 //! - \c true : There is data in the receive FIFO.
286 //! - \c false : There is no data in the receive FIFO.
287 //
288 //*****************************************************************************
UARTCharAvailable(uint32_t base)289 __STATIC_INLINE bool UARTCharAvailable(uint32_t base)
290 {
291 // Return the availability of characters.
292 return ((HWREG(base + UART_O_FR) & UART_FR_RXFE) ? false : true);
293 }
294
295 //*****************************************************************************
296 //
297 //! \brief Receives a character from the specified port.
298 //!
299 //! This function gets a character from the receive FIFO for the specified
300 //! port.
301 //!
302 //! \note The \ref UARTCharAvailable() function should be called before
303 //! attempting to call this function.
304 //!
305 //! \param[in] base is the base address of the UART port.
306 //!
307 //! \return Returns the character read from the specified port
308 //!
309 //! \sa \ref UARTCharAvailable()
310 //
311 //*****************************************************************************
UARTGetCharNonBlocking(uint32_t base)312 __STATIC_INLINE uint8_t UARTGetCharNonBlocking(uint32_t base)
313 {
314 // Return a character from the data register
315 return (HWREGB(base + UART_O_DR));
316 }
317
318 //*****************************************************************************
319 //
320 //! \brief Waits for a character from the specified port.
321 //!
322 //! This function gets a character from the receive FIFO for the specified
323 //! port. If there are no characters available, this function waits until a
324 //! character is received before returning.
325 //!
326 //! \param base is the base address of the UART port.
327 //!
328 //! \return Returns the character read from the specified port
329 //
330 //*****************************************************************************
331 extern uint8_t UARTGetChar(uint32_t base);
332
333 //*****************************************************************************
334 //
335 //! \brief Determines if there is any space in the transmit FIFO.
336 //!
337 //! This function returns a flag indicating whether or not there is space
338 //! available in the transmit FIFO.
339 //!
340 //! \param base is the base address of the UART port.
341 //!
342 //! \return Returns status of the transmit FIFO.
343 //! - \c true : There is space available in the transmit FIFO.
344 //! - \c false : There is no space available in the transmit FIFO.
345 //
346 //*****************************************************************************
UARTSpaceAvailable(uint32_t base)347 __STATIC_INLINE bool UARTSpaceAvailable(uint32_t base)
348 {
349 // Return the availability of space.
350 return ((HWREG(base + UART_O_FR) & UART_FR_TXFF) ? false : true);
351 }
352
353 //*****************************************************************************
354 //
355 //! \brief Sends a character to the specified port.
356 //!
357 //! This function writes the character \c data to the transmit FIFO for the
358 //! specified port.
359 //!
360 //! \note The \ref UARTSpaceAvailable() function should be called before
361 //! attempting to call this function.
362 //!
363 //! \param base is the base address of the UART port.
364 //! \param data is the character to be transmitted.
365 //!
366 //! \return None
367 //!
368 //! \sa \ref UARTSpaceAvailable()
369 //
370 //*****************************************************************************
UARTPutCharNonBlocking(uint32_t base,uint8_t data)371 __STATIC_INLINE void UARTPutCharNonBlocking(uint32_t base, uint8_t data)
372 {
373 // Write this character to the transmit FIFO.
374 HWREG(base + UART_O_DR) = data;
375 }
376
377 //*****************************************************************************
378 //
379 //! \brief Waits to send a character to the specified port.
380 //!
381 //! This function sends the character \c data to the transmit FIFO for the
382 //! specified port. If there is no space available in the transmit FIFO, this
383 //! function waits until there is space available before returning.
384 //!
385 //! \param base is the base address of the UART port.
386 //! \param data is the character to be transmitted.
387 //!
388 //! \return None
389 //
390 //*****************************************************************************
391 extern void UARTPutChar(uint32_t base, uint8_t data);
392
393 //*****************************************************************************
394 //
395 //! \brief Determines whether the UART transmitter is busy or not.
396 //!
397 //! Allows the caller to determine whether all transmitted bytes have cleared
398 //! the transmitter hardware. If \c false is returned, the transmit FIFO is
399 //! empty and all bits of the last transmitted character, including all stop
400 //! bits, have left the hardware shift register.
401 //!
402 //! \param base is the base address of the UART port.
403 //!
404 //! \return Returns status of UART transmitter.
405 //! - \c true : UART is transmitting.
406 //! - \c false : All transmissions are complete.
407 //
408 //*****************************************************************************
UARTBusy(uint32_t base)409 __STATIC_INLINE bool UARTBusy(uint32_t base)
410 {
411 // Determine if the UART is busy.
412 return ((HWREG(base + UART_O_FR) & UART_FR_BUSY) ? true : false);
413 }
414
415 //*****************************************************************************
416 //
417 //! \brief Enables individual UART interrupt sources.
418 //!
419 //! This function enables the indicated UART interrupt sources. Only the
420 //! sources that are enabled can be reflected to the processor interrupt;
421 //! disabled sources have no effect on the processor.
422 //!
423 //! \param base is the base address of the UART port.
424 //! \param intFlags is the bit mask of the interrupt sources to be enabled.
425 //! The parameter is the bitwise OR of any of the following:
426 //! - \ref UART_INT_EOT : End Of Transmission interrupt.
427 //! - \ref UART_INT_OE : Overrun Error interrupt.
428 //! - \ref UART_INT_BE : Break Error interrupt.
429 //! - \ref UART_INT_PE : Parity Error interrupt.
430 //! - \ref UART_INT_FE : Framing Error interrupt.
431 //! - \ref UART_INT_RT : Receive Timeout interrupt.
432 //! - \ref UART_INT_TX : Transmit interrupt.
433 //! - \ref UART_INT_RX : Receive interrupt.
434 //! - \ref UART_INT_CTS : CTS interrupt.
435 //! - \ref UART_INT_TXDMADONE : TX DMA Done interrupt.
436 //! - \ref UART_INT_RXDMADONE : RX DMA Done interrupt.
437 //!
438 //! \return None
439 //
440 //*****************************************************************************
UARTEnableInt(uint32_t base,uint32_t intFlags)441 __STATIC_INLINE void UARTEnableInt(uint32_t base, uint32_t intFlags)
442 {
443 // Enable the specified interrupts.
444 HWREG(base + UART_O_IMSC) |= intFlags;
445 }
446
447 //*****************************************************************************
448 //
449 //! \brief Disables individual UART interrupt sources.
450 //!
451 //! This function disables the indicated UART interrupt sources. Only the
452 //! sources that are enabled can be reflected to the processor interrupt;
453 //! disabled sources have no effect on the processor.
454 //!
455 //! \param base is the base address of the UART port.
456 //! \param intFlags is the bit mask of the interrupt sources to be disabled.
457 //! - \ref UART_INT_EOT : End Of Transmission interrupt.
458 //! - \ref UART_INT_OE : Overrun Error interrupt.
459 //! - \ref UART_INT_BE : Break Error interrupt.
460 //! - \ref UART_INT_PE : Parity Error interrupt.
461 //! - \ref UART_INT_FE : Framing Error interrupt.
462 //! - \ref UART_INT_RT : Receive Timeout interrupt.
463 //! - \ref UART_INT_TX : Transmit interrupt.
464 //! - \ref UART_INT_RX : Receive interrupt.
465 //! - \ref UART_INT_CTS : CTS interrupt.
466 //! - \ref UART_INT_TXDMADONE : TX DMA Done interrupt.
467 //! - \ref UART_INT_RXDMADONE : RX DMA Done interrupt.
468 //!
469 //! \return None
470 //
471 //*****************************************************************************
UARTDisableInt(uint32_t base,uint32_t intFlags)472 __STATIC_INLINE void UARTDisableInt(uint32_t base, uint32_t intFlags)
473 {
474 // Disable the specified interrupts.
475 HWREG(base + UART_O_IMSC) &= ~(intFlags);
476 }
477
478 //*****************************************************************************
479 //
480 //! \brief Gets the current interrupt status.
481 //!
482 //! This function returns the interrupt status for the specified UART. Either
483 //! the raw interrupt status or the status of interrupts that are allowed to
484 //! reflect to the processor can be returned.
485 //!
486 //! \param base is the base address of the UART port.
487 //! \param masked selects either raw or masked interrupt.
488 //! - \c true : Masked interrupt status is required.
489 //! - \c false : Raw interrupt status is required.
490 //!
491 //! \return Returns the current interrupt status, enumerated as a bit field of:
492 //! - \ref UART_INT_EOT : End Of Transmission interrupt.
493 //! - \ref UART_INT_OE : Overrun Error interrupt.
494 //! - \ref UART_INT_BE : Break Error interrupt.
495 //! - \ref UART_INT_PE : Parity Error interrupt.
496 //! - \ref UART_INT_FE : Framing Error interrupt.
497 //! - \ref UART_INT_RT : Receive Timeout interrupt.
498 //! - \ref UART_INT_TX : Transmit interrupt.
499 //! - \ref UART_INT_RX : Receive interrupt.
500 //! - \ref UART_INT_CTS : CTS interrupt.
501 //! - \ref UART_INT_TXDMADONE : TX DMA Done interrupt.
502 //! - \ref UART_INT_RXDMADONE : RX DMA Done interrupt.
503 //
504 //*****************************************************************************
UARTIntStatus(uint32_t base,bool masked)505 __STATIC_INLINE uint32_t UARTIntStatus(uint32_t base, bool masked)
506 {
507 // Return either the interrupt status or the raw interrupt status as
508 // requested.
509 if (masked)
510 {
511 return (HWREG(base + UART_O_MIS));
512 }
513 else
514 {
515 return (HWREG(base + UART_O_RIS));
516 }
517 }
518
519 //*****************************************************************************
520 //
521 //! \brief Clears UART interrupt sources.
522 //!
523 //! The specified UART interrupt sources are cleared, so that they no longer
524 //! assert. This function must be called in the interrupt handler to keep the
525 //! interrupt from being recognized again immediately upon exit.
526 //!
527 //! \note Due to write buffers and synchronizers in the system it may take several
528 //! clock cycles from a register write clearing an event in a module and until the
529 //! event is actually cleared in the NVIC of the system CPU. It is recommended to
530 //! clear the event source early in the interrupt service routine (ISR) to allow
531 //! the event clear to propagate to the NVIC before returning from the ISR.
532 //! At the same time, an early event clear allows new events of the same type to be
533 //! pended instead of ignored if the event is cleared later in the ISR.
534 //! It is the responsibility of the programmer to make sure that enough time has passed
535 //! before returning from the ISR to avoid false re-triggering of the cleared event.
536 //! A simple, although not necessarily optimal, way of clearing an event before
537 //! returning from the ISR is:
538 //! -# Write to clear event (interrupt source). (buffered write)
539 //! -# Dummy read from the event source module. (making sure the write has propagated)
540 //! -# Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any
541 //! synchronizers)
542 //!
543 //! \param base is the base address of the UART port.
544 //! \param intFlags is a bit mask of the interrupt sources to be cleared.
545 //! - \ref UART_INT_EOT : End Of Transmission interrupt.
546 //! - \ref UART_INT_OE : Overrun Error interrupt.
547 //! - \ref UART_INT_BE : Break Error interrupt.
548 //! - \ref UART_INT_PE : Parity Error interrupt.
549 //! - \ref UART_INT_FE : Framing Error interrupt.
550 //! - \ref UART_INT_RT : Receive Timeout interrupt.
551 //! - \ref UART_INT_TX : Transmit interrupt.
552 //! - \ref UART_INT_RX : Receive interrupt.
553 //! - \ref UART_INT_CTS : CTS interrupt.
554 //! - \ref UART_INT_TXDMADONE : TX DMA Done interrupt.
555 //! - \ref UART_INT_RXDMADONE : RX DMA Done interrupt.
556 //!
557 //! \return None
558 //
559 //*****************************************************************************
UARTClearInt(uint32_t base,uint32_t intFlags)560 __STATIC_INLINE void UARTClearInt(uint32_t base, uint32_t intFlags)
561 {
562 // Clear the requested interrupt sources
563 HWREG(base + UART_O_ICR) = intFlags;
564 }
565
566 //*****************************************************************************
567 //
568 //! \brief Enable UART DMA operation.
569 //!
570 //! The specified UART DMA features are enabled. The UART can be
571 //! configured to use DMA for transmit or receive, and to disable
572 //! receive if an error occurs.
573 //!
574 //! \note The uDMA controller must also be set up before DMA can be used
575 //! with the UART.
576 //!
577 //! \param base is the base address of the UART port.
578 //! \param dmaFlags is a bit mask of the DMA features to enable.
579 //! The parameter is the bitwise OR of any of the following values:
580 //! - UART_DMA_RX : Enable DMA for receive.
581 //! - UART_DMA_TX : Enable DMA for transmit.
582 //! - UART_DMA_ERR_RXSTOP : Disable DMA receive on UART error.
583 //!
584 //! \return None
585 //
586 //*****************************************************************************
UARTEnableDMA(uint32_t base,uint32_t dmaFlags)587 __STATIC_INLINE void UARTEnableDMA(uint32_t base, uint32_t dmaFlags)
588 {
589 // Set the requested bits in the UART DMA control register.
590 HWREG(base + UART_O_DMACTL) |= dmaFlags;
591 }
592
593 //*****************************************************************************
594 //
595 //! \brief Disable UART DMA operation.
596 //!
597 //! This function is used to disable UART DMA features that were enabled
598 //! by \ref UARTEnableDMA(). The specified UART DMA features are disabled.
599 //!
600 //! \param base is the base address of the UART port.
601 //! \param dmaFlags is a bit mask of the DMA features to disable.
602 //! The parameter is the bitwise OR of any of the following values:
603 //! - UART_DMA_RX : Enable DMA for receive.
604 //! - UART_DMA_TX : Enable DMA for transmit.
605 //! - UART_DMA_ERR_RXSTOP : Disable DMA receive on UART error.
606 //!
607 //! \return None
608 //
609 //*****************************************************************************
UARTDisableDMA(uint32_t base,uint32_t dmaFlags)610 __STATIC_INLINE void UARTDisableDMA(uint32_t base, uint32_t dmaFlags)
611 {
612 // Clear the requested bits in the UART DMA control register.
613 HWREG(base + UART_O_DMACTL) &= ~dmaFlags;
614 }
615
616 //*****************************************************************************
617 //
618 //! \brief Gets current receiver errors.
619 //!
620 //! This function returns the current state of each of the 4 receiver error
621 //! sources. The returned errors are equivalent to the four error bits
622 //! returned via the previous call to \ref UARTGetChar() or \ref UARTGetCharNonBlocking()
623 //! with the exception that the overrun error is set immediately the overrun
624 //! occurs rather than when a character is next read.
625 //!
626 //! \param base is the base address of the UART port.
627 //!
628 //! \return Returns a bitwise OR combination of the receiver error flags:
629 //! - \ref UART_RXERROR_FRAMING
630 //! - \ref UART_RXERROR_PARITY
631 //! - \ref UART_RXERROR_BREAK
632 //! - \ref UART_RXERROR_OVERRUN
633 //
634 //*****************************************************************************
UARTGetRxError(uint32_t base)635 __STATIC_INLINE uint32_t UARTGetRxError(uint32_t base)
636 {
637 // Return the current value of the receive status register.
638 return (HWREG(base + UART_O_RSR_ECR) & 0x0000000F);
639 }
640
641 //*****************************************************************************
642 //
643 //! \brief Clears all reported receiver errors.
644 //!
645 //! This function is used to clear all receiver error conditions reported via
646 //! \ref UARTGetRxError(). If using the overrun, framing error, parity error or
647 //! break interrupts, this function must be called after clearing the interrupt
648 //! to ensure that later errors of the same type trigger another interrupt.
649 //!
650 //! \param base is the base address of the UART port.
651 //!
652 //! \return None
653 //
654 //*****************************************************************************
UARTClearRxError(uint32_t base)655 __STATIC_INLINE void UARTClearRxError(uint32_t base)
656 {
657 // Any write to the Error Clear Register will clear all bits which are
658 // currently set.
659 HWREG(base + UART_O_RSR_ECR) = 0;
660 }
661
662 //*****************************************************************************
663 //
664 //! \brief Enable CTS flow control
665 //!
666 //! Hardware flow control is disabled by default.
667 //!
668 //! \param base is the base address of the UART port.
669 //!
670 //! \return None
671 //
672 //*****************************************************************************
UARTEnableCTS(uint32_t base)673 __STATIC_INLINE void UARTEnableCTS(uint32_t base)
674 {
675 HWREG(base + UART_O_CTL) |= (UART_CTL_CTSEN);
676 }
677
678 //*****************************************************************************
679 //
680 //! \brief Enable RTS flow control
681 //!
682 //! Hardware flow control is disabled by default.
683 //!
684 //! \param base is the base address of the UART port.
685 //!
686 //! \return None
687 //
688 //*****************************************************************************
UARTEnableRTS(uint32_t base)689 __STATIC_INLINE void UARTEnableRTS(uint32_t base)
690 {
691 HWREG(base + UART_O_CTL) |= (UART_CTL_RTSEN);
692 }
693
694 //*****************************************************************************
695 //
696 //! \brief Disable CTS flow control
697 //!
698 //! Hardware flow control is disabled by default.
699 //!
700 //! \param base is the base address of the UART port.
701 //!
702 //! \return None
703 //
704 //*****************************************************************************
UARTDisableCTS(uint32_t base)705 __STATIC_INLINE void UARTDisableCTS(uint32_t base)
706 {
707 HWREG(base + UART_O_CTL) &= ~(UART_CTL_CTSEN);
708 }
709
710 //*****************************************************************************
711 //
712 //! \brief Disable RTS flow control
713 //!
714 //! Hardware flow control is disabled by default.
715 //!
716 //! \param base is the base address of the UART port.
717 //!
718 //! \return None
719 //
720 //*****************************************************************************
UARTDisableRTS(uint32_t base)721 __STATIC_INLINE void UARTDisableRTS(uint32_t base)
722 {
723 HWREG(base + UART_O_CTL) &= ~(UART_CTL_RTSEN);
724 }
725
726 //*****************************************************************************
727 //
728 // Mark the end of the C bindings section for C++ compilers.
729 //
730 //*****************************************************************************
731 #ifdef __cplusplus
732 }
733 #endif
734
735 //*****************************************************************************
736 //
737 //! Close the Doxygen group.
738 //! @}
739 //! @}
740 //
741 //*****************************************************************************
742
743 #endif // __UART_H__
744