pintos: Avoid literal control character in Perl variable name.
[pintos-anon] / src / devices / input.c
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. */
7 static struct intq buffer;
8
9 /* Initializes the input buffer. */
10 void
11 input_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. */
18 void
19 input_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. */
30 uint8_t
31 input_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. */
47 bool
48 input_full (void) 
49 {
50   ASSERT (intr_get_level () == INTR_OFF);
51   return intq_full (&buffer);
52 }