1
1
/*
2
2
Author: Adam Garbo
3
- Created: February 1st , 2021
3
+ Created: March 26 , 2021
4
4
License: MIT. See SparkFun Arduino Apollo3 Project for more information
5
5
6
6
This example demonstrates the combined use of the Artemis Watchdog Timer (WDT)
9
9
Both RTC and WDT interrupts will wake the system, print the date and time,
10
10
and then re-enter deep sleep.
11
11
12
- The WDT is configured to trigger every 10 seconds. If the WDT is not "pet"
12
+ The WDT is configured to trigger every 10 seconds. If the WDT is not "pet"
13
13
after 100 seconds, a system reset will be triggered.
14
-
15
- The RTC alarm is configured to trigger every minute and enter deep sleep
14
+
15
+ The RTC alarm is configured to trigger every minute and enter deep sleep
16
16
between interrupts. Alarm interuptswill also restart the WDT and reset
17
17
the watchdog interrput counter.
18
18
*/
@@ -104,11 +104,9 @@ void goToSleep()
104
104
for (int x = 0 ; x < 50 ; x++)
105
105
am_hal_gpio_pinconfig (x, g_AM_HAL_GPIO_DISABLE);
106
106
107
- // Power down Flash, SRAM, cache
108
- am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_CACHE); // Turn off CACHE
109
- am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_FLASH_512K); // Turn off everything but lower 512k
110
- // am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_SRAM_64K_DTCM); // Turn off everything but lower 64k
111
- // am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); //Turn off all memory (doesn't recover)
107
+ // Power down CACHE, flashand SRAM
108
+ am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_ALL); // Turn off CACHE and flash
109
+ am_hal_pwrctrl_memory_deepsleep_retain (AM_HAL_PWRCTRL_MEM_SRAM_384K); // Retain all SRAM (0.6 uA)
112
110
113
111
// Keep the 32kHz clock running for RTC
114
112
am_hal_stimer_config (AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
@@ -123,9 +121,6 @@ void goToSleep()
123
121
// Power up gracefully
124
122
void wakeUp ()
125
123
{
126
- // Power up SRAM, turn on entire Flash
127
- am_hal_pwrctrl_memory_deepsleep_powerdown (AM_HAL_PWRCTRL_MEM_MAX);
128
-
129
124
// Go back to using the main clock
130
125
am_hal_stimer_config (AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
131
126
am_hal_stimer_config (AM_HAL_STIMER_HFRC_3MHZ);
@@ -136,10 +131,10 @@ void wakeUp()
136
131
137
132
// Renable power to UART0
138
133
am_hal_pwrctrl_periph_enable (AM_HAL_PWRCTRL_PERIPH_UART0);
139
-
134
+
140
135
// Enable ADC
141
136
initializeADC ();
142
-
137
+
143
138
// Enable ADC
144
139
initializeADC ();
145
140
@@ -168,7 +163,7 @@ extern "C" void am_watchdog_isr(void)
168
163
wdt.restart (); // "Pet" the dog
169
164
}
170
165
else {
171
- digitalWrite (LED_BUILTIN, HIGH ); // Visual indication of system reset trigger
166
+ while ( 1 ); // Wait for reset to occur
172
167
}
173
168
174
169
watchdogFlag = true ; // Set the watchdog flag
0 commit comments