Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 InterruptIn button(USER_BUTTON0); 00004 DigitalOut led1(LED1); 00005 Thread * pTestTask = NULL; 00006 00007 static void idle_hook(void) { 00008 // Do the following instead of "__WFI()" 00009 __SEV(); 00010 __WFE(); 00011 __WFE(); 00012 } 00013 00014 void SoftwareStandby(void) { 00015 volatile uint32_t dummy_32; 00016 volatile uint8_t dummy_8; 00017 00018 core_util_critical_section_enter(); 00019 00020 // Set the standby_mode_en bit of the power control register in the PL310 to 1. 00021 L2C.REG15_POWER_CTRL = 0x00000001uL; 00022 dummy_32 = L2C.REG15_POWER_CTRL; 00023 00024 // Clear the TME bit in the watchdog timer control/status register (WTCSR) of the watchdog timer to 0 to stop the watchdog timer. 00025 WDT.WTCSR = 0xA518; 00026 WDT.WTCNT = 0x5A00; 00027 WDT.WTCSR = 0xA51D; // CKS[2:0] = b'101 : 1/1024 x P0 (7.8ms) 00028 00029 CPG.STBCR1 = 0x80; 00030 dummy_8 = CPG.STBCR1; 00031 00032 __WFI(); 00033 00034 core_util_critical_section_exit(); 00035 } 00036 00037 static void interrupt_button(void) { 00038 #if(0) // It may or may not be present. 00039 if (pTestTask != NULL) { 00040 pTestTask->signal_set(1); 00041 } 00042 #endif 00043 } 00044 00045 void test_task(void) { 00046 int test_cnt = 0; 00047 00048 button.fall(&interrupt_button); 00049 button.rise(&interrupt_button); 00050 00051 while (true) { 00052 SoftwareStandby(); 00053 #if(0) // It may or may not be present. 00054 // It becomes sleep during idle task. 00055 Thread::signal_wait(1); 00056 #endif 00057 led1 = !led1; 00058 printf("%d\r\n", test_cnt++); 00059 ThisThread::sleep_for(5); // Wait for output completion of printf(). 00060 } 00061 } 00062 00063 int main() { 00064 Thread::attach_idle_hook(idle_hook); 00065 pTestTask = new Thread(); 00066 pTestTask->start(test_task); 00067 }
Generated on Mon Jul 25 2022 20:25:36 by
1.7.2