Daiki Kato / Mbed OS Sleep_test_use_OS
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 InterruptIn button(USER_BUTTON0);
00005 DigitalOut led1(LED1);
00006 Thread * pTestTask = NULL;
00007 
00008 static void idle_hook(void) {
00009     __WFI();  // Do not set when using SoftwareStandby.
00010 }
00011 
00012 static void interrupt_button(void) {
00013     if (pTestTask != NULL) {
00014         pTestTask->signal_set(1);
00015     }
00016 }
00017 
00018 void test_task(void) {
00019     int test_cnt = 0;
00020 
00021     button.fall(&interrupt_button);
00022     button.rise(&interrupt_button);
00023 
00024     while (true) {
00025         // It becomes sleep during idle task.
00026         Thread::signal_wait(1);
00027         led1 = !led1;
00028         printf("%d\n", test_cnt++);
00029     }
00030 }
00031 
00032 int main() {
00033     Thread::attach_idle_hook(idle_hook);
00034     pTestTask = new Thread();
00035     pTestTask->start(test_task);
00036 }