mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/timeout/main.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "mbed.h" |
elessair | 0:f269e3021894 | 2 | #include "test_env.h" |
elessair | 0:f269e3021894 | 3 | |
elessair | 0:f269e3021894 | 4 | Timeout timer; |
elessair | 0:f269e3021894 | 5 | DigitalOut led(LED1); |
elessair | 0:f269e3021894 | 6 | |
elessair | 0:f269e3021894 | 7 | namespace { |
elessair | 0:f269e3021894 | 8 | const int MS_INTERVALS = 1000; |
elessair | 0:f269e3021894 | 9 | } |
elessair | 0:f269e3021894 | 10 | |
elessair | 0:f269e3021894 | 11 | void print_char(char c = '*') { |
elessair | 0:f269e3021894 | 12 | printf("%c", c); |
elessair | 0:f269e3021894 | 13 | fflush(stdout); |
elessair | 0:f269e3021894 | 14 | } |
elessair | 0:f269e3021894 | 15 | |
elessair | 0:f269e3021894 | 16 | void toggleOff(void); |
elessair | 0:f269e3021894 | 17 | |
elessair | 0:f269e3021894 | 18 | void toggleOn(void) { |
elessair | 0:f269e3021894 | 19 | static int toggle_counter = 0; |
elessair | 0:f269e3021894 | 20 | if (toggle_counter == MS_INTERVALS) { |
elessair | 0:f269e3021894 | 21 | led = !led; |
elessair | 0:f269e3021894 | 22 | print_char(); |
elessair | 0:f269e3021894 | 23 | toggle_counter = 0; |
elessair | 0:f269e3021894 | 24 | } |
elessair | 0:f269e3021894 | 25 | toggle_counter++; |
elessair | 0:f269e3021894 | 26 | timer.attach_us(toggleOff, 500); |
elessair | 0:f269e3021894 | 27 | } |
elessair | 0:f269e3021894 | 28 | |
elessair | 0:f269e3021894 | 29 | void toggleOff(void) { |
elessair | 0:f269e3021894 | 30 | timer.attach_us(toggleOn, 500); |
elessair | 0:f269e3021894 | 31 | } |
elessair | 0:f269e3021894 | 32 | |
elessair | 0:f269e3021894 | 33 | int main() { |
elessair | 0:f269e3021894 | 34 | MBED_HOSTTEST_TIMEOUT(15); |
elessair | 0:f269e3021894 | 35 | MBED_HOSTTEST_SELECT(wait_us_auto); |
elessair | 0:f269e3021894 | 36 | MBED_HOSTTEST_DESCRIPTION(Timeout Int us); |
elessair | 0:f269e3021894 | 37 | MBED_HOSTTEST_START("MBED_24"); |
elessair | 0:f269e3021894 | 38 | |
elessair | 0:f269e3021894 | 39 | toggleOn(); |
elessair | 0:f269e3021894 | 40 | |
elessair | 0:f269e3021894 | 41 | while (1); |
elessair | 0:f269e3021894 | 42 | } |