aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/tty/tty.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-03-02 23:05:26 +0000
committersotech117 <michael_foiani@brown.edu>2024-03-02 23:05:26 +0000
commit8c2e0ce946012a4275e8dfa9d8dfd1d5a68d6e3e (patch)
tree1877a33c6488a5b16fb7962e1ffb0f72f13a5052 /kernel/drivers/tty/tty.c
parent9c90e73fda0d5df2e1f11b32d459d3bb07a63192 (diff)
decent coding session
Diffstat (limited to 'kernel/drivers/tty/tty.c')
-rw-r--r--kernel/drivers/tty/tty.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/kernel/drivers/tty/tty.c b/kernel/drivers/tty/tty.c
index 3694877..c47a582 100644
--- a/kernel/drivers/tty/tty.c
+++ b/kernel/drivers/tty/tty.c
@@ -69,8 +69,29 @@ void tty_init()
*/
ssize_t tty_read(chardev_t *cdev, size_t pos, void *buf, size_t count)
{
- NOT_YET_IMPLEMENTED("DRIVERS: tty_read");
- return -1;
+ // NOT_YET_IMPLEMENTED("DRIVERS: tty_read");
+
+ // get the mapped tty
+ tty_t *tty = cd_to_tty(cdev);
+
+ // set the IPL to INTR_KEYBOARD
+ uint8_t prev_ipl = intr_setipl(INTR_KEYBOARD);
+
+ // lock the read mutex of the tty
+ kmutex_lock(&tty->tty_read_mutex);
+
+ // wait until there is something in the line discipline's buffer
+ ldisc_wait_read(&tty->tty_ldisc);
+
+ // read from the ldisc's buffer if there are new characters
+ ssize_t bytes_read = ldisc_read(&tty->tty_ldisc, buf, count);
+ // unlock the read mutex of the tty
+ kmutex_unlock(&tty->tty_read_mutex);
+
+ // revert the IPL
+ intr_setipl(prev_ipl);
+
+ return bytes_read;
}
/**
@@ -88,8 +109,27 @@ ssize_t tty_read(chardev_t *cdev, size_t pos, void *buf, size_t count)
*/
ssize_t tty_write(chardev_t *cdev, size_t pos, const void *buf, size_t count)
{
- NOT_YET_IMPLEMENTED("DRIVERS: tty_write");
- return -1;
+ // NOT_YET_IMPLEMENTED("DRIVERS: tty_write");
+
+ // get the mapped tty
+ tty_t *tty = cd_to_tty(cdev);
+
+ // set the IPL to INTR_KEYBOARD
+ uint8_t prev_ipl = intr_setipl(INTR_KEYBOARD);
+
+ // lock the write mutex of the tty
+ kmutex_lock(&tty->tty_write_mutex);
+
+ // write to the terminal
+ size_t bytes_written = vterminal_write(&tty->tty_vterminal, buf, count);
+
+ // unlock the write mutex of the tty
+ kmutex_unlock(&tty->tty_write_mutex);
+ // revert the IPL
+ intr_setipl(prev_ipl);
+
+
+ return bytes_written;
}
static void tty_receive_char_multiplexer(uint8_t c)