UARTMSP432E4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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  */
48 #ifndef ti_drivers_uart_UARTMSP432E4__include
49 #define ti_drivers_uart_UARTMSP432E4__include
50 
51 #include <stdbool.h>
52 #include <stddef.h>
53 #include <stdint.h>
54 
55 #include <ti/devices/msp432e4/inc/msp432.h>
56 
57 #include <ti/devices/msp432e4/driverlib/gpio.h>
58 #include <ti/devices/msp432e4/driverlib/pin_map.h>
59 
60 #include <ti/drivers/dpl/ClockP.h>
61 #include <ti/drivers/dpl/HwiP.h>
62 #include <ti/drivers/dpl/SemaphoreP.h>
63 
65 #include <ti/drivers/UART.h>
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
78 #define UARTMSP432E4_PIN_UNASSIGNED 0xFFFFFFFF
79 
83 #define UARTMSP432E4_FLOWCTRL_NONE 0
84 
88 #define UARTMSP432E4_FLOWCTRL_HARDWARE 1
89 
93 #define UARTMSP432E4_PA0_U0RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 0, GPIO_PA0_U0RX)
94 
98 #define UARTMSP432E4_PA1_U0TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 1, GPIO_PA1_U0TX)
99 
103 #define UARTMSP432E4_PH1_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 1, GPIO_PH1_U0CTS)
104 
108 #define UARTMSP432E4_PM4_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTM, 4, GPIO_PM4_U0CTS)
109 
113 #define UARTMSP432E4_PB4_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 4, GPIO_PB4_U0CTS)
114 
118 #define UARTMSP432E4_PE6_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 6, GPIO_PE6_U0CTS)
119 
123 #define UARTMSP432E4_PG4_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 4, GPIO_PG4_U0CTS)
124 
128 #define UARTMSP432E4_PH0_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 0, GPIO_PH0_U0RTS)
129 
133 #define UARTMSP432E4_PB5_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 5, GPIO_PB5_U0RTS)
134 
138 #define UARTMSP432E4_PE7_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 7, GPIO_PE7_U0RTS)
139 
143 #define UARTMSP432E4_PG5_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 5, GPIO_PG5_U0RTS)
144 
145 
149 #define UARTMSP432E4_PB0_U1RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 0, GPIO_PB0_U1RX)
150 
154 #define UARTMSP432E4_PQ4_U1RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 4, GPIO_PQ4_U1RX)
155 
159 #define UARTMSP432E4_PR5_U1RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 5, GPIO_PR5_U1RX)
160 
164 #define UARTMSP432E4_PB1_U1TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 1, GPIO_PB1_U1TX)
165 
169 #define UARTMSP432E4_PQ5_U1TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 5, GPIO_PQ5_U1TX)
170 
174 #define UARTMSP432E4_PR6_U1TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 6, GPIO_PR6_U1TX)
175 
179 #define UARTMSP432E4_PP3_U1CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 3, GPIO_PP3_U1CTS)
180 
184 #define UARTMSP432E4_PN1_U1CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 1, GPIO_PN1_U1CTS)
185 
189 #define UARTMSP432E4_PE0_U1RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 0, GPIO_PE0_U1RTS)
190 
194 #define UARTMSP432E4_PN0_U1RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 0, GPIO_PN0_U1RTS)
195 
199 #define UARTMSP432E4_PN7_U1RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 7, GPIO_PN7_U1RTS)
200 
201 
205 #define UARTMSP432E4_PA6_U2RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 6, GPIO_PA6_U2RX)
206 
210 #define UARTMSP432E4_PD4_U2RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 4, GPIO_PD4_U2RX)
211 
215 #define UARTMSP432E4_PA7_U2TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 7, GPIO_PA7_U2TX)
216 
220 #define UARTMSP432E4_PD5_U2TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 5, GPIO_PD5_U2TX)
221 
225 #define UARTMSP432E4_PN3_U2CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 3, GPIO_PN3_U2CTS)
226 
230 #define UARTMSP432E4_PD7_U2CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 7, GPIO_PD7_U2CTS)
231 
235 #define UARTMSP432E4_PJ3_U2CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 3, GPIO_PJ3_U2CTS)
236 
240 #define UARTMSP432E4_PN2_U2RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 2, GPIO_PN2_U2RTS)
241 
245 #define UARTMSP432E4_PD6_U2RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 6, GPIO_PD6_U2RTS)
246 
250 #define UARTMSP432E4_PJ2_U2RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 2, GPIO_PJ2_U2RTS)
251 
252 
256 #define UARTMSP432E4_PA4_U3RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 4, GPIO_PA4_U3RX)
257 
261 #define UARTMSP432E4_PJ0_U3RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 0, GPIO_PJ0_U3RX)
262 
266 #define UARTMSP432E4_PA5_U3TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 5, GPIO_PA5_U3TX)
267 
271 #define UARTMSP432E4_PJ1_U3TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 1, GPIO_PJ1_U3TX)
272 
276 #define UARTMSP432E4_PP5_U3CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 5, GPIO_PP5_U3CTS)
277 
281 #define UARTMSP432E4_PN5_U3CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 5, GPIO_PN5_U3CTS)
282 
286 #define UARTMSP432E4_PJ5_U3CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 5, GPIO_PJ5_U3CTS)
287 
291 #define UARTMSP432E4_PP4_U3RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 4, GPIO_PP4_U3RTS)
292 
296 #define UARTMSP432E4_PN4_U3RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 4, GPIO_PN4_U3RTS)
297 
301 #define UARTMSP432E4_PJ4_U3RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 4, GPIO_PJ4_U3RTS)
302 
303 
307 #define UARTMSP432E4_PA2_U4RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 2, GPIO_PA2_U4RX)
308 
312 #define UARTMSP432E4_PK0_U4RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 0, GPIO_PK0_U4RX)
313 
317 #define UARTMSP432E4_PR1_U4RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 1, GPIO_PR1_U4RX)
318 
322 #define UARTMSP432E4_PA3_U4TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 3, GPIO_PA3_U4TX)
323 
327 #define UARTMSP432E4_PK1_U4TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 1, GPIO_PK1_U4TX)
328 
332 #define UARTMSP432E4_PR0_U4TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 0, GPIO_PR0_U4TX)
333 
337 #define UARTMSP432E4_PK3_U4CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 3, GPIO_PK3_U4CTS)
338 
342 #define UARTMSP432E4_PJ7_U4CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 7, GPIO_PJ7_U4CTS)
343 
347 #define UARTMSP432E4_PN7_U4CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 7, GPIO_PN7_U4CTS)
348 
352 #define UARTMSP432E4_PK2_U4RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 2, GPIO_PK2_U4RTS)
353 
357 #define UARTMSP432E4_PJ6_U4RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 6, GPIO_PJ6_U4RTS)
358 
362 #define UARTMSP432E4_PN6_U4RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 6, GPIO_PN6_U4RTS)
363 
364 
368 #define UARTMSP432E4_PC6_U5RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 6, GPIO_PC6_U5RX)
369 
373 #define UARTMSP432E4_PH6_U5RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 6, GPIO_PH6_U5RX)
374 
378 #define UARTMSP432E4_PC7_U5TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 7, GPIO_PC7_U5TX)
379 
383 #define UARTMSP432E4_PH7_U5TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 7, GPIO_PH7_U5TX)
384 
385 
389 #define UARTMSP432E4_PP0_U6RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 0, GPIO_PP0_U6RX)
390 
394 #define UARTMSP432E4_PP1_U6TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 1, GPIO_PP1_U6TX)
395 
396 
400 #define UARTMSP432E4_PC4_U7RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 4, GPIO_PC4_U7RX)
401 
405 #define UARTMSP432E4_PH6_U7RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 6, GPIO_PH6_U7RX)
406 
410 #define UARTMSP432E4_PC5_U7TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 5, GPIO_PC5_U7TX)
411 
415 #define UARTMSP432E4_PH7_U7TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 7, GPIO_PH7_U7TX)
416 
417 /* UART function table pointer */
419 
432 typedef void (*UARTMSP432E4_ErrorCallback) (UART_Handle handle,
433  uint32_t error);
434 
456 typedef struct {
457  bool (*readIsrFxn) (UART_Handle handle);
458  int (*readTaskFxn) (UART_Handle handle);
460 
516 typedef struct {
518  uint32_t baseAddr;
520  uint32_t intNum;
522  uint32_t intPriority;
524  uint32_t flowControl;
526  unsigned char *ringBufPtr;
528  size_t ringBufSize;
530  uint32_t rxPin;
532  uint32_t txPin;
534  uint32_t ctsPin;
536  uint32_t rtsPin;
540 
546 typedef struct {
547  /* UART state variable */
548  struct {
549  bool opened:1; /* Has the obj been opened */
550  UART_Mode readMode:1; /* Mode for all read calls */
551  UART_Mode writeMode:1; /* Mode for all write calls */
552  UART_DataMode readDataMode:1; /* Type of data being read */
553  UART_DataMode writeDataMode:1; /* Type of data being written */
554  UART_ReturnMode readReturnMode:1; /* Receive return mode */
555  UART_Echo readEcho:1; /* Echo received data back */
556  /*
557  * Flag to determine if a timeout has occurred when the user called
558  * UART_read(). This flag is set by the timeoutClk clock object.
559  */
560  bool bufTimeout:1;
561  /*
562  * Flag to determine when an ISR needs to perform a callback; in both
563  * UART_MODE_BLOCKING or UART_MODE_CALLBACK
564  */
565  bool callCallback:1;
566  /*
567  * Flag to determine if the ISR is in control draining the ring buffer
568  * when in UART_MODE_CALLBACK
569  */
570  bool drainByISR:1;
571  /* Flag to keep the state of the read ring buffer */
572  bool rxEnabled:1;
573 
574  /* Flags to prevent recursion in read callback mode */
575  bool inReadCallback:1;
576  volatile bool readCallbackPending:1;
577  } state;
578 
579  ClockP_Handle timeoutClk; /* Clock object for timeouts */
580  uint32_t baudRate; /* Baud rate for UART */
581  UART_LEN dataLength; /* Data length for UART */
582  UART_STOP stopBits; /* Stop bits for UART */
583  UART_PAR parityType; /* Parity bit type for UART */
584 
585  /* UART read variables */
586  RingBuf_Object ringBuffer; /* local circular buffer object */
587  /* A complement pair of read functions for both the ISR and UART_read() */
589  unsigned char *readBuf; /* Buffer data pointer */
590  size_t readSize; /* Desired number of bytes to read */
591  size_t readCount; /* Number of bytes left to read */
592  SemaphoreP_Handle readSem; /* UART read semaphore */
593  unsigned int readTimeout; /* Timeout for read semaphore */
594  UART_Callback readCallback; /* Pointer to read callback */
595 
596  /* UART write variables */
597  const unsigned char *writeBuf; /* Buffer data pointer */
598  size_t writeSize; /* Desired number of bytes to write*/
599  size_t writeCount; /* Number of bytes left to write */
600  SemaphoreP_Handle writeSem; /* UART write semaphore*/
601  unsigned int writeTimeout; /* Timeout for write semaphore */
602  UART_Callback writeCallback; /* Pointer to write callback */
603 
604  HwiP_Handle hwi; /* Hwi object */
606 
607 #ifdef __cplusplus
608 }
609 #endif
610 
611 #endif /* ti_drivers_uart_UARTMSP432E4__include */
UART_Callback readCallback
Definition: UARTMSP432E4.h:594
void(* UARTMSP432E4_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: UARTMSP432E4.h:432
UART_STOP
UART stop bit settings.
Definition: UART.h:523
uint32_t txPin
Definition: UARTMSP432E4.h:532
size_t readSize
Definition: UARTMSP432E4.h:590
RingBuf_Object ringBuffer
Definition: UARTMSP432E4.h:586
uint32_t intNum
Definition: UARTMSP432E4.h:520
UARTMSP432E4 Hardware attributes.
Definition: UARTMSP432E4.h:516
uint32_t rtsPin
Definition: UARTMSP432E4.h:536
uint32_t flowControl
Definition: UARTMSP432E4.h:524
The definition of a UART function table that contains the required set of functions to control a spec...
Definition: UART.h:635
HwiP_Handle hwi
Definition: UARTMSP432E4.h:604
UARTMSP432E4 Object.
Definition: UARTMSP432E4.h:546
UART_PAR
UART parity type settings.
Definition: UART.h:533
UART_Mode
UART mode settings.
Definition: UART.h:428
uint32_t ctsPin
Definition: UARTMSP432E4.h:534
unsigned int readTimeout
Definition: UARTMSP432E4.h:593
UART_DataMode
UART data mode settings.
Definition: UART.h:483
UART_ReturnMode
UART return mode settings.
Definition: UART.h:461
UART_Echo
UART echo settings.
Definition: UART.h:501
UART Global configuration.
Definition: UART.h:678
UART_LEN dataLength
Definition: UARTMSP432E4.h:581
size_t writeCount
Definition: UARTMSP432E4.h:599
unsigned char * ringBufPtr
Definition: UARTMSP432E4.h:526
const unsigned char * writeBuf
Definition: UARTMSP432E4.h:597
UART_STOP stopBits
Definition: UARTMSP432E4.h:582
UARTMSP432E4_FxnSet readFxns
Definition: UARTMSP432E4.h:588
UART_Callback writeCallback
Definition: UARTMSP432E4.h:602
struct UARTMSP432E4_Object * UARTMSP432E4_Handle
size_t writeSize
Definition: UARTMSP432E4.h:598
SemaphoreP_Handle writeSem
Definition: UARTMSP432E4.h:600
size_t readCount
Definition: UARTMSP432E4.h:591
UARTMSP432E4_ErrorCallback errorFxn
Definition: UARTMSP432E4.h:538
Universal Asynchronous Receiver-Transmitter (UART) Driver.
MSP432E4 GPIO driver.
UART_PAR parityType
Definition: UARTMSP432E4.h:583
uint32_t baseAddr
Definition: UARTMSP432E4.h:518
ClockP_Handle timeoutClk
Definition: UARTMSP432E4.h:579
Definition: RingBuf.h:44
UART_LEN
UART data length settings.
Definition: UART.h:511
const UART_FxnTable UARTMSP432E4_fxnTable
SemaphoreP_Handle readSem
Definition: UARTMSP432E4.h:592
uint32_t baudRate
Definition: UARTMSP432E4.h:580
uint32_t rxPin
Definition: UARTMSP432E4.h:530
size_t ringBufSize
Definition: UARTMSP432E4.h:528
unsigned char * readBuf
Definition: UARTMSP432E4.h:589
uint32_t intPriority
Definition: UARTMSP432E4.h:522
unsigned int writeTimeout
Definition: UARTMSP432E4.h:601
Complement set of read functions to be used by the UART ISR and UARTMSP432E4_read(). Internal use only.
Definition: UARTMSP432E4.h:456
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
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale