Ejemplo n.º 1
0
Archivo: main.c Proyecto: Cr0s/RIOT
int main(void)
{
    phydat_t res;
    uint32_t last = xtimer_now();

    puts("SAUL test application");

    while (1) {
        saul_reg_t *dev = saul_reg;

        if (dev == NULL) {
            puts("No SAUL devices present");
            return 1;
        }

        while (dev) {
            int dim = saul_reg_read(dev, &res);
            phydat_dump(&res, dim);
            dev = dev->next;
        }

        xtimer_periodic_wakeup(&last, INTERVAL);
    }

    return 0;
}
Ejemplo n.º 2
0
int uart_stdio_write(const char* buffer, int len) {
    int written = rtt_write(buffer, len);
    xtimer_ticks32_t last_wakeup = xtimer_now();
    while (blocking_stdout && written < len) {
        xtimer_periodic_wakeup(&last_wakeup, STDIO_POLL_INTERVAL);
        written += rtt_write(&buffer[written], len-written);
    }
    return written;
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: A-Paul/RIOT
static int cmd_sample(int argc, char **argv)
{
    (void)argc;
    (void)argv;
    xtimer_ticks32_t wakeup = xtimer_now();

    while(1) {
        sample();
        xtimer_periodic_wakeup(&wakeup, SAMPLE_PERIOD);
    }

    return 0;
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: OTAkeys/RIOT
int main(void)
{
#if defined(MAIN_THREAD_PIN)
    gpio_t main_pin = MAIN_THREAD_PIN;
    gpio_init(main_pin, GPIO_OUT);
#endif

#if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2)
    timer_arg_t sleep_timer1 = { TEST_SLEEP_TIME_1, WORKER_THREAD_PIN_1 };
    timer_arg_t sleep_timer2 = { TEST_SLEEP_TIME_2, WORKER_THREAD_PIN_2 };
#else
    uint32_t sleep_timer1 = TEST_SLEEP_TIME_1;
    uint32_t sleep_timer2 = TEST_SLEEP_TIME_2;
#endif
    LOG_DEBUG("[INIT]\n");


    thread_create(stack_timer1, TEST_TIMER_STACKSIZE,
                  2, THREAD_CREATE_STACKTEST,
                  timer_func, &sleep_timer1, "timer1");
    thread_create(stack_timer2, TEST_TIMER_STACKSIZE,
                  3, THREAD_CREATE_STACKTEST,
                  timer_func, &sleep_timer2, "timer2");

    uint32_t now = 0;
    uint32_t start = xtimer_now_usec();
    uint32_t until = start + (TEST_TIME_S * US_PER_SEC);
    uint32_t interval = TEST_INTERVAL_MS * US_PER_MS;
    xtimer_ticks32_t last_wakeup = xtimer_now();

    puts("[START]");
    while ((now = xtimer_now_usec()) < until) {
        unsigned percent = (100 * (now - start)) / (until - start);
#if defined(MAIN_THREAD_PIN)
        gpio_set(main_pin);
#endif
        xtimer_periodic_wakeup(&last_wakeup, interval);
#if defined(MAIN_THREAD_PIN)
        gpio_clear(main_pin);
#endif
        printf("Testing (%3u%%)\n", percent);
    }
    puts("Testing (100%)");
    puts("[SUCCESS]");
    return 0;
}
Ejemplo n.º 5
0
/* The reason we have this strange logic is as follows:
   If we have an RTT console, we are powered, and so don't care
   that polling uses a lot of power. If however, we do not
   actually have an RTT console (because we are deployed on
   a battery somewhere) then we REALLY don't want to poll
   especially since we are not expecting to EVER get input. */
int uart_stdio_read(char* buffer, int count) {
    int res = rtt_read(buffer, count);
    if (res == 0) {
        if (!stdin_enabled) {
            mutex_lock(&_rx_mutex);
            /* We only unlock when rtt_stdio_enable_stdin is called
               Note that we assume only one caller invoked this function */
        }
        xtimer_ticks32_t last_wakeup = xtimer_now();
        while(1) {
            xtimer_periodic_wakeup(&last_wakeup, STDIO_POLL_INTERVAL);
            res = rtt_read(buffer, count);
            if (res > 0)
                return res;
        }
    }
    return res;
}
Ejemplo n.º 6
0
int main(void)
{
    int state = 0;
    int step = STEP;
    xtimer_ticks32_t last_wakeup = xtimer_now();

    puts("\nRIOT PWM test");
    puts("Connect an LED or scope to PWM pins to see something\n");

    printf("Available PWM devices: %i\n", PWM_NUMOF);
    for (int i = 0; i < PWM_NUMOF; i++) {
        uint32_t real_f = pwm_init(PWM_DEV(i), MODE, FREQU, STEPS);
        if (real_f == 0) {
            printf("Error initializing PWM_%i\n", i);
            return 1;
        }
        else {
            printf("Initialized PWM_%i @ %" PRIu32 "Hz\n", i, real_f);
        }
    }

    puts("\nLetting the PWM pins oscillate now...");
    while (1) {
        for (int i = 0; i < PWM_NUMOF; i++) {
            for (uint8_t chan = 0; chan < pwm_channels(PWM_DEV(i)); chan++) {
                pwm_set(PWM_DEV(i), chan, state);
            }
        }

        state += step;
        if (state <= 0 || state >= STEPS) {
            step = -step;
        }

        xtimer_periodic_wakeup(&last_wakeup, INTERVAL);
    }

    return 0;
}