Esempio n. 1
0
void timer_completed()
{
	#ifdef LOG_FWK_ENABLED
	uint16_t current_timer = hal_timer_getvalue();
	log_print_stack_string(LOG_FWK, "timer_completed: %d.%d", current_timer/1000,current_timer%1000);
	#endif

    timer_event* event = (timer_event*) queue_pop_value(&event_queue, sizeof(timer_event));

    bool directly_fire_new_event = false;

    if (event_queue.length == 0)
    {
        hal_timer_disable_interrupt();
        started = false;
    } else {
        hal_timer_setvalue(((timer_event*) event_queue.front)->next_event);
        uint16_t diff = hal_timer_getvalue() - ((timer_event*) event_queue.front)->next_event;
        if (diff < 1000)
        	directly_fire_new_event = true;
    }

    event->f(NULL);

    if (directly_fire_new_event)
    	timer_completed();
}
Esempio n. 2
0
bool timer_add_event(timer_event* event)
{
	#ifdef LOG_FWK_ENABLED
	uint16_t current_timer = hal_timer_getvalue();
	log_print_stack_string(LOG_FWK, "timer_add_event: %d.%d", event->next_event/1000,event->next_event%1000);
	log_print_stack_string(LOG_FWK, "timer_add_event timer S : %d.%d", current_timer/1000, current_timer%1000);
	#endif

    if (event->next_event == 0)
    {
        event->f(NULL);
        return true;
    }

    timer_event new_event;
    new_event.f = event->f;
    new_event.next_event = event->next_event;

    if (timer_insert_value_in_queue(&new_event))
    {
        if (!started)
        {
            hal_timer_enable_interrupt();
            started = true;
            hal_timer_setvalue(new_event.next_event);
        }
        uint16_t diff = hal_timer_getvalue() - new_event.next_event;
        if (diff < 1000)
		{
			#ifdef LOG_FWK_ENABLED
        	current_timer = hal_timer_getvalue();
        	log_print_stack_string(LOG_FWK, "timer_add_event M timer overrun : %d.%d", current_timer/1000,current_timer%1000);
        	log_print_stack_string(LOG_FWK, "timer_add_event M: %d.%d", new_event.next_event/1000,  new_event.next_event%1000);
			#endif
			timer_completed();
		}
    } else {
        //log_print_stack_string(LOG_FWK, "Cannot add event, queue is full");
        return false;
    }

	#ifdef LOG_FWK_ENABLED
	current_timer = hal_timer_getvalue();
	log_print_stack_string(LOG_FWK, "timer_add_event timer E : %d.%d", current_timer/1000,current_timer%1000);
	#endif

    return true;
}
bool timer_add_event(timer_event* event)
{

    DPRINT("Add event: current timer: %d.", hal_timer_getvalue());

    if (event->next_event == 0)
    {
        event->f();
        return true;
    }

    timer_event new_event;
    new_event.f = event->f;
    new_event.next_event = event->next_event;


    DPRINT(" - new event : %d %p", new_event.next_event, new_event.f);

    if (timer_insert_value_in_queue(&new_event))
    {
        if (!started)
        {
            hal_timer_enable_interrupt();
            started = true;
            hal_timer_setvalue(new_event.next_event);
        }
        uint16_t diff = hal_timer_getvalue() - new_event.next_event;
        if (diff < 1000)
		{
                    DPRINT("timer_add_event M timer overrun : %d", hal_timer_getvalue());
                    DPRINT("timer_add_event M: %d", new_event.next_event);
                    timer_completed();
		}
    } else {
        DPRINT("Cannot add event, queue is full");
        return false;
    }

    DPRINT("timer_add_event timer E : %d", hal_timer_getvalue());

    return true;
}
void timer_completed()
{

    DPRINT("Timer Completed: cti: %d", hal_timer_getvalue());

    timer_event* event = (timer_event*) queue_pop_value(&event_queue, sizeof(timer_event));

    DPRINT(" - event  next_event %d event %p", event->next_event, event->f);
    DPRINT(" - event_queue lenght   %d ", event_queue.length);

    bool directly_fire_new_event = false;

    if (event_queue.length == 0)
    {
        hal_timer_disable_interrupt();
        started = false;
    } else {
    	DPRINT(" - next_event  next_event %d event %p", ((timer_event*) event_queue.front)->next_event, ((timer_event*) event_queue.front)->f);

        hal_timer_setvalue(((timer_event*) event_queue.front)->next_event);
        uint16_t diff = hal_timer_getvalue() - ((timer_event*) event_queue.front)->next_event;
        DPRINT(" - diff   %d ", diff);

        if (diff < 1000)
        {
            directly_fire_new_event = true;
        }
    }

    event->f();

    if (directly_fire_new_event)
    {
    	timer_completed();
    }
}