[English]

UART

UART API Reference

Functions

OSStatus bk_uart_initialize(bk_uart_t uart, const bk_uart_config_t *config, ring_buffer_t *optional_rx_buffer)

Initialises a UART interface.

备注

Prepares an UART hardware interface for communications

参数
  • uart – : the interface which should be initialised

  • config – : UART configuration structure

  • optional_rx_buffer – : Pointer to an optional RX ring buffer

返回

  • kNoErr : on success.

  • kGeneralErr : if an error occurred with any step

OSStatus bk_uart_finalize(bk_uart_t uart)

Deinitialises a UART interface.

参数

uart – : the interface which should be deinitialised

返回

  • kNoErr : on success.

  • kGeneralErr : if an error occurred with any step

OSStatus bk_uart_send(bk_uart_t uart, const void *data, uint32_t size)

Transmit data on a UART interface.

参数
  • uart – : the UART interface

  • data – : pointer to the start of data

  • size – : number of bytes to transmit

返回

  • kNoErr : on success.

  • kGeneralErr : if an error occurred with any step

OSStatus bk_uart_recv(bk_uart_t uart, void *data, uint32_t size, uint32_t timeout)

Receive data on a UART interface.

参数
  • uart – : the UART interface

  • data – : pointer to the buffer which will store incoming data

  • size – : number of bytes to receive

  • timeout – : timeout in milisecond

返回

  • kNoErr : on success.

  • kGeneralErr : if an error occurred with any step

OSStatus bk_uart_recv_prefetch(bk_uart_t uart, void *data, uint32_t size, uint32_t timeout)
uint32_t bk_uart_get_length_in_buffer(bk_uart_t uart)

Read the length of the data that is already recived by uart driver and stored in buffer.

参数

uart – : the UART interface

返回

Data length

OSStatus bk_uart_set_rx_callback(bk_uart_t uart, uart_callback callback, void *param)

set receive data callback on a UART interface, please notice that, the callback will beinvoked in ISR

参数
  • uart – : the UART interface

  • callback – : callback to invoke when UART receive data, use NULL to clear callback

  • param – : user param which will filled in callback as 2nd parameter

返回

  • kNoErr : on success.

  • kGeneralErr : if an error occurred with any step

Structures

struct ring_buffer_t

Enumerations

enum bk_uart_t

Values:

enumerator BK_UART_1
enumerator BK_UART_2
enumerator BK_UART_MAX