summaryrefslogtreecommitdiffstats
path: root/pintos-progos/devices/input.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/devices/input.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/devices/input.c')
-rw-r--r--pintos-progos/devices/input.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/pintos-progos/devices/input.c b/pintos-progos/devices/input.c
new file mode 100644
index 0000000..4a12160
--- /dev/null
+++ b/pintos-progos/devices/input.c
@@ -0,0 +1,52 @@
1#include "devices/input.h"
2#include <debug.h>
3#include "devices/intq.h"
4#include "devices/serial.h"
5
6/* Stores keys from the keyboard and serial port. */
7static struct intq buffer;
8
9/* Initializes the input buffer. */
10void
11input_init (void)
12{
13 intq_init (&buffer);
14}
15
16/* Adds a key to the input buffer.
17 Interrupts must be off and the buffer must not be full. */
18void
19input_putc (uint8_t key)
20{
21 ASSERT (intr_get_level () == INTR_OFF);
22 ASSERT (!intq_full (&buffer));
23
24 intq_putc (&buffer, key);
25 serial_notify ();
26}
27
28/* Retrieves a key from the input buffer.
29 If the buffer is empty, waits for a key to be pressed. */
30uint8_t
31input_getc (void)
32{
33 enum intr_level old_level;
34 uint8_t key;
35
36 old_level = intr_disable ();
37 key = intq_getc (&buffer);
38 serial_notify ();
39 intr_set_level (old_level);
40
41 return key;
42}
43
44/* Returns true if the input buffer is full,
45 false otherwise.
46 Interrupts must be off. */
47bool
48input_full (void)
49{
50 ASSERT (intr_get_level () == INTR_OFF);
51 return intq_full (&buffer);
52}