I'm trying to put a cortex m4 processor (m3 with dsp extensions) to sleep for a little less than a second. I want to be able to tell it to sleep, then a second later, or when a button is pressed, pick up right where I left off. I've looked in the reference manual and VLPS or LLS modes look like it would fit my needs. Ideally I'd like a glorified delay function, for it to sleep for a second. I don't know how to begin to enter that mode or how to program the NVIC. I'm using C on bare metal.
Any help would be greatly appreciated.
Here's the code:
#include "IntervalTimer.h"
//The following is where the SLEEPDEEP flag is at
#define SCR (*((volatile unsigned long *) 0xE000ED10))
volatile uint32_t timerCounter0;
boolean printNow = false;
void timerCallback0() {
timerCounter0++;
printNow = true;
}
void setup() {
SCR = SCR | 0x04; //Set SLEEPDEEP
Serial.begin(true);
IntervalTimer timer0;
timer0.begin(timerCallback0, 1000000);
}
void loop() {
if (printNow) {
Serial.println(timerCounter0);
printNow = false;
asm("wfi\n");
}
}