Beispiel #1
0
static PT_THREAD(thread_uart(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        PT_WAIT_UNTIL(pt, uart_flag);

        led_green_blink(10); /* 10 timer ticks = 100 ms */

        /* does the local node expects an id
         * or do we have to broadcast it? */
        if(timer_reached(TIMER_ID_INPUT, ID_INPUT_TIMEOUT_TICKS))
        {
            send_id_reply(uart_data);
        }
        else
        {
            set_node_id(uart_data);
        }
        uart_flag = 0;
    }

    PT_END(pt);
}
Beispiel #2
0
void __timer_set_helper(uint16_t time)
{
    if(time == 0)
        return;
    if(timer_reached())
        return;
    //won't harm to be sure
    timer_init();
    if(timerstack_count <= TIMER_STACK_SIZE)
    {
        if (timerstack_count != 0)
        {
            if(timer_remaining() > time)
            {
                timerstack[timerstack_count-1] = timer_remaining()-time;
                timer_set(time);
            }
            else
                timerstack[timerstack_count-1] = 0;
        }
        else
            timer_set(time);
    }
    timerstack_count++;
}
Beispiel #3
0
// Periodically capture temperature
static PT_THREAD(thread_periodic_capture(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        TIMER_TEMP_PRINT = 0;
        PT_WAIT_UNTIL(pt,timer_reached( TIMER_TEMP, TIMER_CAPTURE_PERIOD_MS/TIMER_PERIOD_MS));
        //TODO
    }
    PT_END(pt);
}
Beispiel #4
0
// Periodically check and empties rx buffer/send msg and switch states accordingly to received msg
static PT_THREAD(thread_periodic_radio(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        TIMER_TEMP_PRINT = 0;
        PT_WAIT_UNTIL(pt,timer_reached( TIMER_RADIO, TIMER_RADIO_PERIOD_MS/TIMER_PERIOD_MS));
        //TODO
    }
    PT_END(pt);
}
Beispiel #5
0
static PT_THREAD(thread_periodic_send(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        TIMER_RADIO_SEND = 0;
        PT_WAIT_UNTIL(pt, node_id != NODE_ID_UNDEFINED && timer_reached( TIMER_RADIO_SEND, 200));
        send_temperature();
    }

    PT_END(pt);
}
Beispiel #6
0
static PT_THREAD(thread_antibouncing(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        PT_WAIT_UNTIL(pt, antibouncing_flag
          && timer_reached(TIMER_ANTIBOUNCING, ANTIBOUNCING_DURATION));
        antibouncing_flag = 0;
    }

    PT_END(pt);
}
Beispiel #7
0
static PT_THREAD(thread_led_red(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        led_red_switch();
        TIMER_LED_RED_ON = 0;
        PT_WAIT_UNTIL(pt, timer_reached(TIMER_LED_RED_ON, 100));
    }

    PT_END(pt);
}
Beispiel #8
0
static PT_THREAD(thread_led_green(struct pt *pt))
{
    PT_BEGIN(pt);

    while(1)
    {
        PT_WAIT_UNTIL(pt, led_green_flag);
        led_green_on();
        TIMER_LED_GREEN_ON = 0;
        PT_WAIT_UNTIL(pt, timer_reached(TIMER_LED_GREEN_ON,
          led_green_duration));
        led_green_off();
        led_green_flag = 0;
    }

    PT_END(pt);
}
Beispiel #9
0
bool __timer_timeout_helper(bool cond)
{
    if(timer_reached() || !cond)
    {
        timerstack_count--;
        if(timerstack_count == 0)
            timer_reset();
        else if (timerstack_count <= TIMER_STACK_SIZE)
        {
            if(timerstack[timerstack_count-1] != 0)
                timer_set(timer_remaining()+timerstack[timerstack_count-1]);
        }
        return false;
    }
    else
        return true;
}