void prepareForSleep(void)
{
disableSystemTickTimer(); // Disable system tick to allow sleep/stop modes
SCB->SCR = 0x00000004; // Enable Deep sleep mode
clearWakeSource(); // Clear the wake source before we go to sleep
NVIC_EnableIRQ(LLWU_IRQ); // Enable global interrupt for LLWU
g_savedPrimask = DisableGlobalIRQ();
// __disable_irq(); // Disable Global interrupts to avoid entering flash vector table
__ISB(); // Synchronize any pre-fetched instructions
configureFlashPreFetch(false); // Disable instruction & data pre-fetch
}
void goToSleep(void)
{
__DSB(); // Clear the pipeline instructions
__WFI(); // Go to sleep and wait for Event
__ISB(); // Synchronize fetched instructions
}
void wakeFromSleep(void)
{
configureFlashPreFetch(true); // Enable instruction & data pre-fetch
EnableGlobalIRQ(g_savedPrimask);
// __enable_irq(); // Enable Global interrupts
__ISB(); // Synchronize any pre-fetched instructions
clearWakeSource(); // Clear the wake source once we are awake
SCB->SCR = 0x00000000; // Disable Deep sleep mode
NVIC_DisableIRQ(LLWU_IRQ); // Enable global interrupt for LLWU
initializeSystemTickTimer(); // Re enable system tick timer
}