1
+ /*
2
+ * TODO: support multiple 16x50 ports
3
+ */
1
4
#include <kernel.h>
2
5
#include <kdata.h>
3
6
#include <printf.h>
@@ -44,10 +47,58 @@ void tty_putc(uint8_t minor, unsigned char c)
44
47
* uart = c ;
45
48
}
46
49
50
+ /*
51
+ * 16x50 conversion betwen a Bxxxx speed rate (see tty.h) and the values
52
+ * to stuff into the chip.
53
+ */
54
+ static uint16_t clocks [] = {
55
+ 12 , /* Not a real rate */
56
+ 2304 ,
57
+ 1536 ,
58
+ 1047 ,
59
+ 857 ,
60
+ 768 ,
61
+ 384 ,
62
+ 192 ,
63
+ 96 ,
64
+ 48 ,
65
+ 24 ,
66
+ 12 ,
67
+ 6 ,
68
+ 3 ,
69
+ 2 ,
70
+ 1
71
+ };
72
+
73
+
47
74
void tty_setup (uint8_t minor , uint8_t flag )
48
75
{
49
- /* As we don't have a separate clock for serial and the
50
- divider is very limited we are stuck at 115200 8N1 */
76
+ uint8_t d ;
77
+ uint16_t w ;
78
+ struct termios * t = & ttydata [1 ].termios ;
79
+
80
+ d = 0x80 ; /* DLAB (so we can write the speed) */
81
+ d |= (t -> c_cflag & CSIZE ) >> 4 ;
82
+ if (t -> c_cflag & CSTOPB )
83
+ d |= 0x04 ;
84
+ if (t -> c_cflag & PARENB )
85
+ d |= 0x08 ;
86
+ if (!(t -> c_cflag & PARODD ))
87
+ d |= 0x10 ;
88
+ uart [3 ] = d ; /* LCR */
89
+ w = clocks [t -> c_cflag & CBAUD ];
90
+ * uart = w ; /* Set the DL */
91
+ uart [1 ] = w >> 8 ;
92
+ if (w >> 8 ) /* Low speeds interrupt every byte for latency */
93
+ uart [2 ] = 0 ;
94
+ else /* High speeds set our interrupt quite early
95
+ as our latency is poor, turn on 64 byte if
96
+ we have a 16C750 */
97
+ uart [2 ] = 0x51 ;
98
+ uart [3 ] = d & 0x7F ;
99
+ /* FIXME: CTS/RTS support */
100
+ uart [4 ] = 0x03 ; /* DTR RTS */
101
+ uart [1 ] = 0x0D ; /* We don't use tx ints */
51
102
}
52
103
53
104
void tty_sleeping (uint8_t minor )
@@ -57,7 +108,7 @@ void tty_sleeping(uint8_t minor)
57
108
/* No carrier signal */
58
109
int tty_carrier (uint8_t minor )
59
110
{
60
- return 1 ;
111
+ return uart [ 6 ] & 0x80 ;
61
112
}
62
113
63
114
/* No flow control */
@@ -67,6 +118,15 @@ void tty_data_consumed(uint8_t minor)
67
118
68
119
void tty_poll (void )
69
120
{
70
- /* TODO if (cpuio[0x11] & 0x80)
71
- tty_inproc(1, cpuio[0x12]); */
121
+ uint8_t msr ;
122
+ if (uart [5 ] & 0x01 )
123
+ tty_inproc (1 , * uart );
124
+ msr = uart [6 ];
125
+ if (msr & 0x08 ) {
126
+ if (msr & 0x80 )
127
+ tty_carrier_raise (1 );
128
+ else
129
+ tty_carrier_drop (1 );
130
+ }
131
+ /* TOOD: CTS/RTS etc */
72
132
}
0 commit comments