UART
Ameba SDK » HAL

uart functions More...

## Ameba Common

enum | SerialParity { ParityNone = 0, ParityOdd = 1, ParityEven = 2, ParityForced1 = 3, ParityForced0 = 4 }
| UART Parity mode used by serial_format. More...
enum | SerialIrq { RxIrq, TxIrq }
| UART Interrupt enable/disable used by serial_irq_set. More...
enum | FlowControl { FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS }
| UART FlowControl mode used by serial_set_flow_control. More...
typedef void(* | uart_irq_handler) (uint32_t id, SerialIrq event)
typedef struct serial_s | serial_t
void | serial_init (serial_t *obj, PinName tx, PinName rx)
| Initializes the UART device, include clock/function/interrupt/UART registers. More...
void | serial_free (serial_t *obj)
| Deinitializes the UART device, include clock/function/interrupt/UART registers. More...
void | serial_baud (serial_t *obj, int baudrate)
| Set UART device baudrate. More...
void | serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
| Set UART format. More...
void | serial_irq_handler (serial_t *obj, uart_irq_handler handler, uint32_t id)
| Set UART interrupt hander if needed. More...
void | serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable)
| Enable/Disable UART interrupt. More...
int | serial_getc (serial_t *obj)
| get one byte from UART. More...
void | serial_putc (serial_t *obj, int c)
| send one byte use UART. More...
int | serial_readable (serial_t *obj)
| check if there is data in rx fifo. More...
int | serial_writable (serial_t *obj)
| check if write data to tx fifo is permitted. More...
void | serial_clear (serial_t *obj)
| Clear Rx fifo. More...
void | serial_break_set (serial_t *obj)
| enable UART break contol function. More...
void | serial_break_clear (serial_t *obj)
| disable UART break contol function. More...
void | serial_pinout_tx (PinName tx)
| set tx pinmux. More...
void | serial_set_flow_control (serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
| uart autoflow contol setting. More...

## Detailed Description

uart functions

## Enumeration Type Documentation

enum FlowControl

UART FlowControl mode used by serial_set_flow_control.

Enumerator
FlowControlNone | none RTS/CTS
FlowControlRTS | RTS enable
FlowControlCTS | CTS enable
FlowControlRTSCTS | RTS/CTS enable

enum SerialIrq

UART Interrupt enable/disable used by serial_irq_set.

Enumerator
RxIrq | RX IRQ enable/disable
TxIrq | TX IRQ enable/disable

enum SerialParity

UART Parity mode used by serial_format.

Enumerator
ParityNone | parity disable
ParityOdd | odd parity enable
ParityEven | even paroty enable
ParityForced1 | same action with ParityOdd
ParityForced0 | same action with ParityEven

## Function Documentation

void serial_baud | ( | serial_t * | obj,
|  | int | baudrate
| ) |  |

Set UART device baudrate.

Parameters

  obj | uart object define in application software.
  baudrate | Baud Rate Val, like 115200 (unit is HZ).

Return values

  none |

void serial_break_clear | ( | serial_t * | obj | ) |

disable UART break contol function.

Parameters

  obj | uart object define in application software.

Return values

  none |

void serial_break_set | ( | serial_t * | obj | ) |

enable UART break contol function.

Parameters

  obj | uart object define in application software.

Return values

  none |

void serial_clear | ( | serial_t * | obj | ) |

Clear Rx fifo.

Parameters

  obj | uart object define in application software.

Return values

  none |

void serial_format | ( | serial_t * | obj,
|  | int | data_bits,
|  | SerialParity | parity,
|  | int | stop_bits
| ) |  |

Set UART format.

Parameters

  obj | uart object define in application software.

  data_bits

  data bits, this parameter can be one of the following values:
  - 7
  - 8

  parity

  this parameter can be one of the following values:
  - ParityNone
  - ParityOdd
  - ParityEven
  - ParityForced1: same action with ParityOdd
  - ParityForced0: same action with ParityEven

  stop_bits

  this parameter can be one of the following values:
  - 2
  - 1

Return values

  none |

void serial_free | ( | serial_t * | obj | ) |

Deinitializes the UART device, include clock/function/interrupt/UART registers.

Parameters

  obj | uart object define in application software.

Return values

  none |

int serial_getc | ( | serial_t * | obj | ) |

get one byte from UART.

Parameters

  obj | uart object define in application software.

Return values

  | received character

Note
  this function is asynchronous API.

void serial_init | ( | serial_t * | obj,
|  | PinName | tx,
|  | PinName | rx
| ) |  |

Initializes the UART device, include clock/function/interrupt/UART registers.

Parameters

  obj | uart object define in application software.
  tx | Tx PinName according to pinmux spec.
  rx | Rx PinName according to pinmux spec.

Return values

  none |

void serial_irq_handler | ( | serial_t * | obj,
|  | uart_irq_handler | handler,
|  | uint32_t | id
| ) |  |

Set UART interrupt hander if needed.

Parameters

  obj | uart object define in application software.
  handler | interrupt callback function
  id | interrupt callback parameter

Return values

  none |

void serial_irq_set | ( | serial_t * | obj,
|  | SerialIrq | irq,
|  | uint32_t | enable
| ) |  |

Enable/Disable UART interrupt.

Parameters

  obj | uart object define in application software.

  irq

  Tx or Rx interrupt, this parameter can be one of the following values:
  - RxIrq
  - TxIrq

  enable

  this parameter can be one of the following values:
  - 0 disable
  - 1 enable

Return values

  none |

void serial_pinout_tx | ( | PinName | tx | ) |

set tx pinmux.

Parameters

  tx | Tx PinName according to pinmux spec.

Return values

  none |

void serial_putc | ( | serial_t * | obj,
|  | int | c
| ) |  |

send one byte use UART.

Parameters

  obj | uart object define in application software.
  c | the data to transmit.

Return values

  none |

Note
  this function is asynchronous API.

int serial_readable | ( | serial_t * | obj | ) |

check if there is data in rx fifo.

Parameters

  obj | uart object define in application software.

Return values

  1 | TRUE
  0 | FALSE

void serial_set_flow_control | ( | serial_t * | obj,
|  | FlowControl | type,
|  | PinName | rxflow,
|  | PinName | txflow
| ) |  |

uart autoflow contol setting.

Parameters

  obj | uart object define in application software.
  type | autoflow control type.
  rxflow | RTS pin.
  txflow | CTS pin.

Return values

  none |

int serial_writable | ( | serial_t * | obj | ) |

check if write data to tx fifo is permitted.

Parameters

  obj | uart object define in application software.

Return values

  1 | TRUE
  0 | FALSE