UARTMSP432E4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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  */
75 #ifndef ti_drivers_uart_UARTMSP432E4__include
76 #define ti_drivers_uart_UARTMSP432E4__include
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 #include <stdbool.h>
83 #include <stddef.h>
84 #include <stdint.h>
85 
86 #include <ti/devices/msp432e4/inc/msp432.h>
87 
88 #include <ti/devices/msp432e4/driverlib/gpio.h>
89 #include <ti/devices/msp432e4/driverlib/pin_map.h>
90 
91 #include <ti/drivers/dpl/ClockP.h>
92 #include <ti/drivers/dpl/HwiP.h>
93 #include <ti/drivers/dpl/SemaphoreP.h>
94 
96 #include <ti/drivers/UART.h>
98 
105 #define UARTMSP432E4_PIN_UNASSIGNED 0xFFFFFFFF
106 
110 #define UARTMSP432E4_FLOWCTRL_NONE 0
111 
115 #define UARTMSP432E4_FLOWCTRL_HARDWARE 1
116 
120 #define UARTMSP432E4_PA0_U0RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 0, GPIO_PA0_U0RX)
121 
125 #define UARTMSP432E4_PA1_U0TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 1, GPIO_PA1_U0TX)
126 
130 #define UARTMSP432E4_PH1_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 1, GPIO_PH1_U0CTS)
131 
135 #define UARTMSP432E4_PM4_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTM, 4, GPIO_PM4_U0CTS)
136 
140 #define UARTMSP432E4_PB4_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 4, GPIO_PB4_U0CTS)
141 
145 #define UARTMSP432E4_PE6_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 6, GPIO_PE6_U0CTS)
146 
150 #define UARTMSP432E4_PG4_U0CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 4, GPIO_PG4_U0CTS)
151 
155 #define UARTMSP432E4_PH0_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 0, GPIO_PH0_U0RTS)
156 
160 #define UARTMSP432E4_PB5_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 5, GPIO_PB5_U0RTS)
161 
165 #define UARTMSP432E4_PE7_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 7, GPIO_PE7_U0RTS)
166 
170 #define UARTMSP432E4_PG5_U0RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 5, GPIO_PG5_U0RTS)
171 
172 
176 #define UARTMSP432E4_PB0_U1RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 0, GPIO_PB0_U1RX)
177 
181 #define UARTMSP432E4_PQ4_U1RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 4, GPIO_PQ4_U1RX)
182 
186 #define UARTMSP432E4_PR5_U1RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 5, GPIO_PR5_U1RX)
187 
191 #define UARTMSP432E4_PB1_U1TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 1, GPIO_PB1_U1TX)
192 
196 #define UARTMSP432E4_PQ5_U1TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 5, GPIO_PQ5_U1TX)
197 
201 #define UARTMSP432E4_PR6_U1TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 6, GPIO_PR6_U1TX)
202 
206 #define UARTMSP432E4_PP3_U1CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 3, GPIO_PP3_U1CTS)
207 
211 #define UARTMSP432E4_PN1_U1CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 1, GPIO_PN1_U1CTS)
212 
216 #define UARTMSP432E4_PE0_U1RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 0, GPIO_PE0_U1RTS)
217 
221 #define UARTMSP432E4_PN0_U1RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 0, GPIO_PN0_U1RTS)
222 
226 #define UARTMSP432E4_PN7_U1RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 7, GPIO_PN7_U1RTS)
227 
228 
232 #define UARTMSP432E4_PA6_U2RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 6, GPIO_PA6_U2RX)
233 
237 #define UARTMSP432E4_PD4_U2RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 4, GPIO_PD4_U2RX)
238 
242 #define UARTMSP432E4_PA7_U2TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 7, GPIO_PA7_U2TX)
243 
247 #define UARTMSP432E4_PD5_U2TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 5, GPIO_PD5_U2TX)
248 
252 #define UARTMSP432E4_PN3_U2CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 3, GPIO_PN3_U2CTS)
253 
257 #define UARTMSP432E4_PD7_U2CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 7, GPIO_PD7_U2CTS)
258 
262 #define UARTMSP432E4_PJ3_U2CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 3, GPIO_PJ3_U2CTS)
263 
267 #define UARTMSP432E4_PN2_U2RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 2, GPIO_PN2_U2RTS)
268 
272 #define UARTMSP432E4_PD6_U2RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 6, GPIO_PD6_U2RTS)
273 
277 #define UARTMSP432E4_PJ2_U2RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 2, GPIO_PJ2_U2RTS)
278 
279 
283 #define UARTMSP432E4_PA4_U3RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 4, GPIO_PA4_U3RX)
284 
288 #define UARTMSP432E4_PJ0_U3RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 0, GPIO_PJ0_U3RX)
289 
293 #define UARTMSP432E4_PA5_U3TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 5, GPIO_PA5_U3TX)
294 
298 #define UARTMSP432E4_PJ1_U3TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 1, GPIO_PJ1_U3TX)
299 
303 #define UARTMSP432E4_PP5_U3CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 5, GPIO_PP5_U3CTS)
304 
308 #define UARTMSP432E4_PN5_U3CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 5, GPIO_PN5_U3CTS)
309 
313 #define UARTMSP432E4_PJ5_U3CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 5, GPIO_PJ5_U3CTS)
314 
318 #define UARTMSP432E4_PP4_U3RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 4, GPIO_PP4_U3RTS)
319 
323 #define UARTMSP432E4_PN4_U3RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 4, GPIO_PN4_U3RTS)
324 
328 #define UARTMSP432E4_PJ4_U3RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 4, GPIO_PJ4_U3RTS)
329 
330 
334 #define UARTMSP432E4_PA2_U4RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 2, GPIO_PA2_U4RX)
335 
339 #define UARTMSP432E4_PK0_U4RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 0, GPIO_PK0_U4RX)
340 
344 #define UARTMSP432E4_PR1_U4RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 1, GPIO_PR1_U4RX)
345 
349 #define UARTMSP432E4_PA3_U4TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 3, GPIO_PA3_U4TX)
350 
354 #define UARTMSP432E4_PK1_U4TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 1, GPIO_PK1_U4TX)
355 
359 #define UARTMSP432E4_PR0_U4TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 0, GPIO_PR0_U4TX)
360 
364 #define UARTMSP432E4_PK3_U4CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 3, GPIO_PK3_U4CTS)
365 
369 #define UARTMSP432E4_PJ7_U4CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 7, GPIO_PJ7_U4CTS)
370 
374 #define UARTMSP432E4_PN7_U4CTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 7, GPIO_PN7_U4CTS)
375 
379 #define UARTMSP432E4_PK2_U4RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 2, GPIO_PK2_U4RTS)
380 
384 #define UARTMSP432E4_PJ6_U4RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTJ, 6, GPIO_PJ6_U4RTS)
385 
389 #define UARTMSP432E4_PN6_U4RTS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 6, GPIO_PN6_U4RTS)
390 
391 
395 #define UARTMSP432E4_PC6_U5RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 6, GPIO_PC6_U5RX)
396 
400 #define UARTMSP432E4_PH6_U5RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 6, GPIO_PH6_U5RX)
401 
405 #define UARTMSP432E4_PC7_U5TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 7, GPIO_PC7_U5TX)
406 
410 #define UARTMSP432E4_PH7_U5TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 7, GPIO_PH7_U5TX)
411 
412 
416 #define UARTMSP432E4_PP0_U6RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 0, GPIO_PP0_U6RX)
417 
421 #define UARTMSP432E4_PP1_U6TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 1, GPIO_PP1_U6TX)
422 
423 
427 #define UARTMSP432E4_PC4_U7RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 4, GPIO_PC4_U7RX)
428 
432 #define UARTMSP432E4_PH6_U7RX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 6, GPIO_PH6_U7RX)
433 
437 #define UARTMSP432E4_PC5_U7TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTC, 5, GPIO_PC5_U7TX)
438 
442 #define UARTMSP432E4_PH7_U7TX GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTH, 7, GPIO_PH7_U7TX)
443 
444 /* UART function table pointer */
446 
459 typedef void (*UARTMSP432E4_ErrorCallback) (UART_Handle handle,
460  uint32_t error);
461 
483 typedef struct UARTMSP432E4_FxnSet {
484  bool (*readIsrFxn) (UART_Handle handle);
485  int (*readTaskFxn) (UART_Handle handle);
487 
543 typedef struct UARTMSP432E4_HWAttrs {
545  uint32_t baseAddr;
547  uint32_t intNum;
549  uint32_t intPriority;
551  uint32_t flowControl;
553  unsigned char *ringBufPtr;
555  size_t ringBufSize;
557  uint32_t rxPin;
559  uint32_t txPin;
561  uint32_t ctsPin;
563  uint32_t rtsPin;
567 
573 typedef struct UARTMSP432E4_Object {
574  /* UART state variable */
575  struct {
576  bool opened:1; /* Has the obj been opened */
577  UART_Mode readMode:1; /* Mode for all read calls */
578  UART_Mode writeMode:1; /* Mode for all write calls */
579  UART_DataMode readDataMode:1; /* Type of data being read */
580  UART_DataMode writeDataMode:1; /* Type of data being written */
581  UART_ReturnMode readReturnMode:1; /* Receive return mode */
582  UART_Echo readEcho:1; /* Echo received data back */
583  /*
584  * Flag to determine if a timeout has occurred when the user called
585  * UART_read(). This flag is set by the timeoutClk clock object.
586  */
587  bool bufTimeout:1;
588  /*
589  * Flag to determine when an ISR needs to perform a callback; in both
590  * UART_MODE_BLOCKING or UART_MODE_CALLBACK
591  */
592  bool callCallback:1;
593  /*
594  * Flag to determine if the ISR is in control draining the ring buffer
595  * when in UART_MODE_CALLBACK
596  */
597  bool drainByISR:1;
598  /* Flag to keep the state of the read ring buffer */
599  bool rxEnabled:1;
600  } state;
601 
602  ClockP_Handle timeoutClk; /* Clock object for timeouts */
603  uint32_t baudRate; /* Baud rate for UART */
604  UART_LEN dataLength; /* Data length for UART */
605  UART_STOP stopBits; /* Stop bits for UART */
606  UART_PAR parityType; /* Parity bit type for UART */
607 
608  /* UART read variables */
609  RingBuf_Object ringBuffer; /* local circular buffer object */
610  /* A complement pair of read functions for both the ISR and UART_read() */
612  unsigned char *readBuf; /* Buffer data pointer */
613  size_t readSize; /* Desired number of bytes to read */
614  size_t readCount; /* Number of bytes left to read */
615  SemaphoreP_Handle readSem; /* UART read semaphore */
616  unsigned int readTimeout; /* Timeout for read semaphore */
617  UART_Callback readCallback; /* Pointer to read callback */
618 
619  /* UART write variables */
620  const unsigned char *writeBuf; /* Buffer data pointer */
621  size_t writeSize; /* Desired number of bytes to write*/
622  size_t writeCount; /* Number of bytes left to write */
623  SemaphoreP_Handle writeSem; /* UART write semaphore*/
624  unsigned int writeTimeout; /* Timeout for write semaphore */
625  UART_Callback writeCallback; /* Pointer to write callback */
626 
627  HwiP_Handle hwi; /* Hwi object */
629 
630 #ifdef __cplusplus
631 }
632 #endif
633 
634 #endif /* ti_drivers_uart_UARTMSP432E4__include */
UART_Callback readCallback
Definition: UARTMSP432E4.h:617
struct UARTMSP432E4_Object UARTMSP432E4_Object
UARTMSP432E4 Object.
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:459
enum UART_Echo_ UART_Echo
UART echo settings.
uint32_t txPin
Definition: UARTMSP432E4.h:559
int(* readTaskFxn)(UART_Handle handle)
Definition: UARTMSP432E4.h:485
size_t readSize
Definition: UARTMSP432E4.h:613
RingBuf_Object ringBuffer
Definition: UARTMSP432E4.h:609
uint32_t intNum
Definition: UARTMSP432E4.h:547
UARTMSP432E4 Hardware attributes.
Definition: UARTMSP432E4.h:543
uint32_t rtsPin
Definition: UARTMSP432E4.h:563
uint32_t flowControl
Definition: UARTMSP432E4.h:551
enum UART_PAR_ UART_PAR
UART parity type settings.
HwiP_Handle hwi
Definition: UARTMSP432E4.h:627
UARTMSP432E4 Object.
Definition: UARTMSP432E4.h:573
enum UART_LEN_ UART_LEN
UART data length settings.
enum UART_Mode_ UART_Mode
UART mode settings.
uint32_t ctsPin
Definition: UARTMSP432E4.h:561
unsigned int readTimeout
Definition: UARTMSP432E4.h:616
UART Global configuration.
Definition: UART.h:695
UART_LEN dataLength
Definition: UARTMSP432E4.h:604
size_t writeCount
Definition: UARTMSP432E4.h:622
unsigned char * ringBufPtr
Definition: UARTMSP432E4.h:553
const unsigned char * writeBuf
Definition: UARTMSP432E4.h:620
UART_STOP stopBits
Definition: UARTMSP432E4.h:605
UARTMSP432E4_FxnSet readFxns
Definition: UARTMSP432E4.h:611
UART_Callback writeCallback
Definition: UARTMSP432E4.h:625
The definition of a UART function table that contains the required set of functions to control a spec...
Definition: UART.h:652
size_t writeSize
Definition: UARTMSP432E4.h:621
struct UARTMSP432E4_HWAttrs UARTMSP432E4_HWAttrs
UARTMSP432E4 Hardware attributes.
SemaphoreP_Handle writeSem
Definition: UARTMSP432E4.h:623
size_t readCount
Definition: UARTMSP432E4.h:614
UARTMSP432E4_ErrorCallback errorFxn
Definition: UARTMSP432E4.h:565
UART driver interface.
MSP432E4 GPIO driver.
bool(* readIsrFxn)(UART_Handle handle)
Definition: UARTMSP432E4.h:484
UART_PAR parityType
Definition: UARTMSP432E4.h:606
uint32_t baseAddr
Definition: UARTMSP432E4.h:545
enum UART_STOP_ UART_STOP
UART stop bit settings.
ClockP_Handle timeoutClk
Definition: UARTMSP432E4.h:602
enum UART_ReturnMode_ UART_ReturnMode
UART return mode settings.
Definition: RingBuf.h:44
const UART_FxnTable UARTMSP432E4_fxnTable
SemaphoreP_Handle readSem
Definition: UARTMSP432E4.h:615
uint32_t baudRate
Definition: UARTMSP432E4.h:603
uint32_t rxPin
Definition: UARTMSP432E4.h:557
struct UARTMSP432E4_FxnSet UARTMSP432E4_FxnSet
Complement set of read functions to be used by the UART ISR and UARTMSP432E4_read(). Internal use only.
size_t ringBufSize
Definition: UARTMSP432E4.h:555
unsigned char * readBuf
Definition: UARTMSP432E4.h:612
uint32_t intPriority
Definition: UARTMSP432E4.h:549
unsigned int writeTimeout
Definition: UARTMSP432E4.h:624
Complement set of read functions to be used by the UART ISR and UARTMSP432E4_read(). Internal use only.
Definition: UARTMSP432E4.h:483
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
enum UART_DataMode_ UART_DataMode
UART data mode settings.
struct UARTMSP432E4_Object * UARTMSP432E4_Handle
Copyright 2017, Texas Instruments Incorporated