engine_control/source/firmware/kernel/driver/uart.h

64 lines
2.1 KiB
C
Raw Normal View History

2016-07-23 05:59:54 +00:00
//! \file uart.h
//! \author tkl
//! \date Jul 15, 2012
//! \brief Header file of the architecture independent uart implementation.
#ifndef UART_H_
#define UART_H_
//! Function pointer for the uart open function.
typedef int (*uart_fp_open_t)(const void*);
//! Function pointer for the uart close function.
typedef int (*uart_fp_close_t)(const void*);
//! Function pointer for the uart read function.
typedef int (*uart_fp_read_t)(const void*, char*, int);
//! Function pointer for the uart write function.
typedef int (*uart_fp_write_t)(const void*, const char*, int);
//! Function pointer for the uart set callback function.
typedef int (*uart_fp_set_cb_t)(const void*, const void *, const void*);
//! \brief Uart access.
struct uart_fp {
const uart_fp_open_t open; //!< Open.
const uart_fp_close_t close; //!< Close.
const uart_fp_read_t read; //!< Read.
const uart_fp_write_t write; //!< Write.
const uart_fp_set_cb_t set_cb; //!< Set callback.
};
//! \brief Uart driver object.
struct uart {
const void *arch_dep_device; //!< Architecture depended uart device.
const struct uart_fp *fp; //!< Uart access.
struct ringbuffer *buffer; //!< Intermediate buffer.
};
//! \brief Open an uart device.
//! \param this The uart device to open.
//! \retval -1 in error case.
int uart_open(const struct uart *this);
//! \brief Close an uart device.
//! \param this The uart device to close.
//! \retval -1 in error case.
int uart_close(const struct uart *this);
//! \brief Read from an uart device.
//! \param this The uart device to read from.
//! \param buffer The buffer to read to.
//! \param len The size of the buffer.
//! \retval -1 in error case, otherwise the number of read characters.
int uart_read(const struct uart *this, char *buffer, int len);
//! \brief Write to an uart device.
//! \param this The uart device to write to.
//! \param buffer The buffer to write.
//! \param len The number of characters to write.
//! \retval -1 in error case, otherwise the number of written characters.
int uart_write(const struct uart *this, const char *buffer, int len);
#endif /* UART_H_ */