예제 #1
0
파일: main.c 프로젝트: AgamAgarwal/minix
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(int argc, char *argv[])
{
	message m_out;
	int r, ipc_status;
	size_t size;

	/* SEF local startup. */
	env_setargs(argc, argv);
	sef_local_startup();

	for (;;) {
		/* Wait for request. */
		if(driver_receive(ANY, &m_in, &ipc_status) != OK) {
			panic("driver_receive failed");
		}

#if DEBUG2
		printf("Filter: got request %d from %d\n",
			m_in.m_type, m_in.m_source);
#endif

		if(m_in.m_source == DS_PROC_NR && is_ipc_notify(ipc_status)) {
			ds_event();
			continue;
		}

		who_e = m_in.m_source;
		req_id = m_in.BDEV_ID;
		grant_id = m_in.BDEV_GRANT;
		size = 0;

		/* Forword the request message to the drivers. */
		switch(m_in.m_type) {
		case BDEV_OPEN:		/* open/close is a noop for filter. */
		case BDEV_CLOSE:	r = OK;				break;
		case BDEV_READ:		r = do_rdwt(FLT_READ);		break;
		case BDEV_WRITE:	r = do_rdwt(FLT_WRITE);		break;
		case BDEV_GATHER:	r = do_vrdwt(FLT_READ);		break;
		case BDEV_SCATTER:	r = do_vrdwt(FLT_WRITE);	break;
		case BDEV_IOCTL:	r = do_ioctl(&m_in);		break;

		default:
			printf("Filter: ignoring unknown request %d from %d\n", 
				m_in.m_type, m_in.m_source);
			continue;
		}

#if DEBUG2
		printf("Filter: replying with code %d\n", r);
#endif

		/* Send back reply message. */
		m_out.m_type = BDEV_REPLY;
		m_out.BDEV_ID = req_id;
		m_out.BDEV_STATUS = r;
		send(who_e, &m_out);
	}

	return 0;
}
예제 #2
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;
}
예제 #3
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;
}
예제 #4
0
파일: test4.c 프로젝트: joaofidalgo23/LCOM
int test_gesture(short length, unsigned short tolerance) {
	int ipc_status;
	message msg;
	int receive;
	int validation = 1;
	sumOfX = 0;
	int irq_set = mouse_subscribe();
	unsigned long clean;
	counter = 0;
	interrupts = 0;
	while (validation) {
		receive = driver_receive(ANY, &msg, &ipc_status);
		if (receive != 0) {
			printf("driver_receive failed with: %d", receive);
			continue;
		}

		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set) {
					validation = gesture_handler(length, tolerance);
				}
				break;
			default:
				break;
			}
		} else {
		}
	}
	mouse_unsubscribe();
	printf("\n\tpress ANY KEY to continue\n");
	mouse_read(&clean); //Clean the buffer
	return 0;
}
예제 #5
0
int timer_test_int(unsigned long time) {
	if (timer_subscribe_int())
	{
		return 1;
	}
	int r, ipc_status;
	message msg;
	time_counter = 0;
	while (time_counter <= time * TIMER_DEFAULT_FREQ)
	{
		/* 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 & BIT(TIMER0_HOOK_BIT)) { /////// /* subscribed interrupt */
					timer_int_handler();
					if(time_counter % TIMER_DEFAULT_FREQ == 0)
					{
						printf("Segundos decorridos: %d\n", time_counter / TIMER_DEFAULT_FREQ);
					}
				}
				break;
			default:
				break; /* no other notifications expected: do nothing */
			}
		} else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
	}
	return timer_unsubscribe_int();
}
예제 #6
0
int test_date()
{
	int ipc_status;
	message msg;
	unsigned int i=0;
	unsigned rtc_hook_id;
	rtc_subscribe_int(&rtc_hook_id);

	while(1)
	{
		if (driver_receive(ANY, &msg, &ipc_status) != 0)
		{
			if (is_ipc_notify(ipc_status))
			{ /* received notification */
				switch (_ENDPOINT_P(msg.m_source))
				{
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & (1 << RTC_HOOK))
					{ /* subscribed interrupt */
						i++;
					}
					break;
				default:
					break;
				}
			}
		}
	}

	rtc_unsubscribe_int(rtc_hook_id);
	sys_outb(RTC_ADDR_REG, RTC_CTRL_REG_B); ///
}
예제 #7
0
파일: test4.c 프로젝트: joaofidalgo23/LCOM
int test_packet(unsigned short cnt) {
	int i = 0;
	int ipc_status;
	message msg;
	int receive;
	int irq_set = mouse_subscribe();
	unsigned long clean;
	counter = 0;
	interrupts = 0;
	while (i < cnt * 3) {
		receive = driver_receive(ANY, &msg, &ipc_status);
		if (receive != 0) {
			printf("driver_receive failed with: %d", receive);
			continue;
		}

		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set) {
					mouse_handler();
					i++;
				}
				break;
			default:
				break;
			}
		} else {
		}
	}
	mouse_unsubscribe();
	printf("\n\tpress ANY KEY to continue\n");
	mouse_read(&clean); //Clean the buffer
	return 0;
}
예제 #8
0
int test_square(unsigned short x, unsigned short y, unsigned short size, unsigned long color) {
	vg_init(GRAPHIC_MODE);

	int ipc_status;
	message msg;
	int request;
	int irq_set;

	irq_set = subscribe_kbd();

	while (scanCode != EXIT_MAKE_CODE) {
		request = driver_receive(ANY, &msg, &ipc_status);
		if (request != 0) {
			printf("driver_receive failed with: %d", request);
			continue;
		}
		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set) {
					kbd_handler();
				}
				vg_draw_rectangle(x,y,size,size,color);
				break;
			default:
				break;
			}
		}
		else {
		}
	}
	unsubscribe_kbd();
	vg_exit();
	return 0;
}
예제 #9
0
파일: test4.c 프로젝트: jpamorim/feup-lcom
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;
}
예제 #10
0
파일: dp.c 프로젝트: Spenser309/CS551
/*
**  Name:	int dpeth_task(void)
**  Function:	Main entry for dp task
*/
PUBLIC int main(int argc, char **argv)
{
  message m;
  int ipc_status;
  int rc;

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  while (TRUE) {
	if ((rc = netdriver_receive(ANY, &m, &ipc_status)) != OK){
		panic(RecvErrMsg, rc);
	}

	DEBUG(printf("eth: got message %d, ", m.m_type));

	if (is_ipc_notify(ipc_status)) {
		switch(_ENDPOINT_P(m.m_source)) {
			case CLOCK:
				/* to be defined */
				do_watchdog(&m);
				break;
			case HARDWARE:
				/* Interrupt from device */
				handle_hw_intr();
				break;
			case TTY_PROC_NR:
				/* Function key pressed */
				do_dump(&m);
				break;
			default:	
				/* Invalid message type */
				panic(TypeErrMsg, m.m_type);
				break;
		}
		/* message processed, get another one */
		continue;
	}

	switch (m.m_type) {
	    case DL_WRITEV_S:	/* Write message to device */
		do_vwrite_s(&m);
		break;
	    case DL_READV_S:	/* Read message from device */
		do_vread_s(&m);
		break;
	    case DL_CONF:	/* Initialize device */
		do_init(&m);
		break;
	    case DL_GETSTAT_S:	/* Get device statistics */
		do_getstat_s(&m);
		break;
	    default:		/* Invalid message type */
		panic(TypeErrMsg, m.m_type);
		break;
	}
  }
  return OK;			/* Never reached, but keeps compiler happy */
}
예제 #11
0
파일: test3.c 프로젝트: mgpsp/LCOM-FEUP
int kbd_test_timed_scan(unsigned short n)
{
	int ipc_status, r, exit = 0, max, counter = 0, flag = 0;
	unsigned long irq1, irq2, data;
	message msg;

	irq2 = subscribe_int(TIMER0_IRQ, IRQ_REENABLE, &timer0_id);
	irq1 = subscribe_int(KB_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &kb_id);
	if (irq1 == -1 || irq2 == -1) return -1;  // check if subscribe_int failed

	max = n*60;

	do
	{
		r = driver_receive(ANY, &msg, &ipc_status);
		if (r != 0)
		{
			printf("driver_receive failed with: %d", r);
			continue;
		}

		if (is_ipc_notify(ipc_status))
		{
			switch (_ENDPOINT_P(msg.m_source))
			{
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq1)
				{
					counter = 0;
					data = keyboard_handler(0);
					flag = print_scancodes(data, flag);
					if (data == ESC)
					{
						printf("Done\n");
						exit = 1;
					}
				}
				if (msg.NOTIFY_ARG & irq2)
				{
					counter++;
					if (counter >= max)
					{
						printf("Done\n");
						exit = 1;
					}
				}
				break;
			default:
				break;
			}
		}
	} while (exit == 0);

	unsubscribe_int(&kb_id);
	unsubscribe_int(&timer0_id);

	return 0;
}
예제 #12
0
int start() {
	unsigned short character = 0x00;
	int ipc_status;
	message msg;
	int irq_set_kb = kb_subscribe_int();
	int irq_set_timer = timer_subscribe_int();
	int irq_set_mouse = mouse_subscribe_int();
	int r;
	unsigned char packet[3];
	unsigned short counter = 0;

	space_invaders_font = font_init("spaceinvader_font_transparent.bmp");
	srand(1);
	options_load();
	mouse_init();
	init_state();
	highscore_load();
	vg_init(VBE_VIDEO_MODE);

	while (1) { //TODO change condition
		/* 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 & irq_set_kb) { /* keyboard interrupt */
					character = kb_int_handler();
					if (character != KB_2BYTE_SCODE)
						kb_event_handler(character);
				}
				if (msg.NOTIFY_ARG & irq_set_mouse){ /* mouse interrupt */
					mouse_int_handler(counter, packet);
					if(packet[0] != MOUSE_ACK && (packet[0] & BIT(3)))
						counter++;
					if(counter == 3){
						counter = 0;
						mouse_event_handler(packet);
					}

				}
				if (msg.NOTIFY_ARG & irq_set_timer){ /* timer interrupt */
					timer_int_handler();
				}
				break;
			default:
				break; /* no other notifications expected: do nothing */
			}
		}
		else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
	}

	return 0;
}
예제 #13
0
int main_menu()
{
	continue_condition = true;
	fade_condition = false;
	function_to_call = NULL;
	darken = 127;
	int failure = 0;
	initialize_main_menu_buttons();
	int ipc_status;
	message msg;
	int r;
	char * display_name = (char*)malloc(sizeof(char) * strlen("Player name: ")+MAX_PLAYER_NAME_LENGTH);
	strcpy(display_name, "Player name: ");
	display_name = strcat(display_name, get_program_playername());
	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 & get_kbd_irq_set()){  /* subscribed kbd interrupt */
						kbd_int_handler();
					}
					if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */
						if(rtc_ih())
							failure = 1;
						getDateString(get_date_str_ptr());
					}
					if(msg.NOTIFY_ARG & get_timer_irq_set()){
						timer_int_handler();
						main_menu_render();
					}
					if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */
						mouse_int_handler();
				}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
			if(mouse_is_updated())
			{
				assign_mouse(get_previous_mouse(), get_mouse());
				assign_mouse(get_mouse(), get_mouse_state());
				main_menu_mouse_event(get_previous_mouse(), get_mouse());
				move_cursor(get_cursor(), get_mouse()->coords);
			}
		} while(continue_condition);
	}
	return failure;
}
예제 #14
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;
	
}
예제 #15
0
파일: main.c 프로젝트: Spenser309/CS551
int main(void)
{
	int r;
	message m;
	int ipc_status;

	/* SEF local startup. */
	sef_local_startup();

	for(;;)
	{
		r= driver_receive(ANY, &m, &ipc_status);
		if (r < 0)
		{
			printf("PCI: driver_receive failed: %d\n", r);
			break;
		}

		if (is_ipc_notify(ipc_status)) {
			printf("PCI: got notify from %d\n", m.m_source);

			/* done, get a new message */
			continue;
		}

		switch(m.m_type)
		{
		case BUSC_PCI_INIT: do_init(&m); break;
		case BUSC_PCI_FIRST_DEV: do_first_dev(&m); break;
		case BUSC_PCI_NEXT_DEV: do_next_dev(&m); break;
		case BUSC_PCI_FIND_DEV: do_find_dev(&m); break;
		case BUSC_PCI_IDS: do_ids(&m); break;
		case BUSC_PCI_DEV_NAME: do_dev_name(&m); break;
		case BUSC_PCI_RESERVE: do_reserve(&m); break;
		case BUSC_PCI_ATTR_R8: do_attr_r8(&m); break;
		case BUSC_PCI_ATTR_R16: do_attr_r16(&m); break;
		case BUSC_PCI_ATTR_R32: do_attr_r32(&m); break;
		case BUSC_PCI_ATTR_W8: do_attr_w8(&m); break;
		case BUSC_PCI_ATTR_W16: do_attr_w16(&m); break;
		case BUSC_PCI_ATTR_W32: do_attr_w32(&m); break;
		case BUSC_PCI_RESCAN: do_rescan_bus(&m); break;
		case BUSC_PCI_DEV_NAME_S: do_dev_name_s(&m); break;
		case BUSC_PCI_SLOT_NAME_S: do_slot_name_s(&m); break;
		case BUSC_PCI_SET_ACL: do_set_acl(&m); break;
		case BUSC_PCI_DEL_ACL: do_del_acl(&m); break;
		case BUSC_PCI_GET_BAR: do_get_bar(&m); break;
		default:
			printf("PCI: got message from %d, type %d\n",
				m.m_source, m.m_type);
			break;
		}
	}

	return 0;
}
예제 #16
0
파일: rtl8169.c 프로젝트: Ga-vin/MINIX3
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(int argc, char *argv[])
{
	int r;
	int ipc_status;

	/* SEF local startup. */
	env_setargs(argc, argv);
	sef_local_startup();

	while (TRUE) {
		if ((r = netdriver_receive(ANY, &m, &ipc_status)) != OK)
			panic("netdriver_receive failed: %d", r);

		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(m.m_source)) {
			case CLOCK:
				/*
				 * Under MINIX, synchronous alarms are used
				 * instead of watchdog functions.
				 * The approach is very different: MINIX VMD
				 * timeouts are handled within the kernel
				 * (the watchdog is executed by CLOCK), and
				 * notify() the driver in some cases. MINIX
				 * timeouts result in a SYN_ALARM message to
				 * the driver and thus are handled where they
				 * should be handled. Locally, watchdog
				 * functions are used again.
				 */
				rl_watchdog_f(NULL);
				break;
			case HARDWARE:
				do_hard_int();
				if (int_event_check) {
					check_int_events();
				}
				break ;
			default:
				panic("illegal notify from: %d",	m.m_type);
			}

			/* done, get nwe message */
			continue;
		}

		switch (m.m_type) {
		case DL_WRITEV_S:	rl_writev_s(&m, FALSE);	 break;
		case DL_READV_S:	rl_readv_s(&m, FALSE);	 break;
		case DL_CONF:		rl_init(&m);		 break;
		case DL_GETSTAT_S:	rl_getstat_s(&m);	 break;
		default:
			panic("illegal message: %d", m.m_type);
		}
	}
}
예제 #17
0
파일: sb16_dsp.c 프로젝트: Spenser309/CS551
/*===========================================================================*
 *				main
 *===========================================================================*/
PUBLIC int main(int argc, char *argv[]) 
{	
	int r;
	endpoint_t caller;
	int proc_nr;
	message mess;
	int ipc_status;

	/* SEF local startup. */
	sef_local_startup();

	while(TRUE) {
		/* Wait for an incoming message */
		driver_receive(ANY, &mess, &ipc_status);

		caller = mess.m_source;
		proc_nr = mess.IO_ENDPT;

		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(mess.m_source)) {
				case HARDWARE:
					dsp_hardware_msg();
					continue; /* don't reply */
				default:
					r = EINVAL;
			}

			/* dont with this message */
			goto send_reply;
		}

		/* Now carry out the work. */
		switch(mess.m_type) {
			case DEV_OPEN:		r = dsp_open();	break;
			case DEV_CLOSE:		r = dsp_close(); break;
#ifdef DEV_IOCTL
			case DEV_IOCTL:		r = dsp_ioctl(&mess); break;
#endif
#ifdef DEV_READ

			case DEV_READ:		r = EINVAL; break; /* Not yet implemented */
			case DEV_WRITE:		dsp_write(&mess); continue; /* don't reply */
#endif
			
			case DEV_STATUS:	dsp_status(&mess); continue; /* don't reply */
			default:			r = EINVAL;
		}

send_reply:
		/* Finally, prepare and send the reply message. */
		reply(TASK_REPLY, caller, proc_nr, r);
	}

}
예제 #18
0
파일: interupts.c 프로젝트: pedro93/LCOM
//Interrupt receptor
void interupt_handler(int time)
{
	int ipc_status;
	message msg;
	//int irq_set=timer_subscribe_int();
	int error;
	//ligar RTC
	unsigned long regB;
	counter = 0;
	regB = read_rtc(RTC_REG_B);
	regB = regB ^ RTC_UIE;
	write_rtc(RTC_REG_B,regB);

	while(counter<(time*60) && check_number_of_tries()==0) {
		/* Get a request message. */
		error = driver_receive(ANY, &msg, &ipc_status);
		if (error != 0 ) {
			printf("driver_receive failed with: %d",error);
			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(0)) && (counter%60==0)) //subscribed interruptTimer
				{
					//timer_int_handler(counter); //same function as in lab3
					RTC_handler_date();
					counter++;
				}
				else*/
				if(msg.NOTIFY_ARG & BIT(1))
				{
					keyboard_handler(); //different function from the original
				}

				break;
			default:
				break; /* no other notifications expected: do nothing */
			}

		} else
		{ /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
		counter++;
	}

	return;

}
예제 #19
0
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(int argc, char *argv[])
{
  dpeth_t *dep;
  message m;
  int ipc_status;
  int r;

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();
  
  while (TRUE)
    {
      if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK)
	panic("netdriver_receive failed: %d", r);

		if(is_ipc_notify(ipc_status)) {
			switch(_ENDPOINT_P(m.m_source)) {
				case CLOCK:
					do_watchdog(&m);
					break;

	case HARDWARE:
	  dep = &de_state;
	  if (dep->de_mode == DEM_ENABLED) {
	    do_interrupt(dep);
	    if (dep->de_flags & (DEF_ACK_SEND | DEF_ACK_RECV))
	    do_reply(dep);
	    sys_irqenable(&dep->de_hook);
	  }
	  break;
	 default:
	 	printf("ignoring notify from %d\n", m.m_source);
	 	break;
			}
			continue;
		}
      
      switch (m.m_type)
	{
	case DL_WRITEV_S:  do_vwrite_s(&m, FALSE); break;
	case DL_READV_S:   do_vread_s(&m, FALSE);  break;	  
	case DL_CONF:      do_conf(&m);            break;  
	case DL_GETSTAT_S: do_get_stat_s(&m);      break;

	default:  
		printf("message 0x%x; %d from %d\n",
			m.m_type, m.m_type-DL_RQ_BASE, m.m_source);
		panic("illegal message: %d", m.m_type);
	}
    }
}
예제 #20
0
파일: test3.c 프로젝트: joaofidalgo23/LCOM
int kbd_test_timed_scan(unsigned short n) {
    int ipc_status;
    message msg;
    int validation = 0;
    int counter = 0;

    // usado para evitar chamar a função driver_receive várias vezes
    int receive;

    //subscribe() já verifica se não há problemas.
    int irq_set1 = kbd_subscribe();
    int irq_set2 = timer_subscribe_int();

    //Para quando a tecla ESC é libertada, ou quando passam n segundos sem input
    while (!validation) {
        /* Get a request message. */
        receive = driver_receive(ANY, &msg, &ipc_status);
        if (receive != 0) {
            printf("driver_receive failed with: %d", receive);
            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_set1) { /* subscribed interrupt */
                    validation = kbd_handler_c(); /* process it */
                    counter = 0;
                }
                if (msg.NOTIFY_ARG & irq_set2) { /* subscribed interrupt */
                    counter++; /* process it */
                    if (counter == n*60)
                    {
                        printf("\n\tkbd_test_scan() stopped, press ENTER to continue!\n");
                        validation = 1;
                    }
                }
                break;
            default:
                break; /* no other notifications expected: do nothing */
            }
        } else { /* received a standard message, not a notification */
            /* no standard messages expected: do nothing */
        }
    }
    // unsubscribe_int() já verifica se não há problemas.
    kbd_unsubscribe();
    timer_unsubscribe_int();
    return 0;
}
예제 #21
0
void *test_init(unsigned short mode, unsigned short delay) {
	void* video_mem = NULL;
	if((video_mem=vg_init(mode)) == NULL)
	{
		printf("test_init(): vg_init() failed");
		return NULL;
	}
	int failure=0;
	int timer_irq_set=0;
	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;
	//unsigned long ticks=0;
	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 & timer_irq_set){
						timer_int_handler();
					}
					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_ticks() < delay * 60);
	}
	if(timer_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): timer_unsubscribe_int() failed\n");
		failure = 1;
	}
	if(vg_exit()){
		printf("test_init(): vg_exit() failed");
		return NULL;
	}
	printf("Physical Address of VRAM: 0x%X\n", get_vram_phys_addr());
	return (void*)get_video_mem();
}
예제 #22
0
파일: atl2.c 프로젝트: ssinghi/minix
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(int argc, char **argv)
{
	/* Driver task.
	 */
	message m;
	int ipc_status;
	int r;

	/* Initialize SEF. */
	env_setargs(argc, argv);
	sef_local_startup();

	while (TRUE) {
		if ((r = netdriver_receive(ANY, &m, &ipc_status)) != OK)
			panic("netdriver_receive failed: %d", r);

		if (is_ipc_notify(ipc_status)) {
			switch (m.m_source) {
			case HARDWARE:		/* interrupt */
				atl2_intr(&m);

				break;

			case TTY_PROC_NR:	/* function key */
				atl2_dump();

				break;

			default:
				printf("ATL2: illegal notify from %d\n",
					m.m_source);
			}

			continue;
		}

		/* Process requests from Inet. */
		switch (m.m_type) {
		case DL_CONF:		atl2_conf(&m);			break;
		case DL_GETSTAT_S:	atl2_getstat(&m);		break;
		case DL_WRITEV_S:	atl2_writev(&m, FALSE);		break;
		case DL_READV_S:	atl2_readv(&m, FALSE);		break;
		default:
			printf("ATL2: illegal message %d from %d\n",
				m.m_type, m.m_source);
		}
	}
}
예제 #23
0
int test_packet(unsigned short cnt) {

	unsigned long mouse_byte;
	int ipc_status, loops = 0,contador = 0;
	message msg;
	unsigned char packets[3];
	short irq_set = BIT(mouse_subscribe_int());
	enable_packets();
	while (loops != cnt) {
		/* Get a request message. */
		if (driver_receive(ANY, &msg, &ipc_status) != 0) {
			printf("driver_receive failed with: %d");
			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) {
					mouse_byte = mouse_int_handler();
					if (contador == 0) {
						if (!first_byte(mouse_byte)) {
							contador = 0;
							continue;
						}
					}
					packets[contador] = mouse_byte;
					if (contador == 2) {
						contador = 0;
						print_packet(packets);
						loops++;
						continue;
					}
					contador++;
				}
				break;
			default:
				break; /* no other notifications expected: do nothing */
			}
		}
		else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
	}

	return mouse_unsubscribe_int();
}
예제 #24
0
파일: test4.c 프로젝트: pedro-c/LCOM-FEUP
int test_packet(unsigned short cnt) {
	int conta = 0, ind = 0, r, ipc_status;
	unsigned long irq_set, data;
	char cmd;
	message msg;
	if ((irq_set = mouse_subscribe()) == -1) {
		printf("Unable to subscribe mouse!\n");
		return 1;
	}
	if (sys_outb(STAT_REG, ENABLE_MOUSE) != OK) //rato enable
		printf("Error\n");
	if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) //MOUSE
		printf("Error-MC\n");
	if (sys_outb(OUT_BUF, ENABLE_SEND) != OK) //Ativar o envio
		printf("Error-SEND\n");
	while (cnt > conta) {
		if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
			printf("driver_receive failed with: %d", r);
			continue;
		}
		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set) {
					get_packet();
					mouse_print();

				}
				break;
			default:
				break;
			}
		} else {
		}
	}
	printf("Terminou!\n");
	if (sys_outb(STAT_REG, W_TO_MOUSE) != OK)
		printf("ERROR-MC");
	if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK)
		printf("ERROR-DISABLE_STREAM");
	if (sys_inb(OUT_BUF, &data) != OK)
		printf("OUT_BUF not full!\n");
	if (data != ACK)
		printf("Not ACK!\n");
	if (mouse_unsubscribe() == -1)
		printf("falhou unsubscribe mouse!\n");
	return 0;
}
예제 #25
0
파일: keyboard.c 프로젝트: mgpsp/LCOM-FEUP
int exit_on_ESC()
{
	int ipc_status, r, exit = 0;
	unsigned long irq_set, data;
	message msg;

	irq_set = keyboard_subscribe_int();
	if (irq_set == -1) return 1;  // check if subscribe_int failed

	do
	{
		r = driver_receive(ANY, &msg, &ipc_status);
		if (r != 0)
		{
			printf("driver_receive failed with: %d", r);
			continue;
		}

		if (is_ipc_notify(ipc_status))
		{
			switch (_ENDPOINT_P(msg.m_source))
			{
			case HARDWARE:
				if (msg.NOTIFY_ARG & irq_set)
				{
					data = readFromKBC();
					if (data == ESC)
					{
						exit = 1;
						if (vg_exit() != 0)
						{
							printf("\texit_on_ESC(): vg_exit() failed\n");
							return 1;
						}
					}
				}
				break;
			default:
				break;
			}
		}
	} while (exit == 0);

	keyboard_unsubscribe_int();

	return 0;
}
예제 #26
0
/*===========================================================================*
 *				blockdriver_process			     *
 *===========================================================================*/
PUBLIC void blockdriver_process(struct blockdriver *bdp, message *m_ptr,
  int ipc_status)
{
/* Handle the given received message. */
  int r;

  /* Process the notification or request. */
  if (is_ipc_notify(ipc_status)) {
	blockdriver_handle_notify(bdp, m_ptr);

	/* Do not reply to notifications. */
  } else {
	r = blockdriver_handle_request(bdp, m_ptr, SINGLE_THREAD);

	blockdriver_reply(m_ptr, ipc_status, r);
  }
}
예제 #27
0
파일: chardriver.c 프로젝트: grd/minix
/*===========================================================================*
 *				chardriver_process			     *
 *===========================================================================*/
void chardriver_process(struct chardriver *cdp, int driver_type,
  message *m_ptr, int ipc_status)
{
/* Handle the given received message. */
  int r;

  /* Process the notification or request. */
  if (is_ipc_notify(ipc_status)) {
	handle_notify(cdp, m_ptr);

	/* Do not reply to notifications. */
  } else {
	r = handle_request(cdp, m_ptr);

	send_reply(driver_type, m_ptr, ipc_status, r);
  }
}
예제 #28
0
int timer_test_int(unsigned long time)
{
	int irq_set = timer_subscribe_int(); //subscreve e inicia as interrupções do timer0
	timer_set_square(0,60); //coloca a frequencia a 60

	int ipc_status;
	int r;
	message msg;
	unsigned i = 0;
	while( i < time) { // enquando a contagem é menor que o valor passado no parametro
		/* 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 & irq_set)
				 { /* subscribed interrupt */
					 timer_int_handler();
					 if (counter % 60 == 0) //a cada segundo (60 contagens a 60 de frequencia)
					 {
						 i++;
						 printf("%d", i); // imprime o valor do segundo.
						 printf("\n");
					 }
				 }
				 break;
				default:
					break; /* no other notifications expected: do nothing */
			}
		} else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */

			}
	}
	if (timer_unsubscribe_int() != OK)  //termina a subscrição, caso dê erro retorna 1
		return 1;
	
	return 0;
}
예제 #29
0
파일: tda19988.c 프로젝트: Hooman3/minix
static void
tda19988_blk_other(message * m, int ipc_status)
{
	log_trace(&log, "tda19988_blk_other(0x%x)\n", m->m_type);

	if (is_ipc_notify(ipc_status)) {
		if (m->m_source == DS_PROC_NR) {
			log_debug(&log,
			    "bus driver changed state, update endpoint\n");
			i2cdriver_handle_bus_update(&cec_bus_endpoint, cec_bus,
			    cec_address);
			i2cdriver_handle_bus_update(&hdmi_bus_endpoint,
			    hdmi_bus, hdmi_address);
		}
	} else {
		log_warn(&log, "Invalid message type (0x%x)\n", m->m_type);
	}
}
예제 #30
0
파일: e1000.c 프로젝트: mwilbur/minix
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(int argc, char *argv[])
{
    message m;
    int ipc_status;
    int r;

    /* SEF local startup. */
    env_setargs(argc, argv);
    sef_local_startup();

    /*
     * Enter the main driver loop.
     */
    while (TRUE)
    {
	if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK)
	{
	    panic("netdriver_receive failed: %d", r);
	}

	if (is_ipc_notify(ipc_status))
	{
	    switch (_ENDPOINT_P(m.m_source))
	    {
                case HARDWARE:
		    e1000_interrupt(&m);
		    break;

		case CLOCK:
                    break;
	    }
	    continue;
	}
	switch (m.m_type)
	{
	    case DL_WRITEV_S:   e1000_writev_s(&m, FALSE);	break;
	    case DL_READV_S:    e1000_readv_s(&m, FALSE);	break;
	    case DL_CONF:	e1000_init(&m);			break;
	    case DL_GETSTAT_S:  e1000_getstat_s(&m);		break;
	    default:
		panic("illegal message: %d", m.m_type);
	}
    }
}