Preliminary main mbed library for nexpaq development
libraries/tests/rtos/mbed/timer/main.cpp@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
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 "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 | DigitalOut LEDs[4] = { |
nexpaq | 0:6c56fb4bc5f0 | 10 | DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) |
nexpaq | 0:6c56fb4bc5f0 | 11 | }; |
nexpaq | 0:6c56fb4bc5f0 | 12 | |
nexpaq | 0:6c56fb4bc5f0 | 13 | void print_char(char c = '*') |
nexpaq | 0:6c56fb4bc5f0 | 14 | { |
nexpaq | 0:6c56fb4bc5f0 | 15 | printf("%c", c); |
nexpaq | 0:6c56fb4bc5f0 | 16 | fflush(stdout); |
nexpaq | 0:6c56fb4bc5f0 | 17 | } |
nexpaq | 0:6c56fb4bc5f0 | 18 | |
nexpaq | 0:6c56fb4bc5f0 | 19 | void blink(void const *n) { |
nexpaq | 0:6c56fb4bc5f0 | 20 | static int counter = 0; |
nexpaq | 0:6c56fb4bc5f0 | 21 | const int led_id = int(n); |
nexpaq | 0:6c56fb4bc5f0 | 22 | LEDs[led_id] = !LEDs[led_id]; |
nexpaq | 0:6c56fb4bc5f0 | 23 | if (++counter == 75) { |
nexpaq | 0:6c56fb4bc5f0 | 24 | print_char(); |
nexpaq | 0:6c56fb4bc5f0 | 25 | counter = 0; |
nexpaq | 0:6c56fb4bc5f0 | 26 | } |
nexpaq | 0:6c56fb4bc5f0 | 27 | } |
nexpaq | 0:6c56fb4bc5f0 | 28 | |
nexpaq | 0:6c56fb4bc5f0 | 29 | int main(void) { |
nexpaq | 0:6c56fb4bc5f0 | 30 | MBED_HOSTTEST_TIMEOUT(15); |
nexpaq | 0:6c56fb4bc5f0 | 31 | MBED_HOSTTEST_SELECT(wait_us_auto); |
nexpaq | 0:6c56fb4bc5f0 | 32 | MBED_HOSTTEST_DESCRIPTION(Timer); |
nexpaq | 0:6c56fb4bc5f0 | 33 | MBED_HOSTTEST_START("RTOS_7"); |
nexpaq | 0:6c56fb4bc5f0 | 34 | |
nexpaq | 0:6c56fb4bc5f0 | 35 | RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0); |
nexpaq | 0:6c56fb4bc5f0 | 36 | RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1); |
nexpaq | 0:6c56fb4bc5f0 | 37 | RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2); |
nexpaq | 0:6c56fb4bc5f0 | 38 | RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3); |
nexpaq | 0:6c56fb4bc5f0 | 39 | |
nexpaq | 0:6c56fb4bc5f0 | 40 | led_1_timer.start(200); |
nexpaq | 0:6c56fb4bc5f0 | 41 | led_2_timer.start(100); |
nexpaq | 0:6c56fb4bc5f0 | 42 | led_3_timer.start(50); |
nexpaq | 0:6c56fb4bc5f0 | 43 | led_4_timer.start(25); |
nexpaq | 0:6c56fb4bc5f0 | 44 | |
nexpaq | 0:6c56fb4bc5f0 | 45 | Thread::wait(osWaitForever); |
nexpaq | 0:6c56fb4bc5f0 | 46 | } |