Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
uart_arch.h
Go to the documentation of this file.
1 #include <stdbool.h>
2 #include <inttypes.h>
3 #include <stdio.h>
4 #include <sys/select.h>
5 #include <unistd.h>
6 #include <assert.h>
7 
8 #define STDINOUT_BUFFER_SIZE 256
9 #define FD_STDIN 0
10 
14 
15 
16 static inline bool StdInOutChAvailable(void) {
17  struct timeval tv;
18  fd_set fds;
19  tv.tv_sec = 0;
20  tv.tv_usec = 0;
21  FD_ZERO(&fds);
22  FD_SET(FD_STDIN, &fds);
23  select(1, &fds, NULL, NULL, &tv);
24  if (FD_ISSET(FD_STDIN, &fds)) {
25  char tmp_buf[STDINOUT_BUFFER_SIZE];
26  uint8_t n = read(FD_STDIN, tmp_buf, STDINOUT_BUFFER_SIZE);
27  unsigned int i;
28  for(i = 0; i < n; i++) {
30  stdinout_rx_insert_idx++; /* Auto overflow */
31  }
32  }
34 }
35 
36 #define StdInOutTransmit(_char) putchar(_char)
37 #define StdInOutGetch() ({ \
38  assert(stdinout_rx_insert_idx != stdinout_rx_extract_idx); \
39  stdinout_buffer[stdinout_rx_extract_idx++]; \
40 })
uint8_t stdinout_rx_insert_idx
Definition: sim_uart_hw.c:4
#define FD_STDIN
Definition: uart_arch.h:9
char stdinout_buffer[STDINOUT_BUFFER_SIZE]
Definition: sim_uart_hw.c:3
#define STDINOUT_BUFFER_SIZE
Definition: uart_arch.h:8
unsigned char uint8_t
Definition: types.h:14
uint8_t stdinout_rx_extract_idx
Definition: sim_uart_hw.c:5
static bool StdInOutChAvailable(void)
Definition: uart_arch.h:16