Skip to content

Commit 7a703aa

Browse files
committed
adding comments
1 parent 433a901 commit 7a703aa

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

ports/atmel-samd/common-hal/alarm/__init__.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
5050
// TODO: make a custom enum to avoid weird values like PM_SLEEPCFG_SLEEPMODE_BACKUP_Val?
5151
STATIC volatile uint32_t _target;
5252
STATIC bool fake_sleep;
53-
STATIC bool pin_alarm = false;
5453

5554
void alarm_reset(void) {
5655
// Reset the alarm flag
@@ -68,7 +67,9 @@ samd_sleep_source_t alarm_get_wakeup_cause(void) {
6867
return SAMD_WAKEUP_RTC;
6968
}
7069
if (RSTC->RCAUSE.bit.BACKUP) {
71-
if (RTC->MODE0.INTFLAG.bit.TAMPER) {
70+
// not able to detect PinAlarm wake since registers are getting reset
71+
// TODO: come up with a way to detect a TAMPER
72+
if (RTC->MODE0.TAMPID.reg || RTC->MODE0.INTFLAG.bit.TAMPER) {
7273
return SAMD_WAKEUP_GPIO;
7374
}
7475
return SAMD_WAKEUP_RTC;
@@ -189,33 +190,30 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
189190
(void)__get_FPSCR();
190191
}
191192

192-
// hacky way of checking if time alarm or pin alarm
193-
// TODO: find better way of determining pin vs time
193+
// PinAlarm (hacky way of checking if time alarm or pin alarm)
194194
if (RTC->MODE0.INTENSET.bit.TAMPER) {
195195
// Disable interrupts
196196
NVIC_DisableIRQ(RTC_IRQn);
197-
198197
// Must disable the RTC before writing to EVCTRL and TMPCTRL
199198
RTC->MODE0.CTRLA.bit.ENABLE = 0; // Disable the RTC
200199
while (RTC->MODE0.SYNCBUSY.bit.ENABLE); // Wait for synchronization
201-
202200
RTC->MODE0.CTRLA.bit.SWRST = 1; // Software reset the RTC
203201
while (RTC->MODE0.SYNCBUSY.bit.SWRST); // Wait for synchronization
204-
205202
RTC->MODE0.CTRLA.reg = RTC_MODE0_CTRLA_PRESCALER_DIV1024 | // Set prescaler to 1024
206203
RTC_MODE0_CTRLA_MODE_COUNT32; // Set RTC to mode 0, 32-bit timer
207204

208205
// TODO: map requested pin to limited selection of TAMPER pins
209-
//PA02 = IN2
210206
RTC->MODE0.TAMPCTRL.bit.DEBNC2 = 1; // Edge triggered when INn is stable for 4 CLK_RTC_DEB periods
211207
RTC->MODE0.TAMPCTRL.bit.TAMLVL2 = 1; // rising edge
212-
RTC->MODE0.TAMPCTRL.bit.IN2ACT = 1; // WAKE (doesn't save timestamp)
208+
//PA02 = IN2
209+
RTC->MODE0.TAMPCTRL.bit.IN2ACT = 1; // WAKE on IN2 (doesn't save timestamp)
213210

214211
// Enable interrupts
215212
NVIC_SetPriority(RTC_IRQn, 0);
216213
NVIC_EnableIRQ(RTC_IRQn);
217214
// Set interrupts for TAMPER or overflow
218215
RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_TAMPER;
216+
// TimeAlarm
219217
} else {
220218
// Retrieve COMP1 value before resetting RTC
221219
// Disable interrupts
@@ -269,9 +267,6 @@ MP_NOINLINE void common_hal_alarm_pretending_deep_sleep(void) {
269267
SAMD_ALARM_FLAG = 1;
270268
while(RTC->MODE0.SYNCBUSY.reg);
271269
fake_sleep = true;
272-
// if () {
273-
// pin_alarm=true;
274-
// }
275270
} else {
276271
port_idle_until_interrupt();
277272
}

0 commit comments

Comments
 (0)