LowPowerLab Forum

Hardware support => Low Power Techniques => Topic started by: Neko on April 17, 2017, 10:00:25 AM

Title: Who woke me up?
Post by: Neko on April 17, 2017, 10:00:25 AM
I am counting pulses during ListenMode using interrupts on D3. After ListenModeStart and SLEEP_FOREVER, when I wake up, I need to know if I woke up because of an interrupt on D3, or because of a wakeup burst. If it was an interrupt in D3, I simply go back to sleep.  If it was a wakeup burst, then I need to process the burst and listenModeEnd().

Currently, I determine who woke me up by looking at a counter associated with D3. The IRQ increments the counter, so if count is higher than it was before I went to SLEEP, I know it was a pulse on D3 that woke me up, and that the wakeup burst has not arrived yet. If the counts haven't changed, I know it was a wakeup burst.

I do the same thing while I am in listenmode delay (this (https://lowpowerlab.com/forum/low-power-techniques/using-listenmode-as-wakeup-timer/) thread).

All this seems to work well enough, but what if there is a count and the end of listenmode at the same time (rare, I suppose). Is there a way to tell more directly if I am still in listenmode (or delay mode) when I wake up? Is there a register I can read from the radio, or could I add something to the radio.delay IRQ that would be available for my program to read?

Code: [Select]
lastCount = count;
radio.listenModeStart(); // or enter radio.delay() here
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
     
while (lastCount != count) {
   lastCount = count;
   LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
   }
// wake up, process BURST_REMAINING and get message here (or deal with end of radio.delay).

...

void countIRQ()
{
  count++;
}