Last change
on this file since 405 was
231,
checked in by max@…, 7 years ago
|
Add a serial port multiplexer, usable to communicate with the
ALMOS-MKH kernel over a serial port.
|
File size:
1.7 KB
|
Rev | Line | |
---|
[231] | 1 | /* |
---|
| 2 | ******************************************************************************* |
---|
| 3 | * Authors: |
---|
| 4 | * Maxime Villard, 2017 |
---|
| 5 | * Jankovic Marco, 01/07/2014 |
---|
| 6 | ******************************************************************************* |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define XOPEN_SOURCE |
---|
| 10 | |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <string.h> |
---|
| 13 | #include <stdlib.h> |
---|
| 14 | #include <stdint.h> |
---|
| 15 | #include <unistd.h> |
---|
| 16 | #include <fcntl.h> |
---|
| 17 | #include <sys/types.h> |
---|
| 18 | #include <sys/stat.h> |
---|
| 19 | #include <sys/select.h> |
---|
| 20 | #include <sys/time.h> |
---|
| 21 | #include <pthread.h> |
---|
| 22 | #include <signal.h> |
---|
| 23 | #include <sys/ioctl.h> |
---|
| 24 | #include <termios.h> |
---|
| 25 | #include <time.h> |
---|
| 26 | #include <sys/types.h> |
---|
| 27 | |
---|
| 28 | #include <err.h> |
---|
| 29 | |
---|
| 30 | #include "config.h" |
---|
| 31 | |
---|
| 32 | #define READ_LEN 64 |
---|
| 33 | #define FIFO_LIMIT_SIZE 512 |
---|
| 34 | |
---|
| 35 | #define XON 0x11 |
---|
| 36 | #define XOFF 0x13 |
---|
| 37 | |
---|
| 38 | #define UNUSED(x) (void)(x) /* for unused variables */ |
---|
| 39 | |
---|
| 40 | /* |
---|
| 41 | * Encoding for the multiplexer: we use packets, and their size is at most 2 |
---|
| 42 | * bytes. |
---|
| 43 | * |
---|
| 44 | * If [the first byte of the packet has bit7==1] |
---|
| 45 | * --> bits [0;6] are the TTY number |
---|
| 46 | * --> the next byte is the character (char, as usual) |
---|
| 47 | * Else If [the first byte of the packet == 0x11] |
---|
| 48 | * --> it's XON |
---|
| 49 | * Else If [the first byte of the packet == 0x13] |
---|
| 50 | * --> it's XOFF |
---|
| 51 | * Else |
---|
| 52 | * --> unknown packet, drop it |
---|
| 53 | */ |
---|
| 54 | #define PKT_TTY 0 |
---|
| 55 | #define PKT_DAT 1 |
---|
| 56 | #define PACKET_SIZE 2 |
---|
| 57 | |
---|
| 58 | void *thread_mux_demux(void *a); |
---|
| 59 | void *thread_read_rx(void *a); |
---|
| 60 | void *thread_write_tx(void *a); |
---|
| 61 | |
---|
| 62 | /******************************************************************************/ |
---|
| 63 | |
---|
| 64 | extern int slave_fd[NB_CHANNELS]; |
---|
| 65 | extern int master_fd[NB_CHANNELS]; |
---|
| 66 | extern int fifo_rx_fd; |
---|
| 67 | extern int fifo_tx_fd; |
---|
| 68 | extern int device_fd; |
---|
| 69 | extern int test_rx_fd; |
---|
| 70 | extern int test_tx_fd; |
---|
| 71 | |
---|
| 72 | /******************************************************************************/ |
---|
| 73 | |
---|
Note: See
TracBrowser
for help on using the repository browser.