USART driver

File: csp/drivers/usart.h

Description: USART driver

Note

This interface implementation only support ONE open UART connection.

Typedefs

type csp_usart_conf_t
[source]

Usart configuration. @see csp_usart_open()

uint32_t baudrate
[source]

bits per second.

uint8_t databits
[source]

Number of data bits.

const char *device
[source]

USART device.

uint8_t paritysetting
[source]

Parity setting.

uint8_t stopbits
[source]

Number of stop bits.

Interface Functions

int csp_usart_open(const csp_usart_conf_t *conf, csp_usart_callback_t rx_callback, void *user_data, csp_usart_fd_t *fd)
[source]

Opens an UART device. Opens the UART device and creates a thread for reading/returning data to the application.

Note

On read failure, exit() will be called - terminating the process.

Parameters:
  • conf – UART configuration.

  • rx_callback – receive data callback.

  • user_data – reference forwarded to the rx_callback function.

  • fd – the opened file descriptor.

Returns:

#CSP_ERR_NONE on success, otherwise an error code.

int csp_usart_write(csp_usart_fd_t fd, const void *data, size_t data_length)
[source]

Write data on open UART.

Parameters:
  • data – Outbound data to send over the USART interface.

  • data_length – Outbound data length.

Returns:

number of bytes written on success, a negative value on failure.

void csp_usart_lock(void *driver_data)
[source]

Lock the device, so only a single user can write to the serial port at a time

Parameters:
  • driver_data – Driver data

void csp_usart_unlock(void *driver_data)
[source]

Unlock the USART again

Parameters:
  • driver_data – Driver data

int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t *conf, const char *ifname, uint16_t addr, csp_iface_t **return_iface)
[source]

Opens UART device and add KISS interface.

This is a convience function for opening an UART device and adding it as an interface with a given name.

Note

On read failures, exit() will be called - terminating the process.

Parameters:
  • conf – UART configuration.

  • ifname – internface name (will be copied), or use NULL for default name.

  • addr – CSP address of the interface.

  • return_iface – the added interface.

Returns:

#CSP_ERR_NONE on success, otherwise an error code.