1 ! Copyright (C) 2008 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.syntax assocs classes.struct
4 io.serial kernel system ;
5 IN: io.serial.linux.ffi
11 TYPEDEF: uint tcflag_t
23 FUNCTION: speed_t cfgetispeed ( termios* t )
24 FUNCTION: speed_t cfgetospeed ( termios* t )
25 FUNCTION: int cfsetispeed ( termios* t, speed_t s )
26 FUNCTION: int cfsetospeed ( termios* t, speed_t s )
27 FUNCTION: int tcgetattr ( int i1, termios* t )
28 FUNCTION: int tcsetattr ( int i1, int i2, termios* t )
29 FUNCTION: int tcdrain ( int i1 )
30 FUNCTION: int tcflow ( int i1, int i2 )
31 FUNCTION: int tcflush ( int i1, int i2 )
32 FUNCTION: int tcsendbreak ( int i1, int i2 )
33 FUNCTION: void cfmakeraw ( termios* t )
34 FUNCTION: int cfsetspeed ( termios* t, speed_t s )
36 ! See /usr/include/bits/termios.h
51 CONSTANT: IGNBRK 0o0000001
52 CONSTANT: BRKINT 0o0000002
53 CONSTANT: IGNPAR 0o0000004
54 CONSTANT: PARMRK 0o0000010
55 CONSTANT: INPCK 0o0000020
56 CONSTANT: ISTRIP 0o0000040
57 CONSTANT: INLCR 0o0000100
58 CONSTANT: IGNCR 0o0000200
59 CONSTANT: ICRNL 0o0000400
60 CONSTANT: IUCLC 0o0001000
61 CONSTANT: IXON 0o0002000
62 CONSTANT: IXANY 0o0004000
63 CONSTANT: IXOFF 0o0010000
64 CONSTANT: IMAXBEL 0o0020000
65 CONSTANT: IUTF8 0o0040000
68 CONSTANT: OPOST 0o0000001
69 CONSTANT: OLCUC 0o0000002
70 CONSTANT: ONLCR 0o0000004
71 CONSTANT: OCRNL 0o0000010
72 CONSTANT: ONOCR 0o0000020
73 CONSTANT: ONLRET 0o0000040
74 CONSTANT: OFILL 0o0000100
75 CONSTANT: OFDEL 0o0000200
76 CONSTANT: NLDLY 0o0000400
77 CONSTANT: NL0 0o0000000
78 CONSTANT: NL1 0o0000400
79 CONSTANT: CRDLY 0o0003000
80 CONSTANT: CR0 0o0000000
81 CONSTANT: CR1 0o0001000
82 CONSTANT: CR2 0o0002000
83 CONSTANT: CR3 0o0003000
84 CONSTANT: TABDLY 0o0014000
85 CONSTANT: TAB0 0o0000000
86 CONSTANT: TAB1 0o0004000
87 CONSTANT: TAB2 0o0010000
88 CONSTANT: TAB3 0o0014000
89 CONSTANT: BSDLY 0o0020000
90 CONSTANT: BS0 0o0000000
91 CONSTANT: BS1 0o0020000
92 CONSTANT: FFDLY 0o0100000
93 CONSTANT: FF0 0o0000000
94 CONSTANT: FF1 0o0100000
97 CONSTANT: CSIZE 0o0000060
98 CONSTANT: CS5 0o0000000
99 CONSTANT: CS6 0o0000020
100 CONSTANT: CS7 0o0000040
101 CONSTANT: CS8 0o0000060
102 CONSTANT: CSTOPB 0o0000100
103 CONSTANT: CREAD 0o0000200
104 CONSTANT: PARENB 0o0000400
105 CONSTANT: PARODD 0o0001000
106 CONSTANT: HUPCL 0o0002000
107 CONSTANT: CLOCAL 0o0004000
108 CONSTANT: CIBAUD 0o002003600000
109 CONSTANT: CRTSCTS 0o020000000000
112 CONSTANT: ISIG 0o0000001
113 CONSTANT: ICANON 0o0000002
114 CONSTANT: XCASE 0o0000004
115 CONSTANT: ECHO 0o0000010
116 CONSTANT: ECHOE 0o0000020
117 CONSTANT: ECHOK 0o0000040
118 CONSTANT: ECHONL 0o0000100
119 CONSTANT: NOFLSH 0o0000200
120 CONSTANT: TOSTOP 0o0000400
121 CONSTANT: ECHOCTL 0o0001000
122 CONSTANT: ECHOPRT 0o0002000
123 CONSTANT: ECHOKE 0o0004000
124 CONSTANT: FLUSHO 0o0010000
125 CONSTANT: PENDIN 0o0040000
126 CONSTANT: IEXTEN 0o0100000
141 CONSTANT: VREPRINT 12
142 CONSTANT: VDISCARD 13
147 M: linux lookup-baud ( n -- n )
172 { 1000000 0o0010010 }
173 { 1152000 0o0010011 }
174 { 1500000 0o0010012 }
175 { 2000000 0o0010013 }
176 { 2500000 0o0010014 }
177 { 3000000 0o0010015 }
178 { 3500000 0o0010016 }
179 { 4000000 0o0010017 }
180 } ?at [ invalid-baud ] unless ;