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