Daiki Kato
/
Sleep_test_no_OS
This is a sample to make sleep without using OS.
main.cpp@1:ec156833bab2, 2016-11-18 (annotated)
- Committer:
- dkato
- Date:
- Fri Nov 18 09:46:33 2016 +0000
- Revision:
- 1:ec156833bab2
- Parent:
- 0:19a3b76f6ca9
update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:19a3b76f6ca9 | 1 | #include "mbed.h" |
dkato | 0:19a3b76f6ca9 | 2 | |
dkato | 0:19a3b76f6ca9 | 3 | InterruptIn button(USER_BUTTON0); |
dkato | 0:19a3b76f6ca9 | 4 | DigitalOut led1(LED1); |
dkato | 0:19a3b76f6ca9 | 5 | |
dkato | 0:19a3b76f6ca9 | 6 | static void interrupt_button(void) { |
dkato | 0:19a3b76f6ca9 | 7 | // do nothing |
dkato | 0:19a3b76f6ca9 | 8 | } |
dkato | 0:19a3b76f6ca9 | 9 | |
dkato | 0:19a3b76f6ca9 | 10 | int main() { |
dkato | 0:19a3b76f6ca9 | 11 | int test_cnt = 0; |
dkato | 0:19a3b76f6ca9 | 12 | |
dkato | 0:19a3b76f6ca9 | 13 | button.fall(&interrupt_button); |
dkato | 0:19a3b76f6ca9 | 14 | button.rise(&interrupt_button); |
dkato | 0:19a3b76f6ca9 | 15 | |
dkato | 0:19a3b76f6ca9 | 16 | while (true) { |
dkato | 0:19a3b76f6ca9 | 17 | // Transition to Sleep Mode |
dkato | 1:ec156833bab2 | 18 | __SEV(); |
dkato | 1:ec156833bab2 | 19 | __WFE(); |
dkato | 1:ec156833bab2 | 20 | __WFE(); |
dkato | 0:19a3b76f6ca9 | 21 | led1 = !led1; |
dkato | 0:19a3b76f6ca9 | 22 | printf("%d\n", test_cnt++); |
dkato | 0:19a3b76f6ca9 | 23 | } |
dkato | 0:19a3b76f6ca9 | 24 | } |