summaryrefslogtreecommitdiff
path: root/kernel/serial.c
diff options
context:
space:
mode:
authorJake Mannens <jake72360@gmail.com>2018-09-01 02:27:36 +1000
committerJake Mannens <jake72360@gmail.com>2018-09-01 02:27:36 +1000
commit6d87016287ea76afbdf7e16fb2cf9e4fa20cc0de (patch)
tree9c2ed07925bc89ff3da3d275a6d29d80bb91d955 /kernel/serial.c
parent307eaac66d378c1f6150519123ec1204277464d9 (diff)
Removed the sys_puts system call in favour of calls to tty_write().
Removed the rsputs() function in favour of calls to tty_write(). Corrected a bug in the serial driver and TTY subsystem where a full buffer wouldn't be detected. This was caused by a missing set of brackets on several operations involving the modulus operator. Added the ability for the serial driver to automatically take data from the TTY device's write buffer and push it to the serial port. This can happen in one of two ways; 1) the TTY subsystem notifies the serial driver of new data by calling the write() function pointer in the tty_struct or, 2) the serial port issues an interrupt signalling that it has finished sending data prompting the driver to check the buffers for any more pending data.
Diffstat (limited to 'kernel/serial.c')
-rw-r--r--kernel/serial.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/kernel/serial.c b/kernel/serial.c
index a133865..e712e53 100644
--- a/kernel/serial.c
+++ b/kernel/serial.c
@@ -11,6 +11,9 @@
/* 115200 baud */
#define DIVISOR 1
+/* this shouldn't change */
+#define FIFOSZ 16
+
#define RSBASE 0x3F8
#define RSDATA RSBASE
@@ -23,9 +26,6 @@
#define RSMODEMS (RSBASE + 6)
#define RSSCRATCH (RSBASE + 7)
-#define rswait()\
- while((inb(RSLINES) & 0x20) == 0);
-
extern void rs_isr(void);
/* internal function prototypes */
@@ -38,25 +38,6 @@ struct tty_struct tty_rs = {
static char present;
-int rsputs(char *s) {
- if(!present)
- return -ENXIO;
-
- while(*s) {
- rswait();
- if(*s == '\n' || *s == '\r') {
- outb(RSDATA, '\n');
- rswait();
- outb(RSDATA, '\r');
- s++;
- } else {
- outb(RSDATA, *s++);
- }
- }
-
- return 0;
-}
-
void serial_init(void) {
present = 0;
@@ -91,7 +72,6 @@ void serial_init(void) {
register_isr(0x24, 0, &rs_isr);
irq_enable(0x10);
- rsputs("[kernel] Serial monitor initialized!\n\r");
printk("[rs] Serial port COM0 initialized!\n");
present = 1;
@@ -102,22 +82,46 @@ void rsint_rx(void) {
if((inb(RSLINES) & 1) == 0)
return;
- if(q->pwrite == (q->pread - 1 % sizeof(q->buf)))
+ if(q->pwrite == ((q->pread - 1) % sizeof(q->buf)))
return;
q->buf[q->pwrite] = inb(RSDATA);
- q->pwrite = q->pwrite + 1 % sizeof(q->buf);
+ q->pwrite = (q->pwrite + 1) % sizeof(q->buf);
wake_up(&q->waiting);
}
+/*
+ * void rsint_tx(void) {
+ * int copied = 0;
+ * struct tty_queue *q = &tty_rs.wqueue;
+ *
+ * while(q->pread != q->pwrite) {
+ * [> we're done if the TX FIFO is full <]
+ * if((inb(RSLINES) & 0x20) == 0)
+ * break;
+ *
+ * outb(RSDATA, q->buf[q->pread]);
+ * q->pread = (q->pread + 1) % TTY_BUF_SIZE;
+ *
+ * copied = 1;
+ * }
+ *
+ * if(copied)
+ * wake_up(&q->waiting);
+ * }
+ */
+
void rsint_tx(void) {
+ int i;
int copied = 0;
struct tty_queue *q = &tty_rs.wqueue;
- while(q->pread != q->pwrite) {
- /* we're done if the TX FIFO is full */
- if((inb(RSLINES) & 0x20) == 0)
+ if((inb(RSLINES) & 0x20) == 0)
+ return;
+
+ for(i = 0; i < FIFOSZ; i++) {
+ if(q->pread == q->pwrite)
break;
outb(RSDATA, q->buf[q->pread]);