UART API
UART (Universal Asynchronous Receiver/Transmitter) API interface.
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.
- Returns
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.
- Returns
BK_OK: succeed
others: other errors.
-
int bk_uart_is_in_used(uart_id_t id)
Get the UART whether in used.
- Parameters
id – UART id
- Returns
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
- Parameters
id – UART id
config – UART parameter settings
- Returns
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
- Parameters
id – UART id
- Returns
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.
- Parameters
id – UART id
baud_rate – UART baud rate
- Returns
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.
- Parameters
id – UART id
data_bits – UART data bits
- Returns
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.
- Parameters
id – UART id
stop_bits – UART stop bits
- Returns
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.
- Parameters
id – UART id
partiy – UART partiy
- Returns
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.
- Parameters
id – UART id
rx_threshold – Threshold of Hardware RX flow control
- Returns
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.
- Parameters
id – UART id
threshold – Threshold value above which RX fifo full interrupt is generated
- Returns
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.
- Parameters
id – UART id
threshold – Threshold value below which TX fifo empty interrupt is generated
- Returns
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.
- Parameters
id – UART id
timeout_thresh – timeout threshold
- Returns
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.
- Parameters
id – UART id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_enable_tx_interrupt(uart_id_t id)
Enable TX interrupt of UART id.
- Parameters
id – UART id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_disable_tx_interrupt(uart_id_t id)
Disable TX interrupt of UART id.
- Parameters
id – UART id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_enable_rx_interrupt(uart_id_t id)
Enable RX interrupt of UART id.
- Parameters
id – UART id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_disable_rx_interrupt(uart_id_t id)
Disable RX interrupt of UART id.
- Parameters
id – UART id
- Returns
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.
- Parameters
id – UART id
isr – UART RX callback
param – UART RX callback parameter
- Returns
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.
- Parameters
id – UART id
isr – UART TX callback
param – UART TX callback parameter
- Returns
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.
- Parameters
id – UART id
data – data buffer address
size – data length to send
- Returns
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.
- Parameters
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
- Returns
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.
- Parameters
id – UART id
- Returns
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.
- Parameters
id – UART id
- Returns
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.
- Parameters
id – UART id
enable – true, enable, flase disable
- Returns
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.
- Parameters
id – UART id
enable – true, enable, flase disable
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_enable_sw_fifo(uart_id_t id)
Enable UART software fifo.
- Parameters
id – UART id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_disable_sw_fifo(uart_id_t id)
Disable UART software fifo.
- Parameters
id – UART id
- Returns
BK_OK: succeed
others: other errors.
-
uint32_t bk_uart_get_ate_detect_gpio(void)
Get the gpio pin when in ate detect.
- Returns
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.
- Parameters
id – UART id
isr – UART RX callback
param – UART RX callback parameter
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_uart_recover_rx_isr(uart_id_t id)
Recover uart rx isr.
- Parameters
id – UART id
- Returns
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)
- Parameters
id – UART id
- Returns
true: uart tx over
false: uart tx not over