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