| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures
LPUART peripheral Driver
Low Power Universal Asynchronous Receiver/Transmitter (LPUART)

The section describes the programming interface of the LPUART Peripheral driver. More...

## Data Structures
struct | lpuart_state_t
| Runtime state of the LPUART driver. More...

## LPUART Driver
status_t | lpuart_init (uint32_t lpuartInstance, const lpuart_user_config_t *lpuartUserConfig, lpuart_state_t *lpuartState)
| Initialize a LPUART instance for operation. More...
status_t | lpuart_send_data (lpuart_state_t *lpuartState, uint8_t *sendBuffer, uint32_t txByteCount, uint32_t timeout)
| Send data out through the LPUART module using a blocking method. More...
status_t | lpuart_send_data_async (lpuart_state_t *lpuartState, uint8_t *sendBuffer, uint32_t txByteCount)
| Send data out through the LPUART module using a non-blocking method. More...
status_t | lpuart_get_transmit_status (lpuart_state_t *lpuartState, uint32_t *bytesTransmitted)
| Returns whether the previous transmit has finished yet. More...
status_t | lpuart_get_receive_status (lpuart_state_t *lpuartState, uint32_t *bytesReceived)
| Returns whether the previous receive has finished yet. More...
void | lpuart_shutdown (lpuart_state_t *lpuartState)
| Shutdown the lpuart by disabling interrupts and transmitter/receiver. More...
status_t | lpuart_receive_data (lpuart_state_t *lpuartState, uint8_t *rxBuffer, uint32_t requestedByteCount, uint32_t timeout)
| Get data from the LPUART module using a blocking method. More...
status_t | lpuart_receive_data_async (lpuart_state_t *lpuartState, uint8_t *rxBuffer, uint32_t requestedByteCount)
| Get data from the LPUART module using a non-blocking method. More...
status_t | lpuart_abort_sending_data (lpuart_state_t *lpuartState)
| Terminates an asynchronous transmission early. More...
status_t | lpuart_abort_receiving_data (lpuart_state_t *lpuartState)
| Terminates an asynchronous receive early. More...

### LPUART Peripheral Driver

# Overview

The LPUART peripheral driver transfers data to and from external devices on the Low Power Universal Asynchronous Receiver/Transmitter (LPUART) serial bus. It provides a way to transmit or receive buffers of data with calls to a single function.

# Device structures

The driver uses instantiations of the lpuart_tx_state_t and the lpuart_rx_state_t structure to maintain the current state of a particular LPUART instance module driver. The caller provides memory for the driver state structures during the initialization as the driver itself does not statically allocate memory. The structures are provided below:
// Runtime transmit state of the LPUART driver.
typedef struct LpuartTxState {
uint32_t instance;
bool isTransmitInProgress;
bool isTransmitAsync;
const uint8_t * sendBuffer;
size_t remainingSendByteCount;
size_t transmittedByteCount;
sync_object_t irqSync;
uint8_t fifoEntryCount;
} lpuart_tx_state_t;
// Runtime receive state of the LPUART driver.
typedef struct LpuartRxState {
uint32_t instance;
bool isReceiveInProgress;
bool isReceiveAsync;
uint8_t * receiveBuffer;
size_t remainingReceiveByteCount;
size_t receivedByteCount;
sync_object_t irqSync;
uint8_t fifoEntryCount;
} lpuart_rx_state_t;

# Initialization

To initialize the LPUART driver, call the lpuart_init() function and pass the instance number of the LPUART peripheral you want to use. For instance, to use LPUART0 pass a value of 0 to the initialization function. In addition, you also have to pass a user configuration structure lpuart_user_config_t shown here:
// LPUART configuration structure for user
typedef struct LpuartUserConfig {
uint32_t baudRate;
lpuart_parity_mode_t parityMode;
lpuart_stop_bit_count_t stopBitCount;
lpuart_bit_count_per_char_t bitCountPerChar;
} lpuart_user_config_t;
Typically the user configures the lpuart_user_config_t instantiation as an 8-bit-char, no-parity, 1-stop-bit (8-n-1) with a baud rate of 9600 bps. The user can easily modify the lpuart_user_config_t instantiation to configure the LPUART peripheral to a different baud rate or character transfer features. This is a code example to set up a user LPUART configuration instantiation:
lpuart_user_config_t lpuartConfig;
lpuartConfig.baudRate = 9600;
lpuartConfig.bitCountPerChar = kLpuart8BitsPerChar;
lpuartConfig.parityMode = kLpuartParityDisabled;
lpuartConfig.stopBitCount = kLpuartOneStopBit;

# Transfers

The driver implements transmit and receive functions to transfer buffers of data. The driver supports two different modes for transferring data: blocking and non-blocking.The blocking transmit and receive functions are the lpuart_send_data() and the lpuart_receive_data().The non-blocking (async) transmit and receive functions are the lpuart_send_data_async() and the lpuart_receive_data_async().In all of these cases, the functions are interrupt driven.

## Data Structure Documentation

struct lpuart_state_t

Note, the caller provides memory for the driver state structures during init as the

driver does not statically allocate memory.

### Data Fields
uint32_t | instance
| LPUART module instance number.
bool | isTransmitInProgress
| True if there is an active transmit. More...
bool | isTransmitAsync
| Whether the transmit is asynchronous. More...
const uint8_t * | sendBuffer
| The buffer of data being sent. More...
size_t | remainingSendByteCount
| The remaining number of bytes to be transmitted. More...
size_t | transmittedByteCount
| Number of bytes transmitted so far. More...
bool | isReceiveInProgress
| True if there is an active receive. More...
bool | isReceiveAsync
| Whether the receive is asynchronous. More...
uint8_t * | receiveBuffer
| The buffer of received data. More...
size_t | remainingReceiveByteCount
| The remaining number of bytes to be received. More...
size_t | receivedByteCount
| Number of bytes received so far. More...
sync_object_t | txIrqSync
| Used to wait for ISR to complete its tx business. More...
sync_object_t | rxIrqSync
| Used to wait for ISR to complete its rx business. More...
uint8_t | txFifoEntryCount
| Number of data word entries in tx FIFO.
uint8_t | rxFifoEntryCount
| Number of data word entries in rx FIFO.

#### Field Documentation

bool lpuart_state_t::isTransmitInProgress

bool lpuart_state_t::isTransmitAsync

const uint8_t* lpuart_state_t::sendBuffer

size_t lpuart_state_t::remainingSendByteCount

size_t lpuart_state_t::transmittedByteCount

bool lpuart_state_t::isReceiveInProgress

bool lpuart_state_t::isReceiveAsync

uint8_t* lpuart_state_t::receiveBuffer

size_t lpuart_state_t::remainingReceiveByteCount

size_t lpuart_state_t::receivedByteCount

sync_object_t lpuart_state_t::txIrqSync

sync_object_t lpuart_state_t::rxIrqSync

## Function Documentation

status_t lpuart_init | ( | uint32_t | lpuartInstance,
|  | const lpuart_user_config_t * | lpuartUserConfig,
|  | lpuart_state_t * | lpuartState
| ) |  |

       The caller provides memory for the driver state structures during init.

Parameters

  lpuartInstance | LPUART instance number
  lpuartUserConfig | user configuration structure of type lpuart_user_config_t
  lpuartState | Pointer to the LPUART driver state structure

Returns
  An error code or kStatus_Success

status_t lpuart_send_data | ( | lpuart_state_t * | lpuartState,
|  | uint8_t * | sendBuffer,
|  | uint32_t | txByteCount,
|  | uint32_t | timeout
| ) |  |

By blocking, this means that the function will not return until the transmit is complete.

Parameters

  lpuartState | Pointer to the LPUART driver state structure
  sendBuffer | source buffer containing 8-bit data chars to send
  txByteCount | the number of bytes to send
  timeout | timeout value for RTOS abstraction sync control

Returns
  An error code or kStatus_Success

status_t lpuart_send_data_async | ( | lpuart_state_t * | lpuartState,
|  | uint8_t * | sendBuffer,
|  | uint32_t | txByteCount
| ) |  |

This allows an async method for transmitting data and when coupled with a non-blocking receive, the LPUART can perform a full duplex operation. By non-blocking, this means that the function will return immediately. The application will have to get the transmit status to see when the transmit is complete.

Parameters

  lpuartState | Pointer to the LPUART driver state structure
  sendBuffer | source buffer containing 8-bit data chars to send
  txByteCount | the number of bytes to send

Returns
  An error code or kStatus_Success

status_t lpuart_get_transmit_status | ( | lpuart_state_t * | lpuartState,
|  | uint32_t * | bytesTransmitted
| ) |  |

Parameters

  lpuartState | Pointer to the LPUART driver state structure
  bytesTransmitted | Pointer to value that will be filled in with the number of bytes that have been sent in the active transfer

Return values

  kStatus_Success | The transmit has completed successfully.
  kStatus_LPUART_TxBusy | The transmit is still in progress. bytesTransmitted will be filled with the number of bytes that have been transmitted so far.

status_t lpuart_get_receive_status | ( | lpuart_state_t * | lpuartState,
|  | uint32_t * | bytesReceived
| ) |  |

Parameters

  lpuartState | Pointer to the LPUART driver state structure
  bytesReceived | Pointer to value that will be filled in with the number of bytes that have been received in the active transfer

Return values

  kStatus_Success | The receive has completed successfully.
  kStatus_LPUART_RxBusy | The receive is still in progress. bytesReceived will be filled with the number of bytes that have been received so far.

void lpuart_shutdown | ( | lpuart_state_t * | lpuartState | ) |

Parameters

  lpuartState | Pointer to the LPUART driver state structure

status_t lpuart_receive_data | ( | lpuart_state_t * | lpuartState,
|  | uint8_t * | rxBuffer,
|  | uint32_t | requestedByteCount,
|  | uint32_t | timeout
| ) |  |

By blocking, this means that the function will not return until the receive is complete.

Parameters

  lpuartState | Pointer to the LPUART driver state structure
  rxBuffer | buffer containing 8-bit read data chars received
  requestedByteCount | the number of bytes to receive
  timeout | timeout value for RTOS abstraction sync control

Returns
  An error code or kStatus_Success

status_t lpuart_receive_data_async | ( | lpuart_state_t * | lpuartState,
|  | uint8_t * | rxBuffer,
|  | uint32_t | requestedByteCount
| ) |  |

This allows an async method for receiving data and when coupled with a non-blocking transmit, the LPUART can perform a full duplex operation. By non-blocking, this means that the function will return immediately. The application will have to get the receive status to see when the receive is complete.

Parameters

  lpuartState | Pointer to the LPUART driver state structure
  rxBuffer | buffer containing 8-bit read data chars received
  requestedByteCount | the number of bytes to receive

Returns
  An error code or kStatus_Success

status_t lpuart_abort_sending_data | ( | lpuart_state_t * | lpuartState | ) |

Parameters

  lpuartState | Pointer to the LPUART driver state structure

Return values

  #kStatus_Success | The transmit was successful.

status_t lpuart_abort_receiving_data | ( | lpuart_state_t * | lpuartState | ) |

Parameters

  lpuartState | Pointer to the LPUART driver state structure

Return values

  #kStatus_Success | The receive was successful.