41 #include <sys/select.h>
43 #ifndef UART_THREAD_PRIO
44 #define UART_THREAD_PRIO 11
48 static void *
uart_thread(
void *data __attribute__((unused)));
49 static pthread_mutex_t
uart_mutex = PTHREAD_MUTEX_INITIALIZER;
52 #define TRACE(fmt,args...)
59 if (pthread_create(&tid, NULL,
uart_thread, NULL) != 0) {
60 fprintf(stderr,
"uart_arch_init: Could not create UART reading thread.\n");
64 pthread_setname_np(tid,
"uart");
80 int __attribute__((unused))
fd;
82 if (uart0.reg_addr != NULL) {
84 FD_SET(
fd, &fds_master);
91 if (uart1.reg_addr != NULL) {
93 FD_SET(
fd, &fds_master);
100 if (uart2.reg_addr != NULL) {
102 FD_SET(
fd, &fds_master);
109 if (uart3.reg_addr != NULL) {
111 FD_SET(
fd, &fds_master);
118 if (uart4.reg_addr != NULL) {
120 FD_SET(
fd, &fds_master);
127 if (uart5.reg_addr != NULL) {
129 FD_SET(
fd, &fds_master);
136 if (uart6.reg_addr != NULL) {
138 FD_SET(
fd, &fds_master);
145 if (uart7.reg_addr != NULL) {
147 FD_SET(
fd, &fds_master);
154 if (uart8.reg_addr != NULL) {
156 FD_SET(
fd, &fds_master);
170 if (select(fdmax + 1, &fds, NULL, NULL, NULL) < 0) {
171 fprintf(stderr,
"uart_thread: select failed!");
174 if (uart0.reg_addr != NULL) {
176 if (FD_ISSET(
fd, &fds)) {
182 if (uart1.reg_addr != NULL) {
184 if (FD_ISSET(
fd, &fds)) {
190 if (uart2.reg_addr != NULL) {
192 if (FD_ISSET(
fd, &fds)) {
198 if (uart3.reg_addr != NULL) {
200 if (FD_ISSET(
fd, &fds)) {
206 if (uart4.reg_addr != NULL) {
208 if (FD_ISSET(
fd, &fds)) {
214 if (uart5.reg_addr != NULL) {
216 if (FD_ISSET(
fd, &fds)) {
222 if (uart6.reg_addr != NULL) {
224 if (FD_ISSET(
fd, &fds)) {
230 if (uart7.reg_addr != NULL) {
232 if (FD_ISSET(
fd, &fds)) {
238 if (uart8.reg_addr != NULL) {
240 if (FD_ISSET(
fd, &fds)) {
274 TRACE(
"Error opening %s code %d\n", periph->
dev, ret);
308 if (periph->
reg_addr == NULL) {
return; }
315 ret = write((
int)(port->
fd), &data, 1);
316 }
while (ret < 1 && errno == EAGAIN);
319 TRACE(
"uart_put_byte: write %d failed [%d: %s]\n", data, ret, strerror(errno));
326 unsigned char c =
'D';
328 if (periph->
reg_addr == NULL) {
return; }
335 while (read(
fd, &c, 1) > 0) {
342 TRACE(
"uart_receive_handler: rx_buf full! discarding received byte: %x %c\n", c, c);
351 uint8_t ret =
p->rx_buf[
p->rx_extract_idx];
360 int available =
p->rx_insert_idx -
p->rx_extract_idx;
369 void uart0_init(
void)
378 void uart1_init(
void)
387 void uart2_init(
void)
396 void uart3_init(
void)
405 void uart4_init(
void)
414 void uart5_init(
void)
423 void uart6_init(
void)
432 void uart7_init(
void)
441 void uart8_init(
void)
#define UART3_DEV
uart connected to SBUS input
void uart_put_byte(struct uart_periph *periph, long fd, uint8_t data)
#define TRACE(fmt, args...)
static void uart_receive_handler(struct uart_periph *periph)
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
static void * uart_thread(void *data)
void uart_arch_init(void)
void uart_periph_set_bits_stop_parity(struct uart_periph *periph, uint8_t bits, uint8_t stop, uint8_t parity)
static void uart_periph_open(struct uart_periph *periph, uint32_t baud)
static pthread_mutex_t uart_mutex
uint8_t uart_getch(struct uart_periph *p)
void uart_periph_set_baudrate(struct uart_periph *periph, uint32_t baud)
#define UART_RX_BUFFER_SIZE
Functions to obtain rt priority or set the nice level.
static int get_rt_prio(int prio)
void serial_port_free(struct SerialPort *me)
void serial_port_close(struct SerialPort *me)
int serial_port_open_raw(struct SerialPort *me, const char *device, speed_t speed)
int serial_port_set_bits_stop_parity(struct SerialPort *me, const int bits, const int stop, const int parity)
struct SerialPort * serial_port_new(void)
int serial_port_set_baudrate(struct SerialPort *me, speed_t speed)
void uart_periph_init(struct uart_periph *p)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define UART_DEV_NAME_SIZE
char dev[UART_DEV_NAME_SIZE]
UART Dev (linux)
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
int baudrate
UART Baudrate.
void * reg_addr
UART Register.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.