AM243x MCU+ SDK  09.02.00
uart/v0/uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021-2023 Texas Instruments Incorporated
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 
48 #ifndef UART_V0_H_
49 #define UART_V0_H_
50 
51 /* ========================================================================== */
52 /* Include Files */
53 /* ========================================================================== */
54 
55 #include <stdint.h>
56 #include <kernel/dpl/SemaphoreP.h>
57 #include <kernel/dpl/HwiP.h>
58 #include <drivers/hw_include/cslr.h>
59 #include <drivers/hw_include/cslr_uart.h>
60 #include <drivers/hw_include/hw_types.h>
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 /* ========================================================================== */
68 /* Macros & Typedefs */
69 /* ========================================================================== */
70 
71 
73 typedef void *UART_Handle;
74 
94 #define UART_TRANSFER_MODE_BLOCKING (0U)
95 
99 #define UART_TRANSFER_MODE_CALLBACK (1U)
100 
109 typedef void (*UART_CallbackFxn) (UART_Handle handle,
110  UART_Transaction *transaction);
111 
122 typedef struct
123 {
124  uint32_t baudRate;
126  uint32_t dataLength;
128  uint32_t stopBits;
130  uint32_t parityType;
132  uint32_t readMode;
134  uint32_t readReturnMode;
136  uint32_t writeMode;
142  uint32_t hwFlowControl;
147  /*
148  * Driver configuration
149  */
150  uint32_t transferMode;
152  uint32_t intrNum;
154  uint8_t intrPriority;
156  uint32_t skipIntrReg;
158  int32_t uartDmaIndex;
163  /*
164  * UART configuration
165  */
166  uint32_t operMode;
168  uint32_t rxTrigLvl;
170  uint32_t txTrigLvl;
172  uint32_t rxEvtNum;
174  uint32_t txEvtNum;
176  uint32_t timeGuardVal;
177  /* timeguard feature by UART*/
178 } UART_Params;
179 
181 typedef struct
182 {
183  /*
184  * SOC configuration
185  */
186  uint32_t baseAddr;
188  uint32_t inputClkFreq;
190 } UART_Attrs;
191 
192 /* ========================================================================== */
193 /* Internal/Private Structure Declarations */
194 /* ========================================================================== */
195 
199 typedef struct
200 {
201  /*
202  * User parameters
203  */
208  /*
209  * UART write variables
210  */
211  const void *writeBuf;
213  uint32_t writeCount;
217  /*
218  * UART receive variables
219  */
220  void *readBuf;
222  uint32_t readCount;
226  uint32_t rxTimeoutCnt;
228  uint32_t readErrorCnt;
230  /*
231  * UART ransaction status variables
232  */
237  /*
238  * State variables
239  */
240  uint32_t isOpen;
242  void *lock;
256  void *hwiHandle;
267 } UART_Object;
268 
275 typedef struct
276 {
281 } UART_Config;
282 
284 extern UART_Config gUartConfig[];
286 extern uint32_t gUartConfigNum;
287 
288 /* ========================================================================== */
289 /* Global Variables Declarations */
290 /* ========================================================================== */
291 
292 /* None */
293 
294 /* ========================================================================== */
295 /* Function Declarations */
296 /* ========================================================================== */
297 
301 void UART_init(void);
302 
306 void UART_deinit(void);
307 
324 UART_Handle UART_open(uint32_t index, const UART_Params *prms);
325 
335 void UART_close(UART_Handle handle);
336 
375 int32_t UART_write(UART_Handle handle, UART_Transaction *trans);
376 
411 int32_t UART_read(UART_Handle handle, UART_Transaction *trans);
412 
445 
478 
488 
499 
500 /* ========================================================================== */
501 /* Advanced Function Declarations */
502 /* ========================================================================== */
511 uint32_t UART_getBaseAddr(UART_Handle handle);
512 
520 
527 
528 #ifdef __cplusplus
529 }
530 #endif
531 
532 #endif /* #ifndef UART_V0_H_ */
533 
UART_deinit
void UART_deinit(void)
This function de-initializes the UART module.
UART_Object::readTransferSem
void * readTransferSem
Definition: uart/v0/uart.h:246
UART_Object::lockObj
SemaphoreP_Object lockObj
Definition: uart/v0/uart.h:244
UART_Params::timeGuardVal
uint32_t timeGuardVal
Definition: uart/v0/uart.h:176
UART_Object::readTransferSemObj
SemaphoreP_Object readTransferSemObj
Definition: uart/v0/uart.h:249
UART_Object::uartLld_object
UARTLLD_Object uartLld_object
Definition: uart/v0/uart.h:262
UART_Object::handle
UART_Handle handle
Definition: uart/v0/uart.h:204
UART_Object::hwiHandle
void * hwiHandle
Definition: uart/v0/uart.h:256
index
uint16_t index
Definition: tisci_rm_proxy.h:3
UART_Object::writeBuf
const void * writeBuf
Definition: uart/v0/uart.h:211
UART_Handle
void * UART_Handle
A handle that is returned from a UART_open() call.
Definition: uart/v0/uart.h:73
UART_Object::writeTrans
UART_Transaction * writeTrans
Definition: uart/v0/uart.h:235
UART_Transaction_init
void UART_Transaction_init(UART_Transaction *trans)
Function to initialize the UART_Transaction struct to its defaults.
UART_getHandle
UART_Handle UART_getHandle(uint32_t index)
Function to return a open'ed UART handle given a UART instance index.
UART_writeCancel
int32_t UART_writeCancel(UART_Handle handle, UART_Transaction *trans)
Function to perform UART canceling of current write transaction.
UART_Object::uartLld_initObject
UARTLLD_InitObject uartLld_initObject
Definition: uart/v0/uart.h:266
UART_Config
UART global configuration array.
Definition: uart/v0/uart.h:276
UART_Params::writeMode
uint32_t writeMode
Definition: uart/v0/uart.h:136
UART_Object::writeSizeRemaining
uint32_t writeSizeRemaining
Definition: uart/v0/uart.h:215
UART_Params_init
void UART_Params_init(UART_Params *prms)
Function to initialize the UART_Params struct to its defaults.
UART_CallbackFxn
void(* UART_CallbackFxn)(UART_Handle handle, UART_Transaction *transaction)
The definition of a callback function used by the UART driver when used in UART_TRANSFER_MODE_CALLBAC...
Definition: uart/v0/uart.h:109
UART_Params::dataLength
uint32_t dataLength
Definition: uart/v0/uart.h:126
UART_Params::intrPriority
uint8_t intrPriority
Definition: uart/v0/uart.h:154
UART_write
int32_t UART_write(UART_Handle handle, UART_Transaction *trans)
Function to perform UART write operation.
UART_Params::readMode
uint32_t readMode
Definition: uart/v0/uart.h:132
SemaphoreP.h
UART_Params::rxTrigLvl
uint32_t rxTrigLvl
Definition: uart/v0/uart.h:168
UART_close
void UART_close(UART_Handle handle)
Function to close a UART peripheral specified by the UART handle.
gUartConfig
UART_Config gUartConfig[]
Externally defined driver configuration array.
UARTLLD_InitObject
UART driver initialization object.
Definition: uart_lld.h:506
UART_Object::uartLld_handle
UARTLLD_Handle uartLld_handle
Definition: uart/v0/uart.h:263
UART_Params::uartDmaIndex
int32_t uartDmaIndex
Definition: uart/v0/uart.h:158
UART_Object::uartDmaHandle
void * uartDmaHandle
Definition: uart/v0/uart.h:260
UART_Object::isOpen
uint32_t isOpen
Definition: uart/v0/uart.h:240
UART_flushTxFifo
void UART_flushTxFifo(UART_Handle handle)
Function to flush a TX FIFO of peripheral specified by the UART handle.
UARTLLD_Object
UART driver object.
Definition: uart_lld.h:576
UART_Params::transferMode
uint32_t transferMode
Definition: uart/v0/uart.h:150
UART_Params::skipIntrReg
uint32_t skipIntrReg
Definition: uart/v0/uart.h:156
UART_Config::attrs
UART_Attrs * attrs
Definition: uart/v0/uart.h:277
UART_Object::writeTransferSemObj
SemaphoreP_Object writeTransferSemObj
Definition: uart/v0/uart.h:254
UART_Object::lock
void * lock
Definition: uart/v0/uart.h:242
UART_Object::readCount
uint32_t readCount
Definition: uart/v0/uart.h:222
UART_Params::parityType
uint32_t parityType
Definition: uart/v0/uart.h:130
UART_Object::rxTimeoutCnt
uint32_t rxTimeoutCnt
Definition: uart/v0/uart.h:226
UART_Object::writeCount
uint32_t writeCount
Definition: uart/v0/uart.h:213
UART_Params::hwFlowControl
uint32_t hwFlowControl
Definition: uart/v0/uart.h:142
UART_Object::readSizeRemaining
uint32_t readSizeRemaining
Definition: uart/v0/uart.h:224
UART_Params::readReturnMode
uint32_t readReturnMode
Definition: uart/v0/uart.h:134
HwiP.h
UART_init
void UART_init(void)
This function initializes the UART module.
UART_Params
UART Parameters.
Definition: uart/v0/uart.h:123
UART_readCancel
int32_t UART_readCancel(UART_Handle handle, UART_Transaction *trans)
Function to perform UART canceling of current read transaction.
UART_Params::baudRate
uint32_t baudRate
Definition: uart/v0/uart.h:124
UART_Params::readCallbackFxn
UART_CallbackFxn readCallbackFxn
Definition: uart/v0/uart.h:138
UART_Object::readErrorCnt
uint32_t readErrorCnt
Definition: uart/v0/uart.h:228
UART_Object::writeTransferSem
void * writeTransferSem
Definition: uart/v0/uart.h:251
UART_Config::object
UART_Object * object
Definition: uart/v0/uart.h:279
UART_Transaction
Data structure used with UART_read() and UART_write()
Definition: uart_lld.h:456
UART_getBaseAddr
uint32_t UART_getBaseAddr(UART_Handle handle)
Function to get base address of UART instance of a particular handle.
UART_Params::intrNum
uint32_t intrNum
Definition: uart/v0/uart.h:152
UART_Attrs::inputClkFreq
uint32_t inputClkFreq
Definition: uart/v0/uart.h:188
UART_open
UART_Handle UART_open(uint32_t index, const UART_Params *prms)
This function opens a given UART peripheral.
UART_Params::writeCallbackFxn
UART_CallbackFxn writeCallbackFxn
Definition: uart/v0/uart.h:140
HwiP_Object
Opaque Hwi object used with the Hwi APIs.
Definition: HwiP.h:93
UART_Object
UART driver object.
Definition: uart/v0/uart.h:200
UART_Params::hwFlowControlThr
uint32_t hwFlowControlThr
Definition: uart/v0/uart.h:144
UART_Object::readTrans
UART_Transaction * readTrans
Definition: uart/v0/uart.h:233
UART_Params::stopBits
uint32_t stopBits
Definition: uart/v0/uart.h:128
UART_Object::readBuf
void * readBuf
Definition: uart/v0/uart.h:220
UART_Params::rxEvtNum
uint32_t rxEvtNum
Definition: uart/v0/uart.h:172
gUartConfigNum
uint32_t gUartConfigNum
Externally defined driver configuration array size.
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
UART_read
int32_t UART_read(UART_Handle handle, UART_Transaction *trans)
Function to perform UART read operation.
uart_lld.h
This file contains the prototype of UART driver APIs.
UART_Attrs
UART instance attributes - used during init time.
Definition: uart/v0/uart.h:182
UART_Params::txEvtNum
uint32_t txEvtNum
Definition: uart/v0/uart.h:174
UART_Attrs::baseAddr
uint32_t baseAddr
Definition: uart/v0/uart.h:186
UART_Object::uartLld_initHandle
UARTLLD_InitHandle uartLld_initHandle
Definition: uart/v0/uart.h:265
UART_Object::hwiObj
HwiP_Object hwiObj
Definition: uart/v0/uart.h:258
UART_Object::prms
UART_Params prms
Definition: uart/v0/uart.h:206
UART_Params::txTrigLvl
uint32_t txTrigLvl
Definition: uart/v0/uart.h:170
UART_Params::operMode
uint32_t operMode
Definition: uart/v0/uart.h:166