summaryrefslogtreecommitdiff
path: root/src/kernel/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/serial.c')
-rw-r--r--src/kernel/serial.c67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/kernel/serial.c b/src/kernel/serial.c
index c92f173..9ca8315 100644
--- a/src/kernel/serial.c
+++ b/src/kernel/serial.c
@@ -48,54 +48,47 @@ enum {
CLS_READ = 0x01
};
-bool error;
-#define SERIAL_SPIN_LIMIT 65535
+static const uint16_t ports[] = {
+ CP_1, CP_2, CP_3, CP_4
+};
+
+static bool error[] = {
+ false, false, false, false
+};
-bool serr() {
- return error;
+void reset_error(enum serial_port n) {
+ error[n] = false;
}
void init_serial() {
- error = false;
- outb(CP_1 | CP_INT, 0);
- outb(CP_1 | CP_LINE, CL_BAUD);
- outb(CP_1 | CP_DIVLOW, 0x03);//38400
- outb(CP_1 | CP_DIVHIGH, 0x00);//baud
- outb(CP_1 | CP_LINE, CL_8BIT);
- outb(CP_1 | CP_FIFO, 0xc7);//?
+ for (enum serial_port i = COM1; i <= COM4; ++i) {
+ outb(ports[i] | CP_INT, 0);
+ outb(ports[i] | CP_LINE, CL_BAUD);
+ outb(ports[i] | CP_DIVLOW, 0x03);//38400
+ outb(ports[i] | CP_DIVHIGH, 0x00);//baud
+ outb(ports[i] | CP_LINE, CL_8BIT);
+ outb(ports[i] | CP_FIFO, 0xc7);//?
+ }
}
-void sout(char b) {
- if (error)
+typedef uint16_t serial_spin_t;
+
+void sout(enum serial_port n, uint8_t b) {
+ if (error[n])
return;
- uint16_t s = SERIAL_SPIN_LIMIT;
- while (!(inb(CP_1 | CP_LINE_S) & CLS_WRITE))
- if (!--s) {
- error = true;
+ serial_spin_t spinner = -1;
+ while (!(inb(ports[n] | CP_LINE_S) & CLS_WRITE))
+ if (--spinner) {
+ error[n] = true;
return;
}
- outb(CP_1 | CP_DATA, (uint8_t)b);
-}
-
-void soutsz(const char *s) {
- while (*s)
- sout(*(s++));
-}
-
-void soutsn(const char *s, uint8_t n) {
- while (n--)
- sout(*(s++));
+ outb(ports[n] | CP_DATA, b);
}
-char sin() {
- if (error)
+uint8_t sin(enum serial_port n) {
+ if (error[n])
return 0;
- while (!(inb(CP_1 | CP_LINE_S) & CLS_READ))
+ while (!(inb(ports[n] | CP_LINE_S) & CLS_READ))
;//spin
- return (char)inb(CP_1 | CP_DATA);
-}
-
-void sinsn(char *s, uint8_t n) {
- while (n--)
- *(s++) = sin();
+ return inb(ports[n] | CP_DATA);
} \ No newline at end of file