Daiki Kato
/
SoftwareStanby_test_use_OS
This is a sample to make Software Standby using OS.
main.cpp@0:27ae610e630e, 2016-11-18 (annotated)
- Committer:
- dkato
- Date:
- Fri Nov 18 09:44:29 2016 +0000
- Revision:
- 0:27ae610e630e
- Child:
- 1:29fa0989ec31
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:27ae610e630e | 1 | #include "mbed.h" |
dkato | 0:27ae610e630e | 2 | #include "rtos.h" |
dkato | 0:27ae610e630e | 3 | #include "RZ_A1_Init.h" |
dkato | 0:27ae610e630e | 4 | |
dkato | 0:27ae610e630e | 5 | InterruptIn button(USER_BUTTON0); |
dkato | 0:27ae610e630e | 6 | DigitalOut led1(LED1); |
dkato | 0:27ae610e630e | 7 | Thread * pTestTask = NULL; |
dkato | 0:27ae610e630e | 8 | |
dkato | 0:27ae610e630e | 9 | static void idle_hook(void) { |
dkato | 0:27ae610e630e | 10 | __SEV(); |
dkato | 0:27ae610e630e | 11 | __WFE(); |
dkato | 0:27ae610e630e | 12 | __WFE(); |
dkato | 0:27ae610e630e | 13 | } |
dkato | 0:27ae610e630e | 14 | |
dkato | 0:27ae610e630e | 15 | void SoftwareStandby(void) { |
dkato | 0:27ae610e630e | 16 | volatile uint32_t dummy_32; |
dkato | 0:27ae610e630e | 17 | volatile uint8_t dummy_8; |
dkato | 0:27ae610e630e | 18 | |
dkato | 0:27ae610e630e | 19 | GIC_DisableIRQ(OSTMI0TINT_IRQn); |
dkato | 0:27ae610e630e | 20 | |
dkato | 0:27ae610e630e | 21 | // Set the standby_mode_en bit of the power control register in the PL310 to 1. |
dkato | 0:27ae610e630e | 22 | L2C.REG15_POWER_CTRL = 0x00000001uL; |
dkato | 0:27ae610e630e | 23 | dummy_32 = L2C.REG15_POWER_CTRL; |
dkato | 0:27ae610e630e | 24 | |
dkato | 0:27ae610e630e | 25 | // Clear the TME bit in the watchdog timer control/status register (WTCSR) of the watchdog timer to 0 to stop the watchdog timer. |
dkato | 0:27ae610e630e | 26 | WDT.WTCSR = 0xA518; |
dkato | 0:27ae610e630e | 27 | WDT.WTCNT = 0x5A00; |
dkato | 0:27ae610e630e | 28 | WDT.WTCSR = 0xA51D; // CKS[2:0] = b'101 : 1/1024xP0 (7.8ms) |
dkato | 0:27ae610e630e | 29 | |
dkato | 0:27ae610e630e | 30 | CPG.STBCR1 = 0x80; |
dkato | 0:27ae610e630e | 31 | dummy_8 = CPG.STBCR1; |
dkato | 0:27ae610e630e | 32 | |
dkato | 0:27ae610e630e | 33 | __SEV(); |
dkato | 0:27ae610e630e | 34 | __WFE(); |
dkato | 0:27ae610e630e | 35 | __WFE(); |
dkato | 0:27ae610e630e | 36 | |
dkato | 0:27ae610e630e | 37 | GIC_EnableIRQ(OSTMI0TINT_IRQn); |
dkato | 0:27ae610e630e | 38 | } |
dkato | 0:27ae610e630e | 39 | |
dkato | 0:27ae610e630e | 40 | static void interrupt_button(void) { |
dkato | 0:27ae610e630e | 41 | #if(0) // It may or may not be present. |
dkato | 0:27ae610e630e | 42 | if (pTestTask != NULL) { |
dkato | 0:27ae610e630e | 43 | pTestTask->signal_set(1); |
dkato | 0:27ae610e630e | 44 | } |
dkato | 0:27ae610e630e | 45 | #endif |
dkato | 0:27ae610e630e | 46 | } |
dkato | 0:27ae610e630e | 47 | |
dkato | 0:27ae610e630e | 48 | void test_task(void) { |
dkato | 0:27ae610e630e | 49 | int test_cnt = 0; |
dkato | 0:27ae610e630e | 50 | |
dkato | 0:27ae610e630e | 51 | button.fall(&interrupt_button); |
dkato | 0:27ae610e630e | 52 | button.rise(&interrupt_button); |
dkato | 0:27ae610e630e | 53 | |
dkato | 0:27ae610e630e | 54 | while (true) { |
dkato | 0:27ae610e630e | 55 | SoftwareStandby(); |
dkato | 0:27ae610e630e | 56 | #if(0) // It may or may not be present. |
dkato | 0:27ae610e630e | 57 | // It becomes sleep during idle task. |
dkato | 0:27ae610e630e | 58 | Thread::signal_wait(1); |
dkato | 0:27ae610e630e | 59 | #endif |
dkato | 0:27ae610e630e | 60 | led1 = !led1; |
dkato | 0:27ae610e630e | 61 | printf("%d\n", test_cnt++); |
dkato | 0:27ae610e630e | 62 | wait_ms(2); // Wait for output completion of printf(). |
dkato | 0:27ae610e630e | 63 | } |
dkato | 0:27ae610e630e | 64 | } |
dkato | 0:27ae610e630e | 65 | |
dkato | 0:27ae610e630e | 66 | int main() { |
dkato | 0:27ae610e630e | 67 | Thread::attach_idle_hook(idle_hook); |
dkato | 0:27ae610e630e | 68 | pTestTask = new Thread(); |
dkato | 0:27ae610e630e | 69 | pTestTask->start(test_task); |
dkato | 0:27ae610e630e | 70 | } |