UARTCC32XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019, 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  */
58 #ifndef ti_drivers_uart_UARTCC32XX__include
59 #define ti_drivers_uart_UARTCC32XX__include
60 
61 #include <stdint.h>
62 #include <stdbool.h>
63 
64 #include <ti/drivers/dpl/ClockP.h>
65 #include <ti/drivers/dpl/HwiP.h>
66 #include <ti/drivers/dpl/SemaphoreP.h>
67 #include <ti/drivers/Power.h>
69 #include <ti/drivers/UART.h>
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
82 #define UARTCC32XX_PIN_UNASSIGNED 0xFFF
83 
84 /*
85  * The bits in the pin mode macros are as follows:
86  * The lower 8 bits of the macro refer to the pin, offset by 1, to match
87  * driverlib pin defines. For example, UARTCC32XX_PIN_01_UART1_TX & 0xff = 0,
88  * which equals PIN_01 in driverlib pin.h. By matching the PIN_xx defines in
89  * driverlib pin.h, we can pass the pin directly to the driverlib functions.
90  * The upper 8 bits of the macro correspond to the pin mux confg mode
91  * value for the pin to operate in the UART mode. For example, pin 1 is
92  * configured with mode 7 to operate as UART1 TX.
93  */
94 #define UARTCC32XX_PIN_01_UART1_TX 0x700
95 #define UARTCC32XX_PIN_02_UART1_RX 0x701
96 #define UARTCC32XX_PIN_03_UART0_TX 0x702
97 #define UARTCC32XX_PIN_04_UART0_RX 0x703
98 #define UARTCC32XX_PIN_07_UART1_TX 0x506
99 #define UARTCC32XX_PIN_08_UART1_RX 0x507
100 #define UARTCC32XX_PIN_16_UART1_TX 0x20F
101 #define UARTCC32XX_PIN_17_UART1_RX 0x210
102 #define UARTCC32XX_PIN_45_UART0_RX 0x92C
103 #define UARTCC32XX_PIN_45_UART1_RX 0x22C
104 #define UARTCC32XX_PIN_53_UART0_TX 0x934
105 #define UARTCC32XX_PIN_55_UART0_TX 0x336
106 #define UARTCC32XX_PIN_55_UART1_TX 0x636
107 #define UARTCC32XX_PIN_57_UART0_RX 0x338
108 #define UARTCC32XX_PIN_57_UART1_RX 0x638
109 #define UARTCC32XX_PIN_58_UART1_TX 0x639
110 #define UARTCC32XX_PIN_59_UART1_RX 0x63A
111 #define UARTCC32XX_PIN_62_UART0_TX 0xB3D
113 /*
114  * Flow control pins.
115  */
116 #define UARTCC32XX_PIN_50_UART0_CTS 0xC31
117 #define UARTCC32XX_PIN_50_UART0_RTS 0x331
118 #define UARTCC32XX_PIN_50_UART1_RTS 0xA31
119 #define UARTCC32XX_PIN_52_UART0_RTS 0x633
120 #define UARTCC32XX_PIN_61_UART0_RTS 0x53C
121 #define UARTCC32XX_PIN_61_UART0_CTS 0x63C
122 #define UARTCC32XX_PIN_61_UART1_CTS 0x33C
123 #define UARTCC32XX_PIN_62_UART0_RTS 0xA3D
124 #define UARTCC32XX_PIN_62_UART1_RTS 0x33D
129 #define UARTCC32XX_FLOWCTRL_NONE 0
130 
134 #define UARTCC32XX_FLOWCTRL_HARDWARE 1
135 
146 /* Add UARTCC32XX_STATUS_* macros here */
147 
168 #define UARTCC32XX_CMD_IS_BUSY (UART_CMD_RESERVED + 0)
169 
170 
179 #define UARTCC32XX_CMD_IS_RX_DATA_AVAILABLE (UART_CMD_RESERVED + 1)
180 
181 
190 #define UARTCC32XX_CMD_IS_TX_SPACE_AVAILABLE (UART_CMD_RESERVED + 2)
191 
192 
195 /* UART function table pointer */
197 
219 typedef struct {
220  bool (*readIsrFxn) (UART_Handle handle);
221  int (*readTaskFxn) (UART_Handle handle);
223 
236 typedef void (*UARTCC32XX_ErrorCallback) (UART_Handle handle, uint32_t error);
237 
292 typedef struct {
294  unsigned int baseAddr;
296  unsigned int intNum;
298  unsigned int intPriority;
300  uint32_t flowControl;
302  unsigned char *ringBufPtr;
304  size_t ringBufSize;
306  uint16_t rxPin;
308  uint16_t txPin;
310  uint16_t ctsPin;
312  uint16_t rtsPin;
316 
322 typedef struct {
323  /* UART state variable */
324  struct {
325  bool opened:1; /* Has the obj been opened */
326  UART_Mode readMode:1; /* Mode for all read calls */
327  UART_Mode writeMode:1; /* Mode for all write calls */
328  UART_DataMode readDataMode:1; /* Type of data being read */
329  UART_DataMode writeDataMode:1; /* Type of data being written */
330  UART_ReturnMode readReturnMode:1; /* Receive return mode */
331  UART_Echo readEcho:1; /* Echo received data back */
332  /*
333  * Flag to determine if a timeout has occurred when the user called
334  * UART_read(). This flag is set by the timeoutClk clock object.
335  */
336  bool bufTimeout:1;
337  /*
338  * Flag to determine when an ISR needs to perform a callback; in both
339  * UART_MODE_BLOCKING or UART_MODE_CALLBACK
340  */
341  bool callCallback:1;
342  /*
343  * Flag to determine if the ISR is in control draining the ring buffer
344  * when in UART_MODE_CALLBACK
345  */
346  bool drainByISR:1;
347  /* Flag to keep the state of the read Power constraints */
348  bool rxEnabled:1;
349  /* Flag to keep the state of the write Power constraints */
350  bool txEnabled:1;
351 
352  /* Flags to prevent recursion in read callback mode */
353  bool inReadCallback:1;
354  volatile bool readCallbackPending:1;
355  } state;
356 
357  HwiP_Handle hwiHandle; /* Hwi handle for interrupts */
358  ClockP_Handle timeoutClk; /* Clock object to for timeouts */
359  uint32_t baudRate; /* Baud rate for UART */
360  UART_LEN dataLength; /* Data length for UART */
361  UART_STOP stopBits; /* Stop bits for UART */
362  UART_PAR parityType; /* Parity bit type for UART */
363 
364  /* UART read variables */
365  RingBuf_Object ringBuffer; /* local circular buffer object */
366  /* A complement pair of read functions for both the ISR and UART_read() */
368  unsigned char *readBuf; /* Buffer data pointer */
369  size_t readSize; /* Desired number of bytes to read */
370  size_t readCount; /* Number of bytes left to read */
371  SemaphoreP_Handle readSem; /* UART read semaphore */
372  unsigned int readTimeout; /* Timeout for read semaphore */
373  UART_Callback readCallback; /* Pointer to read callback */
374 
375  /* UART write variables */
376  const unsigned char *writeBuf; /* Buffer data pointer */
377  size_t writeSize; /* Desired number of bytes to write*/
378  size_t writeCount; /* Number of bytes left to write */
379  SemaphoreP_Handle writeSem; /* UART write semaphore*/
380  unsigned int writeTimeout; /* Timeout for write semaphore */
381  UART_Callback writeCallback; /* Pointer to write callback */
382 
383  /* For Power management */
384  Power_NotifyObj postNotify; /* LPDS wake-up notify object */
385  unsigned int powerMgrId; /* Determined from base address */
386  PowerCC32XX_ParkState prevParkTX; /* Previous park state TX pin */
387  uint16_t txPin; /* TX pin ID */
388  PowerCC32XX_ParkState prevParkRTS; /* Previous park state of RTS pin */
389  uint16_t rtsPin; /* RTS pin ID */
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif /* ti_drivers_uart_UARTCC32XX__include */
UART_STOP
UART stop bit settings.
Definition: UART.h:523
const unsigned char * writeBuf
Definition: UARTCC32XX.h:376
unsigned int powerMgrId
Definition: UARTCC32XX.h:385
void(* UARTCC32XX_ErrorCallback)(UART_Handle handle, uint32_t error)
The definition of an optional callback function used by the UART driver to notify the application whe...
Definition: UARTCC32XX.h:236
uint16_t txPin
Definition: UARTCC32XX.h:308
uint32_t baudRate
Definition: UARTCC32XX.h:359
const UART_FxnTable UARTCC32XX_fxnTable
Power_NotifyObj postNotify
Definition: UARTCC32XX.h:384
uint32_t flowControl
Definition: UARTCC32XX.h:300
unsigned int intNum
Definition: UARTCC32XX.h:296
UARTCC32XX Object.
Definition: UARTCC32XX.h:322
uint16_t txPin
Definition: UARTCC32XX.h:387
The definition of a UART function table that contains the required set of functions to control a spec...
Definition: UART.h:635
SemaphoreP_Handle readSem
Definition: UARTCC32XX.h:371
Power Manager.
UART_PAR
UART parity type settings.
Definition: UART.h:533
UART_Mode
UART mode settings.
Definition: UART.h:428
unsigned int baseAddr
Definition: UARTCC32XX.h:294
UART_DataMode
UART data mode settings.
Definition: UART.h:483
UART_ReturnMode
UART return mode settings.
Definition: UART.h:461
uint16_t rtsPin
Definition: UARTCC32XX.h:312
UART_Echo
UART echo settings.
Definition: UART.h:501
PowerCC32XX_ParkState prevParkTX
Definition: UARTCC32XX.h:386
UART Global configuration.
Definition: UART.h:678
size_t readCount
Definition: UARTCC32XX.h:370
uint16_t ctsPin
Definition: UARTCC32XX.h:310
UART_LEN dataLength
Definition: UARTCC32XX.h:360
Power manager interface for the CC32XX.
size_t readSize
Definition: UARTCC32XX.h:369
UART_Callback writeCallback
Definition: UARTCC32XX.h:381
UARTCC32XX_ErrorCallback errorFxn
Definition: UARTCC32XX.h:314
Complement set of read functions to be used by the UART ISR and UARTCC32XX_read(). Internal use only.
Definition: UARTCC32XX.h:219
Power notify object structure.
Definition: Power.h:443
unsigned int intPriority
Definition: UARTCC32XX.h:298
unsigned int writeTimeout
Definition: UARTCC32XX.h:380
Universal Asynchronous Receiver-Transmitter (UART) Driver.
HwiP_Handle hwiHandle
Definition: UARTCC32XX.h:357
UARTCC32XX Hardware attributes.
Definition: UARTCC32XX.h:292
uint16_t rtsPin
Definition: UARTCC32XX.h:389
struct UARTCC32XX_Object * UARTCC32XX_Handle
UART_PAR parityType
Definition: UARTCC32XX.h:362
UART_Callback readCallback
Definition: UARTCC32XX.h:373
Definition: RingBuf.h:44
unsigned char * ringBufPtr
Definition: UARTCC32XX.h:302
UART_LEN
UART data length settings.
Definition: UART.h:511
SemaphoreP_Handle writeSem
Definition: UARTCC32XX.h:379
unsigned int readTimeout
Definition: UARTCC32XX.h:372
RingBuf_Object ringBuffer
Definition: UARTCC32XX.h:365
PowerCC32XX_ParkState prevParkRTS
Definition: UARTCC32XX.h:388
UARTCC32XX_FxnSet readFxns
Definition: UARTCC32XX.h:367
size_t ringBufSize
Definition: UARTCC32XX.h:304
unsigned char * readBuf
Definition: UARTCC32XX.h:368
ClockP_Handle timeoutClk
Definition: UARTCC32XX.h:358
uint16_t rxPin
Definition: UARTCC32XX.h:306
UART_STOP stopBits
Definition: UARTCC32XX.h:361
size_t writeSize
Definition: UARTCC32XX.h:377
void(* UART_Callback)(UART_Handle handle, void *buf, size_t count)
The definition of a callback function used by the UART driver when used in UART_MODE_CALLBACK The cal...
Definition: UART.h:421
size_t writeCount
Definition: UARTCC32XX.h:378
PowerCC32XX_ParkState
Enumeration of states a pin can be parked in.
Definition: PowerCC32XX.h:385
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale