TI-RTOS Drivers  tidrivers_full_2_20_00_08
Data Structures | Typedefs | Variables
UARTMSP432.h File Reference

Detailed Description

UART driver implementation for a EUSCIA peripheral for MSP432.

============================================================================

The UART header file should be included in an application as follows:

Refer to UART.h for a complete description of APIs & example of use.

Stack requirements

The UARTMSP432 driver is (ring) buffered driver where it stores data it may already received in a user-supplied background buffer.

See also
UARTMSP432_HWAttrs

While permitted, it is STRONGLY suggested to avoid implementations where you call UART_read() within it own callback function (when in UART_MODE_CALLBACK).

Doing so, will require additional (task and system) stack for each nested UART_read() call.

Tool chain Number of bytes per nested UART_read() call
GNU 96 bytes + callback function stack requirements
IAR 40 bytes + callback function stack requirements
TI 80 bytes + callback function stack requirements

It is important to note a potential worst case scenario: A full ring buffer with data; say 32 bytes The callback function calls UART_read() with a size of 1 (byte) No other variables are allocated in the callback function No other function calls are made in the callback function

As a result, you need an additional task and system stack of: 32 bytes * (80 bytes for TI + 0 bytes by the callback function) = 2.5kB

This UART driver implementation is designed to operate on a EUSCI controller in UART mode for MSP432 devices.


#include <stdint.h>
#include <stdbool.h>
#include <ti/drivers/ports/ClockP.h>
#include <ti/drivers/ports/HwiP.h>
#include <ti/drivers/ports/SemaphoreP.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/utils/RingBuf.h>
Include dependency graph for UARTMSP432.h:

Go to the source code of this file.

Data Structures

struct  UARTMSP432_FxnSet
 Complement set of read functions to be used by the UART ISR and UARTMSP432_read(). Internal use only. More...
 
struct  UARTMSP432_BaudrateConfig
 UARTMSP432 Baudrate configuration. More...
 
struct  UARTMSP432_HWAttrs
 UARTMSP432 Hardware attributes. More...
 
struct  UARTMSP432_Object
 UARTMSP432 Object. More...
 

Typedefs

typedef struct UARTMSP432_FxnSet UARTMSP432_FxnSet
 Complement set of read functions to be used by the UART ISR and UARTMSP432_read(). Internal use only. More...
 
typedef struct UARTMSP432_BaudrateConfig UARTMSP432_BaudrateConfig
 UARTMSP432 Baudrate configuration. More...
 
typedef struct UARTMSP432_HWAttrs UARTMSP432_HWAttrs
 UARTMSP432 Hardware attributes. More...
 
typedef struct UARTMSP432_Object UARTMSP432_Object
 UARTMSP432 Object. More...
 
typedef struct UARTMSP432_ObjectUARTMSP432_Handle
 

Variables

const UART_FxnTable UARTMSP432_fxnTable
 

Typedef Documentation

Complement set of read functions to be used by the UART ISR and UARTMSP432_read(). Internal use only.

These functions should not be used by the user and are solely intended for the UARTMSP432 driver. The UARTMSP432_FxnSet is a pair of complement functions that are design to operate with one another in a task context and in an ISR context. The readTaskFxn is called by UARTMSP432_read() to drain a circular buffer, whereas the readIsrFxn is used by the UARTMSP432_hwiIntFxn to fill up the circular buffer.

readTaskFxn: Function called by UART read These variables are set and available for use to the readTaskFxn. object->readBuf = buffer; //Pointer to a user buffer object->readSize = size; //Desired no. of bytes to read object->readCount = size; //Remaining no. of bytes to read

readIsrFxn: The required ISR counterpart to readTaskFxn

UARTMSP432 Baudrate configuration.

This structure is used to specifiy the EUSCI controller's clock divider settings to achieve the desired baudrate given the a clock input frequency. Divider values can be determined by referring to the MSP430 baudrate calculator. https://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html

A sample structure is shown below:

1 const UARTMSP432_BaudrateConfig uartBaudrates[] = {
2  // {baudrate, input clock, prescalar, UCBRFx, UCBRSx, oversampling}
3  {
4  .outputBaudrate = 115200,
5  .inputClockFreq = 12000000,
6  .prescalar = 6,
7  .hwRegUCBRFx = 8,
8  .hwRegUCBRSx = 32,
9  .oversampling = 1
10  },
11  {115200, 6000000, 3, 4, 2, 1},
12  {115200, 3000000, 1, 10, 0, 1},
13  {9600, 12000000, 78, 2, 0, 1},
14  {9600, 6000000, 39, 1, 0, 1},
15  {9600, 3000000, 19, 8, 85, 1},
16  {9600, 32768, 3, 0, 146, 0}
17 };

UARTMSP432 Hardware attributes.

These fields are used by driverlib APIs and therefore must be populated by driverlib macro definitions. For MSP432Ware these definitions are found in:

  • uart.h

intPriority is the UART peripheral's interrupt priority, as defined by the underlying OS. It is passed unmodified to the underlying OS's interrupt handler creation code, so you need to refer to the OS documentation for usage. For example, for SYS/BIOS applications, refer to the ti.sysbios.family.arm.m3.Hwi documentation for SYS/BIOS usage of interrupt priorities. If the driver uses the ti.drivers.ports interface instead of making OS calls directly, then the HwiP port handles the interrupt priority in an OS specific way. In the case of the SYS/BIOS port, intPriority is passed unmodified to Hwi_create().

A sample structure is shown below:

1 unsigned char uartMSP432RingBuffer[2][32];
2 
3 const UARTMSP432_HWAttrs uartMSP432HWAttrs[MSP_EXP432P401R_UARTCOUNT] = {
4  {
5  .baseAddr = EUSCI_A0_BASE,
6  .intNum = INT_EUSCIA0,
7  .intPriority = (~0),
8  .clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
9  .bitOrder = EUSCI_A_UART_LSB_FIRST,
10  .numBaudrateEntries = sizeof(uartMSP432Baudrates) /
11  sizeof(UARTMSP432_BaudrateConfig),
12  .baudrateLUT = uartMSP432Baudrates,
13  .ringBufPtr = uartMSP432RingBuffer[0],
14  .ringBufSize = sizeof(uartMSP432RingBuffer[0])
15  },
16  {
17  .baseAddr = EUSCI_A2_BASE,
18  .intNum = INT_EUSCIA2,
19  .intPriority = (~0),
20  .clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
21  .bitOrder = EUSCI_A_UART_LSB_FIRST,
22  .numBaudrateEntries = sizeof(uartMSP432Baudrates) /
23  sizeof(UARTMSP432_BaudrateConfig),
24  .baudrateLUT = uartMSP432Baudrates
25  .ringBufPtr = uartMSP432RingBuffer[1],
26  .ringBufSize = sizeof(uartMSP432RingBuffer[1])
27  }
28 };

UARTMSP432 Object.

The application must not access any member variables of this structure!

Variable Documentation

const UART_FxnTable UARTMSP432_fxnTable
Copyright 2016, Texas Instruments Incorporated