Preliminary main mbed library for nexpaq development
TESTS/mbedmicro-rtos-mbed/timer/main.cpp@0:6c56fb4bc5f0, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:27:58 2016 +0000
- Revision:
- 0:6c56fb4bc5f0
Moving to library for sharing updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | #include "mbed.h" |
nexpaq | 0:6c56fb4bc5f0 | 2 | #include "greentea-client/test_env.h" |
nexpaq | 0:6c56fb4bc5f0 | 3 | #include "rtos.h" |
nexpaq | 0:6c56fb4bc5f0 | 4 | |
nexpaq | 0:6c56fb4bc5f0 | 5 | #if defined(MBED_RTOS_SINGLE_THREAD) |
nexpaq | 0:6c56fb4bc5f0 | 6 | #error [NOT_SUPPORTED] test not supported |
nexpaq | 0:6c56fb4bc5f0 | 7 | #endif |
nexpaq | 0:6c56fb4bc5f0 | 8 | |
nexpaq | 0:6c56fb4bc5f0 | 9 | int total_ticks = 10; |
nexpaq | 0:6c56fb4bc5f0 | 10 | volatile int current_tick = 0; |
nexpaq | 0:6c56fb4bc5f0 | 11 | |
nexpaq | 0:6c56fb4bc5f0 | 12 | DigitalOut LEDs[4] = { |
nexpaq | 0:6c56fb4bc5f0 | 13 | DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) |
nexpaq | 0:6c56fb4bc5f0 | 14 | }; |
nexpaq | 0:6c56fb4bc5f0 | 15 | |
nexpaq | 0:6c56fb4bc5f0 | 16 | void blink(void const *n) { |
nexpaq | 0:6c56fb4bc5f0 | 17 | static int blink_counter = 0; |
nexpaq | 0:6c56fb4bc5f0 | 18 | const int led_id = int(n); |
nexpaq | 0:6c56fb4bc5f0 | 19 | LEDs[led_id] = !LEDs[led_id]; |
nexpaq | 0:6c56fb4bc5f0 | 20 | if (++blink_counter == 75 && current_tick <= total_ticks) { |
nexpaq | 0:6c56fb4bc5f0 | 21 | greentea_send_kv("tick", current_tick++); |
nexpaq | 0:6c56fb4bc5f0 | 22 | blink_counter = 0; |
nexpaq | 0:6c56fb4bc5f0 | 23 | } |
nexpaq | 0:6c56fb4bc5f0 | 24 | } |
nexpaq | 0:6c56fb4bc5f0 | 25 | |
nexpaq | 0:6c56fb4bc5f0 | 26 | int main(void) { |
nexpaq | 0:6c56fb4bc5f0 | 27 | GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto"); |
nexpaq | 0:6c56fb4bc5f0 | 28 | |
nexpaq | 0:6c56fb4bc5f0 | 29 | RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0); |
nexpaq | 0:6c56fb4bc5f0 | 30 | RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1); |
nexpaq | 0:6c56fb4bc5f0 | 31 | RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2); |
nexpaq | 0:6c56fb4bc5f0 | 32 | RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3); |
nexpaq | 0:6c56fb4bc5f0 | 33 | |
nexpaq | 0:6c56fb4bc5f0 | 34 | led_1_timer.start(200); |
nexpaq | 0:6c56fb4bc5f0 | 35 | led_2_timer.start(100); |
nexpaq | 0:6c56fb4bc5f0 | 36 | led_3_timer.start(50); |
nexpaq | 0:6c56fb4bc5f0 | 37 | led_4_timer.start(25); |
nexpaq | 0:6c56fb4bc5f0 | 38 | |
nexpaq | 0:6c56fb4bc5f0 | 39 | while(current_tick <= total_ticks) { |
nexpaq | 0:6c56fb4bc5f0 | 40 | Thread::wait(10); |
nexpaq | 0:6c56fb4bc5f0 | 41 | } |
nexpaq | 0:6c56fb4bc5f0 | 42 | |
nexpaq | 0:6c56fb4bc5f0 | 43 | led_4_timer.stop(); |
nexpaq | 0:6c56fb4bc5f0 | 44 | led_3_timer.stop(); |
nexpaq | 0:6c56fb4bc5f0 | 45 | led_2_timer.stop(); |
nexpaq | 0:6c56fb4bc5f0 | 46 | led_1_timer.stop(); |
nexpaq | 0:6c56fb4bc5f0 | 47 | |
nexpaq | 0:6c56fb4bc5f0 | 48 | GREENTEA_TESTSUITE_RESULT(1); |
nexpaq | 0:6c56fb4bc5f0 | 49 | |
nexpaq | 0:6c56fb4bc5f0 | 50 | Thread::wait(osWaitForever); |
nexpaq | 0:6c56fb4bc5f0 | 51 | } |