Browse Source

Allow serial port options to be specified in a relatively friendly format.

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
64e1df4af6
2 changed files with 24 additions and 14 deletions
  1. 1
    1
      src/config.h
  2. 23
    13
      src/core/serial.c

+ 1
- 1
src/config.h View File

28
 #if ! COMPRESERVE
28
 #if ! COMPRESERVE
29
 #define COMSPEED	9600		/* Baud rate */
29
 #define COMSPEED	9600		/* Baud rate */
30
 #define COMDATA		8		/* Data bits */ 
30
 #define COMDATA		8		/* Data bits */ 
31
-#define COMPARITY	N		/* Parity */
31
+#define COMPARITY	0		/* Parity: 0=None, 1=Odd, 2=Even */
32
 #define COMSTOP		1		/* Stop bits */
32
 #define COMSTOP		1		/* Stop bits */
33
 #endif
33
 #endif
34
 
34
 

+ 23
- 13
src/core/serial.c View File

16
 #include "init.h"
16
 #include "init.h"
17
 #include "io.h"
17
 #include "io.h"
18
 #include "timer.h"
18
 #include "timer.h"
19
+#include "config/serial.h"
19
 
20
 
20
 /* Set default values if none specified */
21
 /* Set default values if none specified */
21
 
22
 
22
 #ifndef COMCONSOLE
23
 #ifndef COMCONSOLE
23
-#define COMCONSOLE ( 0x3f8 )
24
+#define COMCONSOLE	0x3f8
24
 #endif
25
 #endif
25
 
26
 
26
-#ifndef CONSPEED
27
-#define CONSPEED ( 9600 )
27
+#ifndef COMSPEED
28
+#define COMSPEED	9600
29
+#endif
30
+
31
+#ifndef COMDATA
32
+#define COMDATA		8
33
+#endif
34
+
35
+#ifndef COMPARITY
36
+#define COMPARITY	N
37
+#endif
38
+
39
+#ifndef COMSTOP
40
+#define COMSTOP		1
28
 #endif
41
 #endif
29
 
42
 
30
 #undef UART_BASE
43
 #undef UART_BASE
31
-#define UART_BASE COMCONSOLE
44
+#define UART_BASE ( COMCONSOLE )
32
 
45
 
33
 #undef UART_BAUD
46
 #undef UART_BAUD
34
-#define UART_BAUD CONSPEED
47
+#define UART_BAUD ( COMSPEED )
35
 
48
 
36
 #if ((115200%UART_BAUD) != 0)
49
 #if ((115200%UART_BAUD) != 0)
37
 #error Bad ttys0 baud rate
50
 #error Bad ttys0 baud rate
40
 #define COMBRD (115200/UART_BAUD)
53
 #define COMBRD (115200/UART_BAUD)
41
 
54
 
42
 /* Line Control Settings */
55
 /* Line Control Settings */
43
-#ifndef	COMPARM
44
-/* Set 8bit, 1 stop bit, no parity */
45
-#define	COMPARM	0x03
46
-#endif
47
-
48
-#define UART_LCS COMPARM
56
+#define UART_LCS ( ( ( (COMDATA) - 5 )	<< 0 ) | \
57
+		   ( ( (COMPARITY) )	<< 3 ) | \
58
+		   ( ( (COMSTOP) - 1 )	<< 2 ) )
49
 
59
 
50
 /* Data */
60
 /* Data */
51
 #define UART_RBR 0x00
61
 #define UART_RBR 0x00
133
 
143
 
134
 /*
144
 /*
135
  * int serial_init(void);
145
  * int serial_init(void);
136
- *	Initialize port UART_BASE to speed CONSPEED, line settings 8N1.
146
+ *	Initialize port UART_BASE to speed COMSPEED, line settings 8N1.
137
  */
147
  */
138
 static void serial_init ( void ) {
148
 static void serial_init ( void ) {
139
 	int status;
149
 	int status;
150
 	uart_writeb(lcs, UART_BASE + UART_LCR);
160
 	uart_writeb(lcs, UART_BASE + UART_LCR);
151
 #endif
161
 #endif
152
 
162
 
153
-	/* Set Baud Rate Divisor to CONSPEED, and test to see if the
163
+	/* Set Baud Rate Divisor to COMSPEED, and test to see if the
154
 	 * serial port appears to be present.
164
 	 * serial port appears to be present.
155
 	 */
165
 	 */
156
 	uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
166
 	uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);

Loading…
Cancel
Save