UART API

[English]

UART (Universal Asynchronous Receiver/Transmitter) 通用异步收发器API接口。

Header File

Functions

bk_err_t bk_uart_driver_init(void)

Init the UART driver.

This API init the resoure common to all UART id:

  • Init UART driver control memory

Attention

1. This API should be called before any other UART APIs.

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_driver_deinit(void)

Deinit the UART driver.

This API free all resource related to UART and power down all UART id.

返回

  • BK_OK: succeed

  • others: other errors.

int bk_uart_is_in_used(uart_id_t id)

Get the UART whether in used.

参数

id – UART id

返回

  • 1: in used

  • 0: not in used

bk_err_t bk_uart_init(uart_id_t id, const uart_config_t *config)

Init the UART id.

This API init the UART id:

  • Power up the UART id

  • Configure the UART id clock

  • Map the UART id to dedicated GPIO port

  • Set the UART baud rate, data bits, parity, stop bits,flow ctrl and source clock

  • Start the UART id

参数
  • id – UART id

  • config – UART parameter settings

返回

  • BK_OK: succeed

  • BK_ERR_UART_NOT_INIT: UART driver not init

  • BK_ERR_NULL_PARAM: UART config parameter is NULL

  • BK_ERR_UART_INVALID_ID: UART id is invalid

  • BK_ERR_UART_BAUD_RATE_NOT_SUPPORT: UART baud rate is not support

  • others: other errors.

bk_err_t bk_uart_deinit(uart_id_t id)

Deinit the UART id.

This API deinit the UART id:

  • Stop the UART id

  • Reset all configuration of UART id to default value

  • Disable the UART id interrupt

  • Power down the UART id

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_baud_rate(uart_id_t id, uint32_t baud_rate)

Set the UART baud rate.

参数
  • id – UART id

  • baud_rate – UART baud rate

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_data_bits(uart_id_t id, uart_data_bits_t data_bits)

Set the UART data bits.

参数
  • id – UART id

  • data_bits – UART data bits

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_stop_bits(uart_id_t id, uart_stop_bits_t stop_bits)

Set the UART stop bits.

参数
  • id – UART id

  • stop_bits – UART stop bits

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_parity(uart_id_t id, uart_parity_t partiy)

Set the UART partiy.

参数
  • id – UART id

  • partiy – UART partiy

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_hw_flow_ctrl(uart_id_t id, uint8_t rx_threshold)

Set the UART hardware flow control.

参数
  • id – UART id

  • rx_threshold – Threshold of Hardware RX flow control

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_rx_full_threshold(uart_id_t id, uint8_t threshold)

Set the UART threshold value for RX fifo full.

参数
  • id – UART id

  • threshold – Threshold value above which RX fifo full interrupt is generated

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_tx_empty_threshold(uart_id_t id, uint8_t threshold)

Set the UART threshold value for TX fifo empty.

参数
  • id – UART id

  • threshold – Threshold value below which TX fifo empty interrupt is generated

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_rx_timeout(uart_id_t id, uart_rx_stop_detect_time_t timeout_thresh)

Set the UART threshold timeout for receive data, unit is bit.

UART finish receiving data when the periods is more than timeout threshold. If the time is expired, the UART_RX_STOP_END interrupt is triggered.

参数
  • id – UART id

  • timeout_thresh – timeout threshold

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_disable_hw_flow_ctrl(uart_id_t id)

Disable the UART hardware flow control.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_enable_tx_interrupt(uart_id_t id)

Enable TX interrupt of UART id.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_disable_tx_interrupt(uart_id_t id)

Disable TX interrupt of UART id.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_enable_rx_interrupt(uart_id_t id)

Enable RX interrupt of UART id.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_disable_rx_interrupt(uart_id_t id)

Disable RX interrupt of UART id.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_register_rx_isr(uart_id_t id, uart_isr_t isr, void *param)

Register the RX interrupt service routine for UART id.

参数
  • id – UART id

  • isr – UART RX callback

  • param – UART RX callback parameter

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_register_tx_isr(uart_id_t id, uart_isr_t isr, void *param)

Register the TX interrupt service routine for UART id.

参数
  • id – UART id

  • isr – UART TX callback

  • param – UART TX callback parameter

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_write_bytes(uart_id_t id, const void *data, uint32_t size)

Send data to the UART port from a given buffer and length.

参数
  • id – UART id

  • data – data buffer address

  • size – data length to send

返回

  • BK_OK: succeed

  • others: other errors.

int bk_uart_read_bytes(uart_id_t id, void *data, uint32_t size, uint32_t timeout_ms)

UART read bytes from UART buffer.

参数
  • id – UART id

  • data – pointer to the buffer

  • size – data length to read

  • timeout_ms – timeout ms, if set BEKEN_WAIT_FOREVER, read will wait forever

返回

  • BK_ERR_UART_NOT_INIT: UART driver not init

  • BK_ERR_UART_INVALID_ID: UART id number is invalid

  • BK_ERR_UART_ID_NOT_INIT: UART id not init

  • BK_ERR_UART_RX_TIMEOUT: UART receive data timeout

  • others (>=0): The number of bytes read from UART FIFO

bk_err_t bk_uart_disable_rx(uart_id_t id)

Disable UART TX pin and set as GPIO.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_disable_tx(uart_id_t id)

Disable UART TX pin and set as GPIO.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_enable_rx(uart_id_t id, bool enable)

Just set UART RX enable/disable, doesn’t set pin.

参数
  • id – UART id

  • enable – true, enable, flase disable

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_set_enable_tx(uart_id_t id, bool enable)

Just set UART TX enable/disable, doesn’t set pin.

参数
  • id – UART id

  • enable – true, enable, flase disable

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_enable_sw_fifo(uart_id_t id)

Enable UART software fifo.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_disable_sw_fifo(uart_id_t id)

Disable UART software fifo.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_uart_get_ate_detect_gpio(void)

Get the gpio pin when in ate detect.

返回

the ate detect gpio pin

bk_err_t bk_uart_take_rx_isr(uart_id_t id, uart_isr_t isr, void *param)

Register uart rx isr and disable software fifo.

参数
  • id – UART id

  • isr – UART RX callback

  • param – UART RX callback parameter

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_uart_recover_rx_isr(uart_id_t id)

Recover uart rx isr.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.

bool bk_uart_is_tx_over(uart_id_t id)

Get whether the uart tx over(tx fifo empty)

参数

id – UART id

返回

  • true: uart tx over

  • false: uart tx not over

bk_err_t bk_uart_pm_backup(uart_id_t id)

Backup uart config.

参数

id – UART id

返回

  • BK_OK: succeed

  • others: other errors.