UARTCC32XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017, 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  */
90 #ifndef ti_drivers_uart_UARTCC32XX__include
91 #define ti_drivers_uart_UARTCC32XX__include
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 #include <stdint.h>
98 #include <stdbool.h>
99 
100 #include <ti/drivers/dpl/ClockP.h>
101 #include <ti/drivers/dpl/HwiP.h>
102 #include <ti/drivers/dpl/SemaphoreP.h>
103 #include <ti/drivers/Power.h>
105 #include <ti/drivers/UART.h>
107 
108 
115 #define UARTCC32XX_PIN_UNASSIGNED 0xFFF
116 
117 #define UARTCC32XX_PIN_01_UART1_TX 0x700
118 #define UARTCC32XX_PIN_02_UART1_RX 0x701
119 #define UARTCC32XX_PIN_03_UART0_TX 0x702
120 #define UARTCC32XX_PIN_04_UART0_RX 0x703
121 #define UARTCC32XX_PIN_07_UART1_TX 0x506
122 #define UARTCC32XX_PIN_08_UART1_RX 0x507
123 #define UARTCC32XX_PIN_16_UART1_TX 0x20F
124 #define UARTCC32XX_PIN_17_UART1_RX 0x210
125 #define UARTCC32XX_PIN_45_UART0_RX 0x92C
126 #define UARTCC32XX_PIN_45_UART1_RX 0x22C
127 #define UARTCC32XX_PIN_53_UART0_TX 0x934
128 #define UARTCC32XX_PIN_55_UART0_TX 0x336
129 #define UARTCC32XX_PIN_55_UART1_TX 0x636
130 #define UARTCC32XX_PIN_57_UART0_RX 0x338
131 #define UARTCC32XX_PIN_57_UART1_RX 0x638
132 #define UARTCC32XX_PIN_58_UART1_TX 0x639
133 #define UARTCC32XX_PIN_59_UART1_RX 0x63A
134 #define UARTCC32XX_PIN_62_UART0_TX 0xB3D
135 
136 /*
137  * Flow control pins. Only available for UART1. The CTS and RTS
138  * pins for UART0 and UART2 are shown in the Pin Multiplexing table,
139  * but CTSEN and RTSEN are only implemented on UART1.
140  */
141 //#define UARTCC32XX_PIN_50_UART0_CTS 0xC31
142 //#define UARTCC32XX_PIN_50_UART0_RTS 0x331
143 #define UARTCC32XX_PIN_50_UART1_RTS 0xA31
144 //#define UARTCC32XX_PIN_52_UART0_RTS 0x633
145 //#define UARTCC32XX_PIN_61_UART0_RTS 0x53C
146 //#define UARTCC32XX_PIN_61_UART0_CTS 0x63C
147 #define UARTCC32XX_PIN_61_UART1_CTS 0x33C
148 //#define UARTCC32XX_PIN_62_UART0_RTS 0xA3D
149 #define UARTCC32XX_PIN_62_UART1_RTS 0x33D
150 
154 #define UARTCC32XX_FLOWCTRL_NONE 0
155 
159 #define UARTCC32XX_FLOWCTRL_HARDWARE 1
160 
171 /* Add UARTCC32XX_STATUS_* macros here */
172 
193 #define UARTCC32XX_CMD_IS_BUSY (UART_CMD_RESERVED + 0)
194 
195 
204 #define UARTCC32XX_CMD_IS_RX_DATA_AVAILABLE (UART_CMD_RESERVED + 1)
205 
206 
215 #define UARTCC32XX_CMD_IS_TX_SPACE_AVAILABLE (UART_CMD_RESERVED + 2)
216 
217 
220 /* UART function table pointer */
222 
244 typedef struct UARTCC32XX_FxnSet {
245  bool (*readIsrFxn) (UART_Handle handle);
246  int (*readTaskFxn) (UART_Handle handle);
248 
301 typedef struct UARTCC32XX_HWAttrsV1 {
303  unsigned int baseAddr;
305  unsigned int intNum;
307  unsigned int intPriority;
309  uint32_t flowControl;
311  unsigned char *ringBufPtr;
313  size_t ringBufSize;
315  uint16_t rxPin;
317  uint16_t txPin;
319  uint16_t ctsPin;
321  uint16_t rtsPin;
323 
329 typedef struct UARTCC32XX_Object {
330  /* UART state variable */
331  struct {
332  bool opened:1; /* Has the obj been opened */
333  UART_Mode readMode:1; /* Mode for all read calls */
334  UART_Mode writeMode:1; /* Mode for all write calls */
335  UART_DataMode readDataMode:1; /* Type of data being read */
336  UART_DataMode writeDataMode:1; /* Type of data being written */
337  UART_ReturnMode readReturnMode:1; /* Receive return mode */
338  UART_Echo readEcho:1; /* Echo received data back */
339  /*
340  * Flag to determine if a timeout has occurred when the user called
341  * UART_read(). This flag is set by the timeoutClk clock object.
342  */
343  bool bufTimeout:1;
344  /*
345  * Flag to determine when an ISR needs to perform a callback; in both
346  * UART_MODE_BLOCKING or UART_MODE_CALLBACK
347  */
348  bool callCallback:1;
349  /*
350  * Flag to determine if the ISR is in control draining the ring buffer
351  * when in UART_MODE_CALLBACK
352  */
353  bool drainByISR:1;
354  /* Flag to keep the state of the read Power constraints */
355  bool rxEnabled:1;
356  /* Flag to keep the state of the write Power constraints */
357  bool txEnabled:1;
358  } state;
359 
360  HwiP_Handle hwiHandle; /* Hwi handle for interrupts */
361  ClockP_Handle timeoutClk; /* Clock object to for timeouts */
362  uint32_t baudRate; /* Baud rate for UART */
363  UART_LEN dataLength; /* Data length for UART */
364  UART_STOP stopBits; /* Stop bits for UART */
365  UART_PAR parityType; /* Parity bit type for UART */
366 
367  /* UART read variables */
368  RingBuf_Object ringBuffer; /* local circular buffer object */
369  /* A complement pair of read functions for both the ISR and UART_read() */
371  unsigned char *readBuf; /* Buffer data pointer */
372  size_t readSize; /* Desired number of bytes to read */
373  size_t readCount; /* Number of bytes left to read */
374  SemaphoreP_Handle readSem; /* UART read semaphore */
375  unsigned int readTimeout; /* Timeout for read semaphore */
376  UART_Callback readCallback; /* Pointer to read callback */
377 
378  /* UART write variables */
379  const unsigned char *writeBuf; /* Buffer data pointer */
380  size_t writeSize; /* Desired number of bytes to write*/
381  size_t writeCount; /* Number of bytes left to write */
382  SemaphoreP_Handle writeSem; /* UART write semaphore*/
383  unsigned int writeTimeout; /* Timeout for write semaphore */
384  UART_Callback writeCallback; /* Pointer to write callback */
385  unsigned int writeEmptyClkTimeout; /* TX FIFO timeout tick count */
386 
387  /* For Power management */
388  ClockP_Handle txFifoEmptyClk; /* UART TX FIFO empty clock */
389  Power_NotifyObj postNotify; /* LPDS wake-up notify object */
390  unsigned int powerMgrId; /* Determined from base address */
391  PowerCC32XX_ParkState prevParkTX; /* Previous park state TX pin */
392  uint16_t txPin; /* TX pin ID */
393  PowerCC32XX_ParkState prevParkRTS; /* Previous park state of RTS pin */
394  uint16_t rtsPin; /* RTS pin ID */
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /* ti_drivers_uart_UARTCC32XX__include */
const unsigned char * writeBuf
Definition: UARTCC32XX.h:379
enum UART_Echo_ UART_Echo
UART echo settings.
unsigned int powerMgrId
Definition: UARTCC32XX.h:390
uint16_t txPin
Definition: UARTCC32XX.h:317
uint32_t baudRate
Definition: UARTCC32XX.h:362
const UART_FxnTable UARTCC32XX_fxnTable
Power_NotifyObj postNotify
Definition: UARTCC32XX.h:389
uint32_t flowControl
Definition: UARTCC32XX.h:309
unsigned int intNum
Definition: UARTCC32XX.h:305
UARTCC32XX Object.
Definition: UARTCC32XX.h:329
uint16_t txPin
Definition: UARTCC32XX.h:392
enum UART_PAR_ UART_PAR
UART parity type settings.
SemaphoreP_Handle readSem
Definition: UARTCC32XX.h:374
Power manager interface.
enum UART_LEN_ UART_LEN
UART data length settings.
struct UARTCC32XX_Object * UARTCC32XX_Handle
enum UART_Mode_ UART_Mode
UART mode settings.
Power notify object structure.
Definition: Power.h:113
unsigned int baseAddr
Definition: UARTCC32XX.h:303
uint16_t rtsPin
Definition: UARTCC32XX.h:321
PowerCC32XX_ParkState prevParkTX
Definition: UARTCC32XX.h:391
UART Global configuration.
Definition: UART.h:695
size_t readCount
Definition: UARTCC32XX.h:373
struct UARTCC32XX_HWAttrsV1 UARTCC32XX_HWAttrsV1
UARTCC32XX Hardware attributes.
uint16_t ctsPin
Definition: UARTCC32XX.h:319
UART_LEN dataLength
Definition: UARTCC32XX.h:363
Power manager interface for the CC32XX.
struct UARTCC32XX_FxnSet UARTCC32XX_FxnSet
Complement set of read functions to be used by the UART ISR and UARTCC32XX_read(). Internal use only.
ClockP_Handle txFifoEmptyClk
Definition: UARTCC32XX.h:388
size_t readSize
Definition: UARTCC32XX.h:372
UART_Callback writeCallback
Definition: UARTCC32XX.h:384
unsigned int writeEmptyClkTimeout
Definition: UARTCC32XX.h:385
The definition of a UART function table that contains the required set of functions to control a spec...
Definition: UART.h:652
Complement set of read functions to be used by the UART ISR and UARTCC32XX_read(). Internal use only.
Definition: UARTCC32XX.h:244
unsigned int intPriority
Definition: UARTCC32XX.h:307
unsigned int writeTimeout
Definition: UARTCC32XX.h:383
UART driver interface.
HwiP_Handle hwiHandle
Definition: UARTCC32XX.h:360
UARTCC32XX Hardware attributes.
Definition: UARTCC32XX.h:301
uint16_t rtsPin
Definition: UARTCC32XX.h:394
struct UARTCC32XX_Object UARTCC32XX_Object
UARTCC32XX Object.
enum UART_STOP_ UART_STOP
UART stop bit settings.
enum UART_ReturnMode_ UART_ReturnMode
UART return mode settings.
UART_PAR parityType
Definition: UARTCC32XX.h:365
UART_Callback readCallback
Definition: UARTCC32XX.h:376
Definition: RingBuf.h:44
unsigned char * ringBufPtr
Definition: UARTCC32XX.h:311
int(* readTaskFxn)(UART_Handle handle)
Definition: UARTCC32XX.h:246
SemaphoreP_Handle writeSem
Definition: UARTCC32XX.h:382
unsigned int readTimeout
Definition: UARTCC32XX.h:375
RingBuf_Object ringBuffer
Definition: UARTCC32XX.h:368
PowerCC32XX_ParkState prevParkRTS
Definition: UARTCC32XX.h:393
UARTCC32XX_FxnSet readFxns
Definition: UARTCC32XX.h:370
size_t ringBufSize
Definition: UARTCC32XX.h:313
unsigned char * readBuf
Definition: UARTCC32XX.h:371
ClockP_Handle timeoutClk
Definition: UARTCC32XX.h:361
uint16_t rxPin
Definition: UARTCC32XX.h:315
UART_STOP stopBits
Definition: UARTCC32XX.h:364
size_t writeSize
Definition: UARTCC32XX.h:380
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:438
size_t writeCount
Definition: UARTCC32XX.h:381
bool(* readIsrFxn)(UART_Handle handle)
Definition: UARTCC32XX.h:245
enum UART_DataMode_ UART_DataMode
UART data mode settings.
PowerCC32XX_ParkState
Enumeration of states a pin can be parked in.
Definition: PowerCC32XX.h:385
Copyright 2017, Texas Instruments Incorporated