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

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

@@ -16,22 +16,35 @@
16 16
 #include "init.h"
17 17
 #include "io.h"
18 18
 #include "timer.h"
19
+#include "config/serial.h"
19 20
 
20 21
 /* Set default values if none specified */
21 22
 
22 23
 #ifndef COMCONSOLE
23
-#define COMCONSOLE ( 0x3f8 )
24
+#define COMCONSOLE	0x3f8
24 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 41
 #endif
29 42
 
30 43
 #undef UART_BASE
31
-#define UART_BASE COMCONSOLE
44
+#define UART_BASE ( COMCONSOLE )
32 45
 
33 46
 #undef UART_BAUD
34
-#define UART_BAUD CONSPEED
47
+#define UART_BAUD ( COMSPEED )
35 48
 
36 49
 #if ((115200%UART_BAUD) != 0)
37 50
 #error Bad ttys0 baud rate
@@ -40,12 +53,9 @@
40 53
 #define COMBRD (115200/UART_BAUD)
41 54
 
42 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 60
 /* Data */
51 61
 #define UART_RBR 0x00
@@ -133,7 +143,7 @@ static int serial_ischar ( void ) {
133 143
 
134 144
 /*
135 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 148
 static void serial_init ( void ) {
139 149
 	int status;
@@ -150,7 +160,7 @@ static void serial_init ( void ) {
150 160
 	uart_writeb(lcs, UART_BASE + UART_LCR);
151 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 164
 	 * serial port appears to be present.
155 165
 	 */
156 166
 	uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);

Loading…
Cancel
Save