PKUOS - Pintos
Pintos source browser for PKU Operating System course
input.c
Go to the documentation of this file.
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
12{
14}
15
16/** Adds a key to the input buffer.
17 Interrupts must be off and the buffer must not be full. */
18void
20{
23
24 intq_putc (&buffer, key);
26}
27
28/** Retrieves a key from the input buffer.
29 If the buffer is empty, waits for a key to be pressed. */
32{
33 enum intr_level old_level;
34 uint8_t key;
35
36 old_level = intr_disable ();
37 key = intq_getc (&buffer);
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
49{
51 return intq_full (&buffer);
52}
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
Definition: debug.h:31
void input_init(void)
Initializes the input buffer.
Definition: input.c:11
static struct intq buffer
Stores keys from the keyboard and serial port.
Definition: input.c:7
uint8_t input_getc(void)
Retrieves a key from the input buffer.
Definition: input.c:31
bool input_full(void)
Returns true if the input buffer is full, false otherwise.
Definition: input.c:48
void input_putc(uint8_t key)
Adds a key to the input buffer.
Definition: input.c:19
enum intr_level intr_disable(void)
Disables interrupts and returns the previous interrupt status.
Definition: interrupt.c:104
enum intr_level intr_get_level(void)
Returns the current interrupt status.
Definition: interrupt.c:65
enum intr_level intr_set_level(enum intr_level level)
Enables or disables interrupts as specified by LEVEL and returns the previous interrupt status.
Definition: interrupt.c:81
intr_level
Interrupts on or off?
Definition: interrupt.h:9
@ INTR_OFF
Interrupts disabled.
Definition: interrupt.h:10
uint8_t intq_getc(struct intq *q)
Removes a byte from Q and returns it.
Definition: intq.c:38
void intq_putc(struct intq *q, uint8_t byte)
Adds BYTE to the end of Q.
Definition: intq.c:61
void intq_init(struct intq *q)
Initializes interrupt queue Q.
Definition: intq.c:11
bool intq_full(const struct intq *q)
Returns true if Q is full, false otherwise.
Definition: intq.c:28
void serial_notify(void)
The fullness of the input buffer may have changed.
Definition: serial.c:148
unsigned char uint8_t
Definition: stdint.h:20
A circular queue of bytes.
Definition: intq.h:25