Example #1
0
int kbd_test_scan_C(void) {
	int r;
	unsigned long data = 0, irq_set;
	int ipc_status;
	message msg;

	irq_set = kbd_subscribe_int();

	while (data != ESC_CODE){
		if ( r = driver_receive(ANY, &msg, &ipc_status) != 0 ) {
			printf("driver_receive failed with: %d", r);
			continue;}
		if (is_ipc_notify(ipc_status)) { /* received notification */
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE: /* hardware interrupt notification */
				if (msg.NOTIFY_ARG &BIT(irq_set)) {
					data = kbd_read_buff();
					if(BIT(7) & data)
						printf("Break code: 0x%2X", data);
					else
						printf("Make code: 0x%2X", data);
					printf("\n ----///---- \n");
				}break;
			default: break;
			}
		}
	}
	kbd_unsubscribe_int();
	return 0;
}
Example #2
0
int kbd_test_scan(unsigned short ass) {
	int irq_set = kbd_subscribe_int();
	int ipc_status;
	message msg;
	unsigned char result = 0;
	if (irq_set == ERROR) {
		printf("kbd_test_scan()::kernel call didn't return 0\n");
		return ERROR;
	}
	while (result != KEY_ESC) {
		if (driver_receive(ANY, &msg, &ipc_status) != OK) {
			printf("kbd_test_scan()::driver_receive failed\n");
			continue;
		}
		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set) {
					if (ass) {
						result = kbd_int_handler_asm();
					} else {
						result = kbd_int_handler_C();
					}
					if (result == KEY_ESC) {
						printf(
								"kbd_test_scan()::esc was pressed, press any key to continue\n");
					}
				}
				break;
			}
		}
	}
	kbd_unsubscribe_int();
	return 0;
}
Example #3
0
int test_scan(void) {
	int r;
	unsigned long data = 0, irq_set;
	irq_set = kbd_subscribe_int();
	int ipc_status;
	message msg;
	int i = 0;

	while (data != BREAK_ESC){
		if ( r = driver_receive(ANY, &msg, &ipc_status) != 0 ) {
			printf("driver_receive failed with: %d", r);
			continue;}
		if (is_ipc_notify(ipc_status)) { /* received notification */
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE: /* hardware interrupt notification */
				if (msg.NOTIFY_ARG &irq_set) {
					data = kbd_read_out();
					if(1 << 7 & data)
						printf("Break: 0x%X \n", data);
					else printf("Make: 0x%X \n", data);
				}break;
			default: break;
			}
		}
	}
	kbd_unsubscribe_int();
	return 0;
}
Example #4
0
int subscribe_all()
{
	if (timer_subscribe_int() == -1)
		return -1;

	if (kbd_subscribe_int() == -1)
	{
		timer_unsubscribe_int();
		return -1;
	}

	if (mouse_subscribe_int() == -1)
	{
		kbd_unsubscribe_int();
		timer_unsubscribe_int();
		return -1;
	}

	if (rtc_subscribe_int() == -1)
	{
		kbd_unsubscribe_int();
		timer_unsubscribe_int();
		mouse_unsubscribe_int();
		return -1;
	}

	if (sp1_subscribe_int() == -1)
	{
		kbd_unsubscribe_int();
		timer_unsubscribe_int();
		mouse_unsubscribe_int();
		rtc_unsubscribe_int();
		return -1;
	}

	if (sp2_subscribe_int() == -1)
	{
		kbd_unsubscribe_int();
		timer_unsubscribe_int();
		mouse_unsubscribe_int();
		rtc_unsubscribe_int();
		sp1_unsubscribe_int();
		return -1;
	}

	return 0;
}
Example #5
0
int test_line(unsigned short xi, unsigned short yi, 
		           unsigned short xf, unsigned short yf, unsigned long color) {
	
	char* video_mem = NULL;
	int failure =0;
	if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL)
	{
		printf("test_line(): vg_init() failed");
		return 1;
	}
	draw_line(video_mem,xi,yi, xf,yf,color);
	int kbd_irq_set = 0;
	if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts
		printf("test_line(): kbd_subscribe_int() failed \n");
		failure = 1;
	}
	int ipc_status;
	message msg;
	int r;
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & kbd_irq_set) { /* subscribed kbd interrupt */
						if(kbd_int_handler())
							failure = 1;
					}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
		} while(get_scancode() != ESC_BREAK && !failure);
	}
	if(kbd_unsubscribe_int()){//unsubscribe interrupts
		printf("test_square(): kbd_unsubscribe_int() failed\n");
		failure = 1;
	}
	printf("Done\n");

	if(vg_exit()){
		printf("test_line(): vg_exit() failed");
		return 1;
	}
	return failure;
	
}
Example #6
0
int kbd_test_leds(unsigned short n, unsigned short *toggle) {
	unsigned short led_status = 0;
	kbd_subscribe_int();
	unsigned int i = 0;
	for (i = 0; i < n; i++) {
		if (kbd_toggle_led(toggle[i], &led_status) != 0) {
			printf("kbd_test_leds()::led number %d doesn't exist\n", toggle[i]);
			continue;
		}
		printf("kbd_test_leds()::0x0%X ", led_status);
		printf("(caps lock = %s, scroll lock = %s, num lock = %s)\n",
				led_status & CAPS_LOCK ? "o" : " ",
				led_status & SCROLL_LOCK ? "o" : " ",
				led_status & NUM_LOCK ? "o" : " ");
		timer_wait(12 /* 12/60 = 200ms */);
	}
	kbd_unsubscribe_int();
	return 0;
}
Example #7
0
int kbd_test_timed_scan(unsigned short n){
	int r;
	unsigned long data = 0, irq_set_KBD, irq_set_TIMER;
	int ipc_status;
	message msg;
	unsigned long limit = 60 * n;

	irq_set_KBD = kbd_subscribe_int();
	irq_set_TIMER = timer_subscribe_int();

	while (data != ESC_CODE){
		if(/*get_counter() >= limit*/1){
			printf("Your time ran out!!!\n\n");
			break;
		}
		if ( r = driver_receive(ANY, &msg, &ipc_status) != 0 ) {
			printf("driver_receive failed with: %d", r);
			continue;}
		if (is_ipc_notify(ipc_status)) { /* received notification */
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE: /* hardware interrupt notification */
				if (msg.NOTIFY_ARG &BIT(irq_set_KBD)) {
					data = kbd_read_buff();
					if(BIT(7) & data)
						printf("Break code: 0x%2X", data);
					else
						printf("Make code: 0x%2X", data);
					printf("\n ----///---- \n");
					//reset_counter();
				}
				if (msg.NOTIFY_ARG &BIT(irq_set_TIMER)) {
					//timer_int_handler();
				}break;
			default: break;
			}
		}
	}
	kbd_unsubscribe_int();
	timer_unsubscribe_int();
	return 0;
}
Example #8
0
int kbd_test_timed_scan(unsigned short n) {
	int ipc_status;
	unsigned char result = 0;
	message msg;
	int kbd_interrupt = kbd_subscribe_int();
	int timer_interrupt = timer_subscribe_int();
	if (kbd_interrupt == ERROR || timer_interrupt == ERROR) {
		printf("kbd_test_timed_scan()::kernel call didn't return 0\n");
		return 1;
	}
	while (result != KEY_ESC && timer_count < n * 60) {
		if (driver_receive(ANY, &msg, &ipc_status) != OK) {
			printf("kbd_test_timed_scan()::driver_receive failed\n");
			continue;
		}
		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & timer_interrupt) {
					timer_int_handler();
					if (timer_count >= n * 60) {
						printf("kbd_test_timed_scan()::timed out\n");
					}
				}
				if (msg.NOTIFY_ARG & kbd_interrupt) {
					result = kbd_int_handler_C();
					if (result == KEY_ESC) {
						printf(
								"kbd_test_timed_scan()::esc was pressed, press any key to continue\n");
					}
				}
				break;
			}
		}
	}
	timer_unsubscribe_int();
	kbd_unsubscribe_int();
	return 0;
}
Example #9
0
int unsubscribe_all()
{
	if (timer_unsubscribe_int() != -1 && kbd_unsubscribe_int() != -1 && mouse_unsubscribe_int() != -1 && rtc_unsubscribe_int() != -1)
		return 0;
	return -1;
}
Example #10
0
int test_move(unsigned short xi, unsigned short yi, char *xpm[], 
				unsigned short hor, short delta, unsigned short time1)
{
	if(xpm == NULL)
		return 1;
	char* video_mem = NULL;
	int failure =0;
	int width, height;
	char* pix = NULL;
	if((pix = (char*) read_xpm(xpm, &width, &height)) == NULL)
		return 1;
	if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL)
	{
		printf("test_move(): vg_init() failed");
		return 1;
	}
	int kbd_irq_set = 0;
	int timer_irq_set=0;
	if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts
		printf("test_move(): kbd_subscribe_int() failed \n");
		failure = 1;
	}
	if((timer_irq_set = timer_subscribe_int()) < 0){//subscribe timer 0 interrupts
		printf("test_move(): timer_subscribe_int() failed \n");
		failure = 1;
	}
	int ipc_status;
	message msg;
	int r;
	double step = (double)delta/(time1*60);
	double xfp = xi;
	double yfp = yi;
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & kbd_irq_set)  /* subscribed kbd interrupt */
						if(kbd_int_handler())
							failure = 1;
					if(msg.NOTIFY_ARG & timer_irq_set){
						if(get_ticks() < time1 * 60){//enquanto tempo desjado nao passou
							timer_int_handler();
							blank_secondary_buf();//clear buffer
							draw_pixmap(get_secondary_buf(),(int) xfp, (int) yfp, height, width, pix);
							commit_to_video_mem();
							if(hor)
								xfp += step;//se movimento horizontal incrementar x
							else yfp +=step;//senao incrementar y
						}
					}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
		} while(get_scancode() != ESC_BREAK && !failure);
	}
	if(timer_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): timer_unsubscribe_int() failed\n");
		failure = 1;
	}
	if(kbd_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): kbd_unsubscribe_int() failed\n");
		failure = 1;
	}
	printf("Done\n");
	if(vg_exit()){
		printf("test_move(): vg_exit() failed");
		return 1;
	}
	return failure;
}