Daiki Kato
/
SoftwareStanby_test_use_OS
This is a sample to make Software Standby using OS.
main.cpp
- Committer:
- dkato
- Date:
- 2019-10-08
- Revision:
- 3:64e8fa1b8787
- Parent:
- 2:c0f92fd0e8e9
- Child:
- 4:272e885e36a9
File content as of revision 3:64e8fa1b8787:
#include "mbed.h" InterruptIn button(USER_BUTTON0); DigitalOut led1(LED1); Thread * pTestTask = NULL; static void idle_hook(void) { // interim measures // "__WFI()" doesn't work after SoftwareStandby. // do nothing } void SoftwareStandby(void) { volatile uint32_t dummy_32; volatile uint8_t dummy_8; GIC_DisableIRQ(OSTMI0TINT_IRQn); // Set the standby_mode_en bit of the power control register in the PL310 to 1. L2C.REG15_POWER_CTRL = 0x00000001uL; dummy_32 = L2C.REG15_POWER_CTRL; // Clear the TME bit in the watchdog timer control/status register (WTCSR) of the watchdog timer to 0 to stop the watchdog timer. WDT.WTCSR = 0xA518; WDT.WTCNT = 0x5A00; WDT.WTCSR = 0xA51D; // CKS[2:0] = b'101 : 1/1024 x P0 (7.8ms) CPG.STBCR1 = 0x80; dummy_8 = CPG.STBCR1; __WFI(); GIC_EnableIRQ(OSTMI0TINT_IRQn); } static void interrupt_button(void) { #if(0) // It may or may not be present. if (pTestTask != NULL) { pTestTask->signal_set(1); } #endif } void test_task(void) { int test_cnt = 0; button.fall(&interrupt_button); button.rise(&interrupt_button); while (true) { SoftwareStandby(); #if(0) // It may or may not be present. // It becomes sleep during idle task. Thread::signal_wait(1); #endif led1 = !led1; printf("%d\r\n", test_cnt++); ThisThread::sleep_for(5); // Wait for output completion of printf(). } } int main() { Thread::attach_idle_hook(idle_hook); // interim measures pTestTask = new Thread(); pTestTask->start(test_task); }