Shinichiro Nakamura
/
TestProgramForBugTopic990
This is a test program for http://mbed.org/forum/bugs-suggestions/topic/990/
Diff: main.cpp
- Revision:
- 1:4cfa24bbc098
- Parent:
- 0:3eb38701225c
diff -r 3eb38701225c -r 4cfa24bbc098 main.cpp --- a/main.cpp Mon Aug 16 11:25:35 2010 +0000 +++ b/main.cpp Mon Aug 16 22:32:37 2010 +0000 @@ -7,6 +7,18 @@ #include "mbed.h" +/** + * TEST_MODE 0: Test a Timeout. + * TEST_MODE 1: Test a Ticker. + */ +#define TEST_MODE 0 + +#if TEST_MODE + +/* + * A test for Ticker. + */ + BusOut myled(LED4, LED3, LED2, LED1); Ticker tickerForLED; Ticker tickerForAnother; @@ -25,14 +37,17 @@ // Do nothing. } -int main() { +/** + * Entry point for Ticker. + */ +int main(void) { int n = 0; - + /* * Start my LED ticker. */ - tickerForLED.attach(&tickfunc_led, 0.2); - + tickerForLED.attach(&tickfunc_led, 0.2); + /* * Wait 5 seconds. */ @@ -41,7 +56,7 @@ /* * Attach another ticker. * Then the LED ticker will be stop. - */ + */ while (1) { /* * Check for this loop. @@ -53,11 +68,76 @@ */ tickerForAnother.attach_us(&tickfunc_another, 2 * 1000); wait_ms(100); + } +} - tickerForAnother.attach_us(&tickfunc_another, 2 * 1000); +#else + +/* + * A test for Timeout. + */ + +BusOut myled(LED4, LED3, LED2, LED1); +Ticker tickerForLED; +Timeout timeout; + +/** + * Tick function for toggle 4 LEDs. + */ +void tickfunc_led(void) { + myled = myled + 1; +} + +/** + * Timeout function. + */ +void timeoutfunc(void) { + printf("timeoutfunc.\n"); +} + +/** + * Entry point for Timeout. + */ +int main(void) { + int n = 0; + + /* + * Start my LED ticker. + */ + tickerForLED.attach(&tickfunc_led, 0.2); + + /* + * Wait 5 seconds. + */ + wait(5); + + /* + * Attach timeout. + * Then the LED ticker will be stop. + */ + while (1) { + /* + * Check for this loop. + */ + printf("n=%d\n", n++); + + /* + * Change my timeout. + */ + timeout.detach(); + timeout.attach_us(&timeoutfunc, 2 * 1000); wait_ms(100); - tickerForAnother.attach_us(&tickfunc_another, 2 * 1000); + timeout.detach(); + timeout.attach_us(&timeoutfunc, 200 * 1000); + wait_ms(100); + + timeout.attach_us(&timeoutfunc, 20 * 1000); + wait_ms(100); + + timeout.attach_us(&timeoutfunc, 200 * 1000); wait_ms(100); } } + +#endif