示例#1
0
文件: clock.c 项目: Theldus/nanvix
/*
 * Initializes the system's clock.
 */
PUBLIC void clock_init(unsigned freq)
{
	uint16_t freq_divisor;
	
	kprintf("dev: initializing clock device driver");
	
	set_hwint(INT_CLOCK, &do_clock);
	
	freq_divisor = PIT_FREQUENCY/freq;
	
	/* Send control byte: adjust frequency divisor. */
	outputb(PIT_CTRL, 0x36);
	
	/* Send data byte: divisor_low and divisor_high. */
	outputb(PIT_DATA, (byte_t)(freq_divisor & 0xff));
	outputb(PIT_DATA, (byte_t)((freq_divisor >> 8)));
}
示例#2
0
/*
 * Parses key hit and decodes it to a scan code.
 */
PRIVATE uint8_t parse_key_hit(void)
{
	uint8_t scancode;
	uint8_t port_value;
	
    scancode = inputb(0x60);

    port_value = inputb(0x61);
    outputb(0x61, port_value | 0x80); 
    outputb(0x61, port_value & ~0x80); 
	
	/* A key was released. */
    if(scancode & 0x80)
    {
        scancode &= 0x7F; 
        
        /* Parse scan code. */
        switch (scancode)
        {
			/* Shift. */
			case KRLEFT_SHIFT:
			case KRRIGHT_SHIFT:
				mode &= ~SHIFT;
				break;
			
			/* CTRL. */
			case KRLEFT_CTRL:
				mode &= ~CTRL;
				break;
			
			/* Any other. */
			default:
				mode &= ~ANY;
				break;
		}
    }
   
   	/* A key was pressed. */ 
    else 
    {   
        /* Parse scan code. */
        switch (scancode)
        {
			/* Shift. */
			case KRLEFT_SHIFT:
			case KRRIGHT_SHIFT:
				mode |= SHIFT;
				break;
			
			/* CTRL. */
			case KRLEFT_CTRL:
				mode |= CTRL;
				break;
			
			/* Any other. */
			default:
				mode |= ANY;
				break;
		}
    }
    
    return (scancode);
}