MSPM0L11XX_L13XX TI-Driver Library  2.01.00.03
UART.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file UART.h
34  *
35  * @brief UART driver interface.
36  *
37  * @defgroup UART Universal Asynchronous Receiver-Transmitter (UART)
38  *
39  * The UART header file should be included in an application as follows:
40  * @code
41  * #include <ti/drivers/UART.h>
42  * @endcode
43  *
44  * @anchor ti_drivers_UART_Overview
45  * # Overview
46  * UART has both RX and TX ring buffers for receiving/sending data.
47  * UART uses DMA to transfer data between the UART FIFOs and the
48  * RX and TX ring buffers in blocking mode. In callback mode,
49  * DMA will transfer data straight between the hardware
50  * FIFO and the source/destination buffer supplied by the application.
51  * NOTE: If the source-buffer for a TX operation resides in flash,
52  * the driver will constrain the flash to remain on during idle.
53  * The UART APIs for reading and writing data have been made more
54  * posix-like.
55  * UART provides for event notification, allowing the application
56  * to receive TX start and completion events, and RX error events.
57  * @note These events are synchronous to what can be observed on the data
58  * lines. A UART_STAT_TXFE_SET event will for example only occur
59  * after all data has been shifted from the hardware FIFO out onto the
60  * TX-pin. In contrast, read and write-callbacks are invoked when the
61  * driver has finished writing data into the hardware FIFO.
62  *
63  * To use the UART driver, ensure that the correct driver library for your
64  * device is linked in and include this header file as follows:
65  * @code
66  * #include <ti/drivers/UART.h>
67  * @endcode
68  *
69  ******************************************************************************
70  */
74 /* clang-format off */
75 #ifndef ti_drivers_uart_UART__include
76 #define ti_drivers_uart_UART__include
77 
78 #include <stdbool.h>
79 #include <stdint.h>
80 #include <stdlib.h>
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 #include <ti/driverlib/dl_gpio.h>
86 #include <ti/driverlib/dl_uart_main.h>
87 
94 #define UART_STATUS_SUCCESS (0)
95 
99 #define UART_STATUS_SREADTIMEOUT (1)
100 
104 #define UART_STATUS_EFRAMING (-1)
105 
109 #define UART_STATUS_EPARITY (-2)
110 
114 #define UART_STATUS_EBREAK (-4)
115 
119 #define UART_STATUS_EOVERRUN (-8)
120 
124 #define UART_STATUS_EINUSE (-9)
125 
129 #define UART_STATUS_EINVALID (-10)
130 
134 #define UART_STATUS_EFAIL (-11)
135 
139 #define UART_STATUS_EMEMORY (-12)
140 
144 #define UART_STATUS_ETIMEOUT (-13)
145 
149 #define UART_STATUS_ECANCELLED (-14)
150 
154 #define UART_STATUS_ENOTOPEN (-15)
155 
160 #define UART_STATUS_EAGAIN (-16)
161 
168 typedef struct UART_Config_ *UART_Handle;
186 typedef void (*UART_Callback)(UART_Handle handle, void *buf, size_t count,
187  void *userArg, int_fast16_t status);
188 
209 typedef void (*UART_EventCallback)(
210  UART_Handle handle, uint32_t event, uint32_t data, void *userArg);
211 
217 typedef enum {
224 
231 
239 } UART_Mode;
240 
256 typedef enum {
259 
263 
269 typedef enum {
270  UART_DataLen_5 = DL_UART_WORD_LENGTH_5_BITS,
271  UART_DataLen_6 = DL_UART_WORD_LENGTH_6_BITS,
272  UART_DataLen_7 = DL_UART_WORD_LENGTH_7_BITS,
273  UART_DataLen_8 = DL_UART_WORD_LENGTH_8_BITS
274 } UART_DataLen;
275 
281 typedef enum {
282  UART_StopBits_1 = DL_UART_STOP_BITS_ONE,
283  UART_StopBits_2 = DL_UART_STOP_BITS_TWO
284 } UART_StopBits;
285 
291 typedef enum {
292  UART_Parity_NONE = DL_UART_PARITY_NONE,
293  UART_Parity_EVEN = DL_UART_PARITY_EVEN,
294  UART_Parity_ODD = DL_UART_PARITY_ODD,
295  UART_Parity_ZERO = DL_UART_PARITY_STICK_ZERO,
296  UART_Parity_ONE = DL_UART_PARITY_STICK_ONE
297 } UART_Parity;
298 
307 typedef struct {
308  UART_Mode readMode;
309  UART_Mode writeMode;
317  uint32_t eventMask;
318  UART_ReadReturnMode readReturnMode;
319  uint32_t baudRate;
320  UART_DataLen dataLength;
321  UART_StopBits stopBits;
322  UART_Parity parityType;
323  void *userArg;
324 } UART_Params;
325 
346 void UART_Params_init(UART_Params *params);
347 
363 UART_Handle UART_open(uint_least8_t index, UART_Params *params);
364 
377 void UART_close(UART_Handle handle);
378 
434 int_fast16_t UART_read(UART_Handle handle, void *buf, size_t size, size_t *bytesRead);
435 
486 int_fast16_t UART_write(UART_Handle handle, const void *buf, size_t size, size_t *bytesWritten);
487 
513 int_fast16_t UART_readTimeout(UART_Handle handle, void *buf, size_t size, size_t *bytesRead, uint32_t timeout);
514 
536 int_fast16_t UART_writeTimeout(UART_Handle handle, const void *buf, size_t size, size_t *bytesWritten, uint32_t timeout);
537 
557 void UART_readCancel(UART_Handle handle);
558 
576 void UART_writeCancel(UART_Handle handle);
577 
592 void UART_rxDisable(UART_Handle handle);
593 
608 void UART_rxEnable(UART_Handle handle);
609 
621 void UART_flushRx(UART_Handle handle);
622 
635 void UART_getRxCount(UART_Handle handle);
636 
637 #ifdef __cplusplus
638 } /* extern "C" */
639 #endif
640 
641 #endif /* ti_drivers_uart_UART__include */
642 /* clang-format on */
UART_DataLen dataLength
Definition: UART.h:320
void * userArg
Definition: UART.h:323
int_fast16_t UART_write(UART_Handle handle, const void *buf, size_t size, size_t *bytesWritten)
Function that writes data to a UART.
UART_Callback writeCallback
Definition: UART.h:313
UART_ReadReturnMode
UART return mode settings.
Definition: UART.h:256
void UART_flushRx(UART_Handle handle)
Function to flush data in the UART RX FIFO.
Definition: UART.h:238
void UART_readCancel(UART_Handle handle)
Function that cancels a UART_read() function call.
Definition: UART.h:223
UART_StopBits stopBits
Definition: UART.h:321
UART_Callback readCallback
Definition: UART.h:311
void UART_close(UART_Handle handle)
Function to close a UART peripheral specified by the UART handle.
Definition: UART.h:293
Definition: UART.h:271
void UART_getRxCount(UART_Handle handle)
Get the number of bytes available in the circular buffer.
UART_EventCallback eventCallback
Definition: UART.h:315
UART Global configuration.
Definition: UARTSupportMSPM0.h:232
uint32_t eventMask
Definition: UART.h:317
void UART_writeCancel(UART_Handle handle)
Function that cancels a UART_write() function call.
void UART_rxDisable(UART_Handle handle)
Function that disables collecting of RX data into the circular buffer.
UART_Mode writeMode
Definition: UART.h:309
void(* UART_EventCallback)(UART_Handle handle, uint32_t event, uint32_t data, void *userArg)
The definition of a callback function used by the UART driver. The callback can occur in task or inte...
Definition: UART.h:209
Definition: UART.h:292
Definition: UART.h:270
uint32_t baudRate
Definition: UART.h:319
UART_ReadReturnMode readReturnMode
Definition: UART.h:318
Definition: UART.h:295
Definition: UART.h:258
Definition: UART.h:294
void UART_rxEnable(UART_Handle handle)
Function that enables collecting of RX data into the circular buffer.
struct UART_Config_ * UART_Handle
A handle that is returned from a UART_open() call.
Definition: UART.h:168
Definition: UART.h:261
int_fast16_t UART_read(UART_Handle handle, void *buf, size_t size, size_t *bytesRead)
Function that reads data from a UART.
UART_Handle UART_open(uint_least8_t index, UART_Params *params)
Function to initialize a given UART peripheral.
UART_Mode
UART mode settings.
Definition: UART.h:217
Definition: UART.h:283
int_fast16_t UART_writeTimeout(UART_Handle handle, const void *buf, size_t size, size_t *bytesWritten, uint32_t timeout)
UART write with timeout. Note that the timeout parameter is different from the hardware read timeout...
UART_Parity parityType
Definition: UART.h:322
UART Parameters.
Definition: UART.h:307
int_fast16_t UART_readTimeout(UART_Handle handle, void *buf, size_t size, size_t *bytesRead, uint32_t timeout)
UART read with timeout. Note that the timeout parameter is different from the hardware read timeout...
UART_DataLen
UART data length settings.
Definition: UART.h:269
UART_Parity
UART parity type settings.
Definition: UART.h:291
Definition: UART.h:273
void(* UART_Callback)(UART_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
The definition of a callback function used by the UART driver when used in UART_Mode_CALLBACK. The callback can occur in task or interrupt context.
Definition: UART.h:186
Definition: UART.h:282
Definition: UART.h:230
Definition: UART.h:272
Definition: UART.h:296
UART_Mode readMode
Definition: UART.h:308
UART_StopBits
UART stop bit settings.
Definition: UART.h:281
void UART_Params_init(UART_Params *params)
Function to initialize the UART_Params struct to its defaults.
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale