//************************************************************************************** /*! \copyright: 2020-2021 Thales Alenia Space Deutschland GmbH * \project: multiMIND * \file: (name of source file: uart.h) * \date: (20.05.2021) * \author: (Sarthak Kelapure) * \brief: (UART thread to collect data on serial interface) * \language: (C) ************************************************************************************** */ #ifndef LIB_UART_H #define LIB_UART_H #define BUFF_SIZE 512 #define POLL_TIMEOUT 2000 #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif typedef struct serial_s serial_t; /** * Destroy the serial structure */ void uart_destroy(serial_t* s); /** * Initializes the serial connection * @param device - serial device name. * @param baud - baud rate for connection. * @return serial structure. */ serial_t* uart_init(char device[], int baud); /** * Send data. * @param s - serial structure. * @param data - character array to transmit. * @param length - size of the data array. */ uint32_t uart_length_send(serial_t* s, uint8_t data[], int length); /** * Send a single character. * @param s - serial structure. * @param data - single character to be sent. */ void uart_send(serial_t* s, uint8_t data); /** * Determine how much data is available * in the serial buffer. * @param s - serial structure. * @return number of characters available. */ int uart_available(serial_t* s); /** * Fetch one char from the serial buffer. * @param s - serial structure. * @return character. Null if empty. */ char uart_get(serial_t* s); /** * Fetch length of chars from the serial buffer. * @param s - serial structure. * @param buff - readback storage * @param len - length to get * @return length. zero if empty. */ int uart_length_get(serial_t* s, char* buff, int len, bool start_of_packet); uint16_t uart_get_hdlc_packet(serial_t* s, uint8_t *buff, uint16_t buff_len); /** * Fetch one char from the serial buffer. * Blocks until data becomes available. * @param s - serial structure. * @return character. */ char uart_blocking_get(serial_t* s); /** * Clear the serial buffer. * @param s - serial structure. */ void uart_clear(serial_t* s); /** * Close the serial port. * @param s - serial structure. * @return value of close(). */ int uart_close(serial_t* s); /** * Deinitializes the UART * @param s - serial structure. */ void uart_deinit(serial_t* s); #ifdef __cplusplus } #endif #endif //LIB_UART_H