schedule the highest priority thread,overP1
[monosproject.git] / src / devices / input.c
blob4a12160ec721ec4bbeb7bc215ef6dd9afa0b37a8
1 #include "devices/input.h"
2 #include <debug.h>
3 #include "devices/intq.h"
4 #include "devices/serial.h"
6 /* Stores keys from the keyboard and serial port. */
7 static struct intq buffer;
9 /* Initializes the input buffer. */
10 void
11 input_init (void)
13 intq_init (&buffer);
16 /* Adds a key to the input buffer.
17 Interrupts must be off and the buffer must not be full. */
18 void
19 input_putc (uint8_t key)
21 ASSERT (intr_get_level () == INTR_OFF);
22 ASSERT (!intq_full (&buffer));
24 intq_putc (&buffer, key);
25 serial_notify ();
28 /* Retrieves a key from the input buffer.
29 If the buffer is empty, waits for a key to be pressed. */
30 uint8_t
31 input_getc (void)
33 enum intr_level old_level;
34 uint8_t key;
36 old_level = intr_disable ();
37 key = intq_getc (&buffer);
38 serial_notify ();
39 intr_set_level (old_level);
41 return key;
44 /* Returns true if the input buffer is full,
45 false otherwise.
46 Interrupts must be off. */
47 bool
48 input_full (void)
50 ASSERT (intr_get_level () == INTR_OFF);
51 return intq_full (&buffer);