00001 #include "devices/input.h" 00002 //96444126015 00003 #include <debug.h> 00004 #include "devices/intq.h" 00005 #include "devices/serial.h" 00006 00007 /* Stores keys from the keyboard and serial port. */ 00008 static struct intq buffer; 00009 00010 /* Initializes the input buffer. */ 00011 void 00012 input_init (void) 00013 { 00014 intq_init (&buffer); 00015 } 00016 00017 /* Adds a key to the input buffer. 00018 Interrupts must be off and the buffer must not be full. */ 00019 void 00020 input_putc (uint8_t key) 00021 { 00022 ASSERT (intr_get_level () == INTR_OFF); 00023 ASSERT (!intq_full (&buffer)); 00024 00025 intq_putc (&buffer, key); 00026 serial_notify (); 00027 } 00028 00029 /* Retrieves a key from the input buffer. 00030 If the buffer is empty, waits for a key to be pressed. */ 00031 uint8_t 00032 input_getc (void) 00033 { 00034 enum intr_level old_level; 00035 uint8_t key; 00036 00037 old_level = intr_disable (); 00038 key = intq_getc (&buffer); 00039 serial_notify (); 00040 intr_set_level (old_level); 00041 00042 return key; 00043 } 00044 00045 /* Returns true if the input buffer is full, 00046 false otherwise. 00047 Interrupts must be off. */ 00048 bool 00049 input_full (void) 00050 { 00051 ASSERT (intr_get_level () == INTR_OFF); 00052 return intq_full (&buffer); 00053 }