UARTs

API for UART serial ports.

Functions

struct metal_uart *metal_uart_get_device(unsigned int device_num)

Get a handle for a UART device.

Return

A handle to the UART device, or NULL if the device does not exist

Parameters
  • device_num: The index of the desired UART device

__inline__ void metal_uart_init(struct metal_uart *uart, int baud_rate)

Initialize UART device.

Initialize the UART device described by the UART handle. This function must be called before any other method on the UART can be invoked. It is invalid to initialize a UART more than once.

Parameters
  • uart: The UART device handle

  • baud_rate: the baud rate to set the UART to

__inline__ int metal_uart_putc(struct metal_uart *uart, int c)

Output a character over the UART.

Return

0 upon success

Parameters
  • uart: The UART device handle

  • c: The character to send over the UART

__inline__ int metal_uart_txready(struct metal_uart *uart)

Test, determine if tx output is blocked(full/busy)

Return

0 not blocked

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_getc(struct metal_uart *uart, int *c)

Read a character sent over the UART.

If “c == -1” no char was ready. If “c != -1” then C == byte value (0x00 to 0xff)

Return

0 upon success

Parameters
  • uart: The UART device handle

  • c: The varible to hold the read character

__inline__ int metal_uart_get_baud_rate(struct metal_uart *uart)

Get the baud rate of the UART peripheral.

Return

The current baud rate of the UART

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_set_baud_rate(struct metal_uart *uart, int baud_rate)

Set the baud rate of the UART peripheral.

Return

the new baud rate of the UART

Parameters
  • uart: The UART device handle

  • baud_rate: The baud rate to configure

__inline__ struct metal_interrupt *metal_uart_interrupt_controller(struct metal_uart *uart)

Get the interrupt controller of the UART peripheral.

Get the interrupt controller for the UART peripheral. The interrupt controller must be initialized before any interrupts can be registered or enabled with it.

Return

The handle for the UART interrupt controller

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_get_interrupt_id(struct metal_uart *uart)

Get the interrupt ID of the UART controller.

Return

The UART interrupt id

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_transmit_interrupt_enable(struct metal_uart *uart)

Enable the UART transmit interrupt.

Return

0 upon success

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_transmit_interrupt_disable(struct metal_uart *uart)

Disable the UART transmit interrupt.

Return

0 upon success

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_receive_interrupt_enable(struct metal_uart *uart)

Enable the UART receive interrupt.

Return

0 upon success

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_receive_interrupt_disable(struct metal_uart *uart)

Disable the UART receive interrupt.

Return

0 upon success

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_set_transmit_watermark(struct metal_uart *uart, size_t level)

Set the transmit watermark level of the UART controller.

Return

0 upon success

Parameters
  • uart: The UART device handle

  • level: The UART transmit watermark level

__inline__ size_t metal_uart_get_transmit_watermark(struct metal_uart *uart)

Get the transmit watermark level of the UART controller.

Return

The UART transmit watermark level

Parameters
  • uart: The UART device handle

__inline__ int metal_uart_set_receive_watermark(struct metal_uart *uart, size_t level)

Set the receive watermark level of the UART controller.

Return

0 upon success

Parameters
  • uart: The UART device handle

  • level: The UART transmit watermark level

__inline__ size_t metal_uart_get_receive_watermark(struct metal_uart *uart)

Get the receive watermark level of the UART controller.

Return

The UART transmit watermark level

Parameters
  • uart: The UART device handle

struct metal_uart
#include <uart.h>

Handle for a UART serial device.