Esempio n. 1
0
File: kbc.c Progetto: DDuarte/cnix
int write_kbc(unsigned long port, unsigned char byte) { LOG
    unsigned long stat, counter = 0;

    while (counter < TIMEOUT_COUNTER) {
        if (sys_inb(STAT_REG, &stat) != 0) {
            printf("write_kbc: sys_inb failed.\n");
            return -1;
        }

        if(!(stat & IBF)) {
            if (sys_outb(port, byte) != 0) {
                printf("write_kbc: sys_outb failed.\n");
                return -1;
            }

            return 0;
        }

        if (tickdelay(micros_to_ticks(DELAY_US)) != 0) {
            printf("write_kbc: tickdelay failed.\n");
            return -1;
        }
        counter++;
    }

    printf("write_kbc: time out.\n");
    return -1;
}
Esempio n. 2
0
File: KBC.c Progetto: kissthink/os
int readKBCState() {
	unsigned long stat, data, counter = 0;

	while (counter < 3) {
		if (sys_inb(STAT_REG, &stat) != OK)
			return -1;

		if ((stat & (OBF | AUX)) != OK) {
			if (sys_inb(DATA_REG, &data) != OK)
				return -1;

			if ((stat & (PAR_ERR | TO_ERR)) == 0)
				return data;
			else if (data == 0xFC)
				return data;
			else if (data == 0xFE)
				return data;
			else
				return -1;

			break;
		}

		tickdelay(micros_to_ticks(DELAY_US));
		counter++;
	}

	return data;
}
Esempio n. 3
0
File: kbc.c Progetto: DDuarte/cnix
int read_kbc(void) { LOG
    unsigned long stat, data, counter = 0;

    while (counter < TIMEOUT_COUNTER) {
        if (sys_inb(STAT_REG, &stat) != 0) {
            printf("read_kbc: sys_inb (1) failed.\n");
            return -1;
        }

        if ((stat & (OBF | AUX)) != 0) {
            if (sys_inb(DATA_REG, &data) != 0) {
                printf("read_kbc: sys_inb (2) failed.\n");
                return -1;
            }

            if ((stat & (PAR_ERR | TO_ERR)) == 0)
                return data;
            else if (data == ERROR)
                return data;
            else if (data == REPEAT)
                return data;
            else
                return -1;
        }

        if (tickdelay(micros_to_ticks(DELAY_US)) != 0) {
            printf("read_kbc: tickdelay failed.\n");
            return -1;
        }
        counter++;
    }

    return -1;
}
Esempio n. 4
0
int writeToKBC(unsigned long reg, unsigned long cmd)
{
	unsigned long stat, r, data, i = 0;

	while(i < 3) // retry 3 times on time-out
	{
		r = sys_inb(STAT_REG, &stat);
		if (r != OK)
		{
			printf("sys_inb failed with: %d", r);
			return -1;
		}

		if ((stat & IBF) == 0)
		{
			r = sys_outb(reg, cmd);
			if (r != OK)
			{
				printf("sys_inb failed with: %d", r);
				return -1;
			}
			else return 0;
		}

		// gives the KBC or the keyboard enough-time to respond
		tickdelay(micros_to_ticks(DELAY_US));

		i++;
	}

	printf("writeToKBC failed: unable to write data\n");
	return -1;
}
Esempio n. 5
0
int test_config(void) {
	printf("\n\tTouch in the mouse\n\n");
	unsigned long data, res;
	unsigned char a[3];
	mouse_subscribe();
	mouse_write(MOUSE_STATUS);
	mouse_read(&data);
	while (1) {
		mouse_read(&data);
		if ((BIT(7) & data) && (BIT(3) & res))
			break;
	}
	a[0] = data;
	while (1) {
		mouse_read(&data);
		if (data <= 3)
			break;
	}
	a[1] = data;
	tickdelay(micros_to_ticks(DELAY_US));
	if (mouse_read(&data) != 0)
		return -1;
	a[2] = data;
	printf("\n\tCONFIGURATION\n");
	printf(
			"\tMode: %s\n\tEnable: %d\n\tScaling: %s\n\tLB: %d\n\tMB: %d\n\tRB: %d\n\tResolution: %d count/mm\n\tSample Rate: %d\n",
			MODE(a[0]) ? "Remote" : "Stream", ENABLE(a[0]),
			SCALING(a[0]) ? "1:1" : "2:1", LEFT(a[0]), MIDDLE(a[0]),
			RIGHT(a[0]), RESOLUTION(a[1]), RATE(a[2]));
	mouse_unsubscribe();
	printf("\n\tpress ANY KEY to continue\n");
	mouse_read(&res); /* clear out buffer */
}
Esempio n. 6
0
int mouse_write(unsigned char cmd) {
	unsigned long stat;
	int i = 0;

	for (i = 0; i < KBC_IO_MAX_TRIES; i++) {
		sys_outb(CMD_REG, WRITE_BYTE);
		tickdelay(micros_to_ticks(DELAY_US));
		sys_outb(IN_BUF, cmd); /* no args command */
		tickdelay(micros_to_ticks(DELAY_US));
		sys_inb(OUT_BUF, &stat); /* assuming it returns OK */

		if (stat == ACK) {
			return 0;
		}
	}
}
Esempio n. 7
0
int sendCMDtoKBD(unsigned long command) {
	int n = 0;
	unsigned long stat;

	for(;n<MAX_TRIES; n++) {
		if( sys_inb(BUF_STAT, &stat) == OK && (stat & ERR_IN_FULL) == 0 && sys_outb(BUF_IN, command) == OK) {
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY));}
	return -1;
}
Esempio n. 8
0
int send_cmd(unsigned long cmd){
	unsigned long stat = 0;
	unsigned long IBF = 0x0002;

	while( 1 ) {
		sys_inb(STAT_REG, &stat);
		if( (stat & IBF) == 0 ) {
			sys_outb(KBC_CMD_REG, cmd);
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 9
0
int kbc_write(unsigned char data) {
	unsigned char status = 0;
	int i;
	for (i = 0; i < 16; i++) {
		sys_inb(STAT_REG, (unsigned long *) &status);
		if ((status & IBF) == 0) {
			sys_outb(IN_BUF, data);
			return OK;
		}
		tickdelay(micros_to_ticks(DELAY));
	}
	return ERROR;
}
Esempio n. 10
0
int kbc_write(unsigned char cmd) {
	unsigned long stat;

	sys_inb(STAT_REG, &stat); /* assuming it returns OK */

	/* loop while 8042 input buffer is not empty */
	if ((stat & IBF) == 0) {
		sys_outb(IN_BUF, cmd); /* no args command */
		return 0;
	}
	tickdelay(micros_to_ticks(DELAY_US));
	return -1;
}
Esempio n. 11
0
int send_kbd(short cmd){
	unsigned long stat;
	while( 1 ) {
		sys_inb(STAT_REG, &stat);
		if(stat != OK)
			continue;
		if( (stat & IBF) == 0 ) {
			sys_outb(KBC_CMD_REG,cmd); /* no args command */
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 12
0
int ms_write(unsigned char port, unsigned char command) {
	unsigned long stat;
	while (1) {
		/* loop while 8042 input buffer is not empty */
		if (sys_inb(STAT_REG, &stat) != OK)
			return -1;

		if ((stat & IBF) == 0) {
			sys_outb(port, command); /* no args command */
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 13
0
int receive_kbd(){
	unsigned long stat;
	while( 1 ) {
			sys_inb(STAT_REG, &stat); /* assuming it returns OK */
			/* loop while 8042 output buffer is empty*/
			if( stat & OBF ) {
				sys_inb(OUT_BUF, &data); /* assuming it returns OK*/
				if ( (stat &(PAR_ERR | TO_ERR)) == 0 )
					return data;
				else
					return -1;
			}
			tickdelay(micros_to_ticks(DELAY_US));
		}
}
Esempio n. 14
0
int kbc_read(unsigned char *data) {
	unsigned char status = 0;
	int i;
	for (i = 0; i < 16; i++) {
		sys_inb(STAT_REG, (unsigned long *) &status);
		if ((status & OBF) != 0) {
			if (sys_inb(OUT_BUF, (unsigned long *) data) != OK) {
				return ERROR;
			}
			return OK;
		}
		tickdelay(micros_to_ticks(DELAY));
	}
	return ERROR;
}
Esempio n. 15
0
int mouse_read(unsigned long* val) {
	unsigned long read = 0;
	int i = 0;
	for (i = 0; i < KBC_IO_MAX_TRIES; i++) {
		sys_inb(STAT_REG, &read);
		if ((read & OBF) && (read & AUX)) {
			if (sys_inb(OUT_BUF, val) != 0) {
				return -1;
			}
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
	return -1;
}
Esempio n. 16
0
int ms_read() {
	unsigned long stat, key;
	int i = 0;
	while (i < 10) {
		if (sys_inb(STAT_REG, &stat) != OK)
			return -1;
		if (stat & OBF) {

			sys_inb(OUT_BUF, &key);
			return key;
		}
		tickdelay(micros_to_ticks(DELAY_US));
		i++;
	}
}
Esempio n. 17
0
int kbd_scan_c(int *apt){

	unsigned long key_register;

	//1 byte
	sys_inb(OUT_BUF, &key_register);
	*apt = (unsigned int) key_register;
	tickdelay(micros_to_ticks(DELAY_US));
	if (0xE0 == (0xE0 & *apt))
	{
		//2 bytes
		return 1;

	}
	return 0;
}
Esempio n. 18
0
int mouse_send_first_command(){

	unsigned long stat;


	while(1)
	{
		sys_inb(STAT_REG, &stat); /*assuming it returns OK*/
		/*loop while 8042 input buffer is not empty*/
		if ((stat & IBF) == 0)
		{
			sys_outb(STAT_REG, MC);
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 19
0
int kbc_cmd_send(unsigned long cmd){

	unsigned long stat = 0;
	unsigned long IBF = 0x0002; //to check if input buffer is full

	while(1)
	{
		sys_inb(STAT_REG, &stat); /*assuming it returns OK*/
		/*loop while 8042 input buffer is not empty*/
		if ((stat & IBF) == 0)
		{
			sys_outb(OUT_BUF, cmd);
			return 0;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 20
0
int kbd_interrupt_handler_read(){ //  reads the bytes from the KBC’s OUT_BUF
	unsigned long stat, key;

	while( 1 ) {
	if(sys_inb(STAT_REG, &stat) != OK)
		return -1;

	   if( stat & OBF ) {
	     sys_inb(OUT_BUF, &key); // assuming it returns OK
	   if ( (stat &(PAR_ERR | TO_ERR)) == 0 )
	     return key;
	    else
	     return -1;
	}
	   tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 21
0
int rec_cmd(){
	unsigned long stat = 0;
	unsigned long OBF = 0x0001;
	unsigned long data = 0;

	while( 1 ) {
		sys_inb(STAT_REG, &stat);
		if( stat & OBF ) {
			sys_inb(OUT_BUF, &data);
			if ( (stat &(PAR_ERR | TO_ERR)) == 0 )
				return data;
			else
				return -1;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 22
0
File: kbd.c Progetto: pedro93/LCOM
int read_keyboard()
{
while(1)
{
	sys_inb(STAT_REG,&stat); //assuming it returns OK

	if(stat & OBF)
	{
		sys_inb(OUT_BUF,&data); //assuming it returns OK

		if((stat&(PAR_ERR|TO_ERR))==0)
			return data;
		else
			return -1;
	}
	tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 23
0
int kbd_read_buff()
{
	unsigned long status;
	unsigned long data;

	while(1) {
		status = get_kbd_status();//read KBD status
		//Looping while outBuffer empty
		if( status & ERR_OUT_FULL ) {
			sys_inb(BUF_OUT, &data); /* assuming it returns OK */
			if ( (status &(ERR_PAR | ERR_TOUT)) == 0 )
				return data;
			else
				return -1;
		}
		tickdelay(micros_to_ticks(DELAY));
	}
}
Esempio n. 24
0
File: KBC.c Progetto: kissthink/os
int writeToKBC(unsigned long port, unsigned char byte) {
	unsigned long stat;

	while (1) {
		if (sys_inb(STAT_REG, &stat) != OK)
			return -1;

		if ((stat & IBF) == 0) {
			if (sys_outb(port, byte) != OK)
				return -1;

			break;
		}

		tickdelay(micros_to_ticks(DELAY_US));
	}

	return 0;
}
Esempio n. 25
0
unsigned long readFromKBC(int ass)
{
	unsigned long stat, r, data, i = 0;

	if (ass == 0)
	{
		data = readFromKBC_asm();
		return  data;
	}

	while(i < 3) // retry 3 times on time-out
	{
		r = sys_inb(STAT_REG, &stat);
		if (r != OK)
		{
			printf("\treadFromKBC() in KBC.c: sys_inb failed with: %d", r);
			return -1;
		}

		if (stat & OBF)
		{
			r = sys_inb(OUT_BUF, &data);
			if (r != OK)
			{
				printf("\treadFromKBC() in KBC.c: sys_inb failed with: %d", r);
				return -1;
			}

			if ((stat & (PAR_ERR | TO_ERR)) == 0)
				return data;
			else
				return -1;
		}

		// gives the KBC or the keyboard enough-time to respond
		tickdelay(micros_to_ticks(DELAY_US));

		i++;
	}

	return -1;
}
Esempio n. 26
0
int kbc_cmd_receive(){

	unsigned long stat = 0;
	unsigned long OBF = 0x0001; //to check if output buffer is full
	unsigned long data = 0;

	while(1)
	{
		sys_inb(STAT_REG, &stat); /*assuming it returns OK*/
		/*loop while 8042 input buffer is not empty*/
		if (stat & OBF)
		{
			sys_inb(OUT_BUF, &data); /*assuming it returns OK*/

			if ((stat & (PAR_ERR | TO_ERR)) == 0)
				return data;
			else
				return -1;
		}
		tickdelay(micros_to_ticks(DELAY_US));
	}
}
Esempio n. 27
0
int kbc_read() {
	unsigned long stat, data;
	int kbc_tries = 0;
	while (kbc_tries < KBC_IO_MAX_TRIES) {
		sys_inb(STAT_REG, &stat); /* assuming it returns OK */
		/* loop while 8042 output buffer is empty */
		if (stat & OBF) {
			sys_inb(OUT_BUF, &data); /* assuming it returns OK */
			if ((stat & (PAR_ERR | TO_ERR)) == 0)
				return data;
			else if (data == ERROR)
				return data;
			else if (data == RESEND)
				return data;
			else
				return -1;
		}
		tickdelay(micros_to_ticks(DELAY_US));
		kbc_tries++;
	}
	return -1;
}
Esempio n. 28
0
int kbc_read(){
	unsigned long stat;
	unsigned long data;
	int tries = 0;

	while(tries < 3) {

		if(sys_inb(STAT_REG, &stat) != OK)
		{
			return -1;
		}

		if(stat & OBF) {

			if ( (stat &(PAR_ERR | TO_ERR)) == 0 && sys_inb(OUT_BUF, &data) == OK)
				return data;
			else
				return -1;
		}
		tickdelay(micros_to_ticks(DELAY_US));
		tries++;
	}
}
Esempio n. 29
0
int game_handling(deck* d) {
	int i;
	int turned = 0;

	if (scancode == 0x9e) {
		for (i = 0; i < 11; i++) {
			vg_draw(d->cards[j]->card_paths[i], d->cards[j]->height,
					d->cards[j]->width, d->posx[j], d->posy[j]);
			tickdelay(micros_to_ticks(DELAY_US));
		}
		d->cards[j]->selected = 1;
	}

	else if (scancode == 0x83 || scancode == 0x81) {
		game_over = 1;
		vg_exit();
	}

	//Press right
	else if (scancode == 0xcd) {
		if (d->cards[j]->selected == 0) {
			vg_draw(d->cards[j]->card_paths[0], d->cards[j]->height,
					d->cards[j]->width, d->posx[j], d->posy[j]);
		}
		j++;

		do {
			if (j == d->num_cards) {
				j = 0;
			}
			if (d->cards[j]->selected == 1)
				j++;
		} while (d->cards[j]->selected == 1);

		vg_draw("/usr/src/drivers/proj/images/image_selected.mg",
				d->cards[j]->height, d->cards[j]->width, d->posx[j],
				d->posy[j]);
	}

	//Press left
	else if (scancode == 0xcb) {
		if (d->cards[j]->selected == 0) {
			vg_draw(d->cards[j]->card_paths[0], d->cards[j]->height,
					d->cards[j]->width, d->posx[j], d->posy[j]);
		}
		j--;

		do {
			if (j == -1) {
				j = d->num_cards - 1;
			}
			if (d->cards[j]->selected == 1)
				j--;
		} while (d->cards[j]->selected == 1);

		vg_draw("/usr/src/drivers/proj/images/image_selected.mg",
				d->cards[j]->height, d->cards[j]->width, d->posx[j],
				d->posy[j]);
	}

	//Press up
	else if (scancode == 0xc8) {
		if (j >= d->num_cards / 2) {
			if (d->cards[j]->selected == 0) {
				vg_draw(d->cards[j]->card_paths[0], d->cards[j]->height,
						d->cards[j]->width, d->posx[j], d->posy[j]);
			}
			j -= 5;

			if (d->cards[j]->selected == 0) {
				vg_draw("/usr/src/drivers/proj/images/image_selected.mg",
						d->cards[j]->height, d->cards[j]->width, d->posx[j],
						d->posy[j]);
			}
		}
	}

	//Press down
	else if (scancode == 0xd0) {
		if (j < d->num_cards / 2) {
			if (d->cards[j]->selected == 0) {
			vg_draw(d->cards[j]->card_paths[0], d->cards[j]->height,
					d->cards[j]->width, d->posx[j], d->posy[j]);
			}
			j += 5;

			if (d->cards[j]->selected == 0) {
				vg_draw("/usr/src/drivers/proj/images/image_selected.mg",
						d->cards[j]->height, d->cards[j]->width, d->posx[j],
						d->posy[j]);
			}
		}
	}

}