Data Structures | Macros | Typedefs | Enumerations | Variables
UARTCC26X2.h File Reference

Detailed Description

UART driver implementation for a CC26X2 UART controller.

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

Driver include

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

Refer to UART.h for a complete description of APIs.

Overview

The general UART API should used in application code, i.e. UART_open() is used instead of UARTCC26X2_open(). The board file will define the device specific config, and casting in the general API will ensure that the correct device specific functions are called. This is also reflected in the example code in Use Cases. This driver supports polling modes for UART_read() and UART_write(). Text mode (e.g., UART_read() returns on receiving a newline character) is also supported by this driver. If polling mode and text mode are not needed, the UARTCC26XX driver can be used instead, which will reduce code size.

General Behavior

Before using the UART in CC26X2:

The following is true for receive operation:

The following apply for transmit operation:

If UART is no longer needed by application:

If the UART is configured in UART_MODE_CALLBACK mode:

Error handling

Read errors

If an error occurs during read operation:

General timeout

A timeout value can only be specified for reads and writes in UART_MODE_BLOCKING. If a timeout occurs during a read when in UART_MODE_BLOCKING, the number of bytes received will be returned. After a read timeout, RX will be turned off and the device allowed to enter standby. For more details see Power Management chapter below.

In UART_MODE_CALLBACK there is no timeout and the application must call UART_readCancel() or UART_writeCancel() to abort the operation.

Closing driver during an ongoing read/write

It's safe to call UART_close() during an ongoing UART_read() and/or UART_write(), this will cancel the ongoing RX/TX immediately.

The RX callback is alwyas called when you call UART_close() if there's an ongoing read. Note that if UART_close() is called during an ongoing read, the size provided in the RX callback function is 0 if < 16 bytes were received before calling UART_close(). This is because 16 bytes is the RX watermark that triggers the ISR to copy bytes from the internal UART FIFO to the software RX buffer.

The TX callback is always called when you call UART_close() if there's an ongoing write. The driver does not wait until a byte is transmitted correctly, so if UART_close() is called in the middle of sending a byte, this byte will be corrupted.

Power Management

The TI-RTOS power management framework will try to put the device into the most power efficient mode whenever possible. Please see the technical reference manual for further details on each power mode.

The UARTCC26X2 driver sets a power constraint during operation to keep the device out of standby. When the operation has finished, the power constraint is released. The following statements are valid:

Flow Control

To enable Flow Control, the RTS and CTS pins must be assigned in the UARTCC26X2_HWAttrs and flowControl must be set to UARTCC26X2_FLOWCTRL_HARDWARE:

const UARTCC26X2_HWAttrs uartCC26X2HWAttrs[] = {
{
.baseAddr = UART0_BASE,
.powerMngrId = PERIPH_UART0,
.intNum = INT_UART0,
.intPriority = ~0,
.swiPriority = 0,
.txPin = CONFIG_UART_TX,
.rxPin = CONFIG_UART_RX,
.ctsPin = CONFIG_UART_CTS,
.rtsPin = CONFIG_UART_RTS
.ringBufPtr = uartCC26X2RingBuffer[0],
.ringBufSize = sizeof(uartCC26X2RingBuffer[0]),
}
};

If the RTS and CTS pins are set to PIN_UNASSIGNED, or flowControl is set to UARTCC26X2_FLOWCONTROL_NONE, the flow control is disabled. An example is shown in the UARTCC26X2_HWAttrs description.

Supported Functions

Generic API function API function Description
UART_init() UARTCC26X2_init() Initialize UART driver
UART_open() UARTCC26X2_open() Initialize UART HW and set system dependencies
UART_close() UARTCC26X2_close() Disable UART HW and release system dependencies
UART_control() UARTCC26X2_control() Configure an already opened UART handle
UART_read() UARTCC26X2_read() Start read from UART
UART_readCancel() UARTCC26X2_readCancel() Cancel ongoing read from UART
UART_readPolling() UARTCC26X2_readPolling() Polling read from UART
UART_write() UARTCC26X2_write() Start write to UART
UART_writeCancel() UARTCC26X2_writeCancel() Cancel ongoing write to UART
UART_writePolling() UARTCC26X2_writePolling()Polling write to UART
Note
All calls should go through the generic API

Use Cases

Basic Receive

Receive 100 bytes over UART in UART_MODE_BLOCKING.

UART_Handle handle;
uint8_t rxBuf[100]; // Receive buffer
uint32_t timeoutUs = 5000; // 5ms timeout, default timeout is no timeout (BIOS_WAIT_FOREVER)
// Init UART and specify non-default parameters
params.baudRate = 9600;
params.readTimeout = timeoutUs / ClockP_getSystemTickPeriod(); // Default tick period is 10us
// Open the UART and do the read
handle = UART_open(CONFIG_UART, &params);
int rxBytes = UART_read(handle, rxBuf, 100);

Receive with Return Partial

This use case will read in UART_MODE_BLOCKING until the wanted amount of bytes is received or until a started reception is inactive for a 32-bit period. This UART_read() call can also be used when unknown amount of bytes shall be read. Note: The partial return is also possible in UART_MODE_CALLBACK mode.

UART_Handle handle;
uint8_t rxBuf[100]; // Receive buffer
// Init UART and specify non-default parameters
params.baudRate = 9600;
// Open the UART and initiate the partial read
handle = UART_open(CONFIG_UART, &params);
// Enable RETURN_PARTIAL
// Begin read
int rxBytes = UART_read(handle, rxBuf, 100));

Basic Transmit

This case will configure the UART to send the data in txBuf in BLOCKING_MODE.

UART_Handle handle;
uint8_t txBuf[] = "Hello World"; // Transmit buffer
// Init UART and specify non-default parameters
params.baudRate = 9600;
// Open the UART and do the write
handle = UART_open(CONFIG_UART, &params);
UART_write(handle, txBuf, sizeof(txBuf));

Receive Continously in UART_MODE_CALLBACK

This case will configure the UART to receive and transmit continously in UART_MODE_CALLBACK, and transmit them back via UART TX. Note that UART_Params.readTimeout is not in use when using UART_MODE_CALLBACK mode.

#define MAX_NUM_RX_BYTES 1000 // Maximum RX bytes to receive in one go
#define MAX_NUM_TX_BYTES 1000 // Maximum TX bytes to send in one go
uint32_t wantedRxBytes; // Number of bytes received so far
uint8_t rxBuf[MAX_NUM_RX_BYTES]; // Receive buffer
uint8_t txBuf[MAX_NUM_TX_BYTES]; // Transmit buffer
// Read callback function
static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
// Make sure we received all expected bytes
if (size == wantedRxBytes) {
// Copy bytes from RX buffer to TX buffer
for (size_t i = 0; i < size; i++)
txBuf[i] = ((uint8_t*)rxBuf)[i];
// Echo the bytes received back to transmitter
UART_write(handle, txBuf, size);
// Start another read, with size the same as it was during first call to
// UART_read()
UART_read(handle, rxBuf, wantedRxBytes);
}
else {
// Handle error or call to UART_readCancel()
}
}
// Write callback function
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
// Do nothing
}
static void taskFxn(uintptr_t a0, uintptr_t a1)
{
UART_Handle handle;
// Init UART
// Specify non-default parameters
UART_Params_init(&params);
params.baudRate = 9600;
params.writeCallback = writeCallback;
params.readCallback = readCallback;
// Open the UART and initiate the first read
handle = UART_open(CONFIG_UART, &params);
wantedRxBytes = 16;
int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
while(true); // Wait forever
}

Baud Rate

The CC26xx driver supports baud rates up to 3Mbaud. However, when receiving more than 32 bytes back-to-back the baud rate is limited to approximately 2Mbaud. The throughput is also dependent on the user application.

Stack requirements

There are no additional stack requirements for calling UART_read() within its own callback.


#include <stdint.h>
#include <stdbool.h>
#include <ti/drivers/dpl/ClockP.h>
#include <ti/drivers/dpl/HwiP.h>
#include <ti/drivers/dpl/SemaphoreP.h>
#include <ti/drivers/dpl/SwiP.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <ti/drivers/utils/RingBuf.h>
Include dependency graph for UARTCC26X2.h:

Go to the source code of this file.

Data Structures

struct  UARTCC26X2_HWAttrs
 UARTCC26X2 Hardware attributes. More...
 
struct  UARTCC26X2_Object
 UARTCC26X2 Object. More...
 

Macros

#define UARTCC26X2_FLOWCTRL_NONE   0
 No hardware flow control. More...
 
#define UARTCC26X2_FLOWCTRL_HARDWARE   1
 Hardware flow control. More...
 
#define UARTCC26X2_CMD_RETURN_PARTIAL_ENABLE   (UART_CMD_RESERVED + 0)
 Command used by UART_control to enable partial return. More...
 
#define UARTCC26X2_CMD_RETURN_PARTIAL_DISABLE   (UART_CMD_RESERVED + 1)
 Command used by UART_control to disable partial return. More...
 
#define UARTCC26X2_CMD_RX_FIFO_FLUSH   (UART_CMD_RESERVED + 2)
 Command used by UART_control to flush the RX FIFO. More...
 
#define UARTCC26X2_FIFO_SIZE   32
 

Typedefs

typedef void(* UARTCC26X2_ErrorCallback) (UART_Handle handle, uint32_t error)
 The definition of an optional callback function used by the UART driver to notify the application when a receive error (FIFO overrun, parity error, etc) occurs. More...
 
typedef struct UARTCC26X2_ObjectUARTCC26X2_Handle
 

Enumerations

enum  UARTCC26X2_FifoThreshold {
  UARTCC26X2_FIFO_THRESHOLD_DEFAULT = 0, UARTCC26X2_FIFO_THRESHOLD_1_8, UARTCC26X2_FIFO_THRESHOLD_2_8, UARTCC26X2_FIFO_THRESHOLD_4_8,
  UARTCC26X2_FIFO_THRESHOLD_6_8, UARTCC26X2_FIFO_THRESHOLD_7_8
}
 UART TX/RX interrupt FIFO threshold select. More...
 

Variables

const UART_FxnTable UARTCC26X2_fxnTable
 

Macro Definition Documentation

§ UARTCC26X2_FLOWCTRL_NONE

#define UARTCC26X2_FLOWCTRL_NONE   0

No hardware flow control.

§ UARTCC26X2_FLOWCTRL_HARDWARE

#define UARTCC26X2_FLOWCTRL_HARDWARE   1

Hardware flow control.

§ UARTCC26X2_FIFO_SIZE

#define UARTCC26X2_FIFO_SIZE   32

Size of the TX and RX FIFOs is 32 items

Typedef Documentation

§ UARTCC26X2_ErrorCallback

typedef void(* UARTCC26X2_ErrorCallback) (UART_Handle handle, uint32_t error)

The definition of an optional callback function used by the UART driver to notify the application when a receive error (FIFO overrun, parity error, etc) occurs.

Parameters
UART_HandleUART_Handle
errorThe current value of the receive status register.

§ UARTCC26X2_Handle

Enumeration Type Documentation

§ UARTCC26X2_FifoThreshold

UART TX/RX interrupt FIFO threshold select.

Defined FIFO thresholds for generation of both TX interrupt and RX interrupt. The default value (UARTCC26X2_FIFO_THRESHOLD_DEFAULT) is defined for backwards compatibility handling. If the RX and TX FIFO & thresholds are not set in the HwAttrs, or are set to UARTCC26X2_FIFO_THRESHOLD_DEFAULT, the RX interrupt FIFO threshold is set to 4/8 full, and the TX interrupt FIFO threshold is set to 1/8 full.

Enumerator
UARTCC26X2_FIFO_THRESHOLD_DEFAULT 

Use default FIFO threshold

UARTCC26X2_FIFO_THRESHOLD_1_8 

FIFO threshold of 1/8 full

UARTCC26X2_FIFO_THRESHOLD_2_8 

FIFO threshold of 2/8 full

UARTCC26X2_FIFO_THRESHOLD_4_8 

FIFO threshold of 4/8 full

UARTCC26X2_FIFO_THRESHOLD_6_8 

FIFO threshold of 6/8 full

UARTCC26X2_FIFO_THRESHOLD_7_8 

FIFO threshold of 7/8 full

Variable Documentation

§ UARTCC26X2_fxnTable

const UART_FxnTable UARTCC26X2_fxnTable
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale