示例#1
0
int timer_test_square(unsigned long freq){

	if (timer_set_square(0, freq) == 0)
		return 0;

	return 1;
}
示例#2
0
int timer_test_square(unsigned long freq) {
	/* Get Timer 0 to work at a @freq frequency */
	
	if(timer_set_square(0, freq) != 0){
		printf("ERROR SETTING FREQUENCY ON TIMER 0\n");
		return 1;
	}

	return 0;
}
示例#3
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;
}
示例#4
0
int set_repetitive_task(unsigned long freq, void(*func)())
{
	if (doing_task) // Current task must be stopped first
	{
		return 1;
	}
	if (timer_subscribe_int())
	{
		return 1;
	}
	if (timer_set_square(0, freq))
	{
		return 1;
	}
	int r, ipc_status;
	message msg;
	time_counter = 0;
	doing_task = true;
	while (doing_task)
	{
		/* Get a request message. */
		if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
			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();
					func();
				}
				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;
}
示例#5
0
文件: timer.c 项目: PTJohe/LCOM
int timer_test_square(unsigned long freq) {
	timer_set_square(0, freq);
	return 0;
}