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);
152 if (select(fdmax + 1, &fds, NULL, NULL, NULL) < 0) {
153 fprintf(stderr,
"uart_thread: select failed!");
156 if (uart0.reg_addr != NULL) {
158 if (FD_ISSET(
fd, &fds)) {
164 if (uart1.reg_addr != NULL) {
166 if (FD_ISSET(
fd, &fds)) {
172 if (uart2.reg_addr != NULL) {
174 if (FD_ISSET(
fd, &fds)) {
180 if (uart3.reg_addr != NULL) {
182 if (FD_ISSET(
fd, &fds)) {
188 if (uart4.reg_addr != NULL) {
190 if (FD_ISSET(
fd, &fds)) {
196 if (uart5.reg_addr != NULL) {
198 if (FD_ISSET(
fd, &fds)) {
204 if (uart6.reg_addr != NULL) {
206 if (FD_ISSET(
fd, &fds)) {
240 TRACE(
"Error opening %s code %d\n", periph->
dev, ret);
274 if (periph->
reg_addr == NULL) {
return; }
281 ret = write((
int)(port->
fd), &data, 1);
282 }
while (ret < 1 && errno == EAGAIN);
285 TRACE(
"uart_put_byte: write %d failed [%d: %s]\n", data, ret, strerror(errno));
292 unsigned char c =
'D';
294 if (periph->
reg_addr == NULL) {
return; }
301 while (read(
fd, &
c, 1) > 0) {
308 TRACE(
"uart_receive_handler: rx_buf full! discarding received byte: %x %c\n",
c,
c);
317 uint8_t ret =
p->rx_buf[
p->rx_extract_idx];
326 int available =
p->rx_insert_idx -
p->rx_extract_idx;
335 void uart0_init(
void)
344 void uart1_init(
void)
353 void uart2_init(
void)
362 void uart3_init(
void)
371 void uart4_init(
void)
380 void uart5_init(
void)
389 void uart6_init(
void)