Nuvoton
/
NuMaker-mbed-tickless-example
NuMaker tickless example
wakeup_wdt.cpp@25:51d3dccddd8b, 21 months ago (annotated)
- Committer:
- cyliang
- Date:
- Wed Mar 01 03:53:04 2023 +0000
- Revision:
- 25:51d3dccddd8b
- Parent:
- 20:759aab916d47
Update os v6.17.0 for M467 target
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ccli8 |
16:ed2c228cbc9c | 1 | /* Avoid conflict with Mbed OS watchdog API |
ccli8 |
16:ed2c228cbc9c | 2 | * |
ccli8 |
16:ed2c228cbc9c | 3 | * Mbed OS has defined watchdog API. To avoid conflict, disable this code when target has implemented Mbed OS watchdog API. |
ccli8 |
16:ed2c228cbc9c | 4 | */ |
ccli8 |
16:ed2c228cbc9c | 5 | #if !defined(DEVICE_WATCHDOG) || !DEVICE_WATCHDOG |
ccli8 |
16:ed2c228cbc9c | 6 | |
ccli8 |
1:eb1da9d36e12 | 7 | #include "mbed.h" |
ccli8 |
1:eb1da9d36e12 | 8 | #include "wakeup.h" |
ccli8 |
16:ed2c228cbc9c | 9 | |
ccli8 |
20:759aab916d47 | 10 | #if defined(TARGET_NANO100) |
ccli8 |
10:d2e2c79389e1 | 11 | /* This target doesn't support relocating vector table and requires overriding |
ccli8 |
10:d2e2c79389e1 | 12 | * vector handler at link-time. */ |
ccli8 |
10:d2e2c79389e1 | 13 | extern "C" void WDT_IRQHandler(void) |
ccli8 |
10:d2e2c79389e1 | 14 | #else |
ccli8 |
1:eb1da9d36e12 | 15 | void WDT_IRQHandler(void) |
ccli8 |
10:d2e2c79389e1 | 16 | #endif |
ccli8 |
1:eb1da9d36e12 | 17 | { |
ccli8 |
1:eb1da9d36e12 | 18 | /* Check WDT interrupt flag */ |
ccli8 |
1:eb1da9d36e12 | 19 | if (WDT_GET_TIMEOUT_INT_FLAG()) { |
ccli8 |
1:eb1da9d36e12 | 20 | WDT_CLEAR_TIMEOUT_INT_FLAG(); |
ccli8 |
1:eb1da9d36e12 | 21 | WDT_RESET_COUNTER(); |
ccli8 |
1:eb1da9d36e12 | 22 | } |
ccli8 |
1:eb1da9d36e12 | 23 | |
ccli8 |
1:eb1da9d36e12 | 24 | // Check WDT wake-up flag |
ccli8 |
1:eb1da9d36e12 | 25 | if (WDT_GET_TIMEOUT_WAKEUP_FLAG()) { |
ccli8 |
1:eb1da9d36e12 | 26 | WDT_CLEAR_TIMEOUT_WAKEUP_FLAG(); |
ccli8 |
1:eb1da9d36e12 | 27 | |
ccli8 |
1:eb1da9d36e12 | 28 | wakeup_eventflags.set(EventFlag_Wakeup_WDT_Timeout); |
ccli8 |
1:eb1da9d36e12 | 29 | } |
ccli8 |
1:eb1da9d36e12 | 30 | } |
ccli8 |
1:eb1da9d36e12 | 31 | |
ccli8 |
1:eb1da9d36e12 | 32 | void config_wdt_wakeup() |
ccli8 |
1:eb1da9d36e12 | 33 | { |
ccli8 |
1:eb1da9d36e12 | 34 | /* Enable IP module clock */ |
ccli8 |
1:eb1da9d36e12 | 35 | CLK_EnableModuleClock(WDT_MODULE); |
ccli8 |
1:eb1da9d36e12 | 36 | |
ccli8 |
1:eb1da9d36e12 | 37 | /* Select IP clock source */ |
ccli8 |
20:759aab916d47 | 38 | #if defined(TARGET_NANO100) |
ccli8 |
10:d2e2c79389e1 | 39 | CLK_SetModuleClock(WDT_MODULE, 0, 0); |
ccli8 |
10:d2e2c79389e1 | 40 | #else |
ccli8 |
1:eb1da9d36e12 | 41 | CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDTSEL_LIRC, 0); |
ccli8 |
10:d2e2c79389e1 | 42 | #endif |
ccli8 |
1:eb1da9d36e12 | 43 | |
ccli8 |
1:eb1da9d36e12 | 44 | SYS_UnlockReg(); |
ccli8 |
18:e236110ce841 | 45 | #if defined(TARGET_M251) |
ccli8 |
18:e236110ce841 | 46 | /* Alarm every 2^16 LIRC clocks, disable system reset, enable system wake-up */ |
ccli8 |
18:e236110ce841 | 47 | /* LIRC higher than other targets, so enlarge clock count */ |
ccli8 |
18:e236110ce841 | 48 | WDT_Open(WDT_TIMEOUT_2POW16, 0, FALSE, TRUE); |
ccli8 |
18:e236110ce841 | 49 | #else |
ccli8 |
1:eb1da9d36e12 | 50 | /* Alarm every 2^14 LIRC clocks, disable system reset, enable system wake-up */ |
ccli8 |
1:eb1da9d36e12 | 51 | WDT_Open(WDT_TIMEOUT_2POW14, 0, FALSE, TRUE); |
ccli8 |
18:e236110ce841 | 52 | #endif |
ccli8 |
1:eb1da9d36e12 | 53 | SYS_LockReg(); |
ccli8 |
10:d2e2c79389e1 | 54 | |
ccli8 |
1:eb1da9d36e12 | 55 | /* NOTE: The name of symbol WDT_IRQHandler is mangled in C++ and cannot override that in startup file in C. |
ccli8 |
1:eb1da9d36e12 | 56 | * So the NVIC_SetVector call cannot be left out. */ |
ccli8 |
1:eb1da9d36e12 | 57 | NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler); |
ccli8 |
1:eb1da9d36e12 | 58 | NVIC_EnableIRQ(WDT_IRQn); |
ccli8 |
1:eb1da9d36e12 | 59 | SYS_UnlockReg(); |
ccli8 |
1:eb1da9d36e12 | 60 | /* Enable WDT timeout interrupt */ |
ccli8 |
1:eb1da9d36e12 | 61 | WDT_EnableInt(); |
ccli8 |
1:eb1da9d36e12 | 62 | SYS_LockReg(); |
ccli8 |
1:eb1da9d36e12 | 63 | } |
ccli8 |
16:ed2c228cbc9c | 64 | |
ccli8 |
16:ed2c228cbc9c | 65 | #else |
ccli8 |
16:ed2c228cbc9c | 66 | |
ccli8 |
20:759aab916d47 | 67 | #include "mbed.h" |
ccli8 |
20:759aab916d47 | 68 | |
ccli8 |
16:ed2c228cbc9c | 69 | void config_wdt_wakeup() |
ccli8 |
16:ed2c228cbc9c | 70 | { |
ccli8 |
20:759aab916d47 | 71 | printf("Disable WDT timeout wake-up on this target\n\n"); |
ccli8 |
16:ed2c228cbc9c | 72 | } |
ccli8 |
16:ed2c228cbc9c | 73 | |
ccli8 |
16:ed2c228cbc9c | 74 | #endif /* #if !defined(DEVICE_WATCHDOG) || !DEVICE_WATCHDOG */ |