LWMesh: systimer and RTC and sleep

Go To Last Post
2 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not exactly a LWMesh topic since it is about SYS_Timer.  But I imagine other LWMesh users doing exactly what I did here.


Summary of my problem:  CPU is asleep in standby.  I expect the CPU to wakeup by RTC interrupt 2 seconds later and then check that a flag is set inside the RTC ISR.  What happens is the CPU wakes up but no flag is set, ie. the ISR didn't execute.  The thing is, it only happens roughly 1-100 minutes after reset.  All the other times the flag is set by the ISR, as it should be.


Background info (correct me if I'm wrong) :

The SYS_Timer uses TC0 (in my version), and it does interrupt the CPU.  It does NOT wake up the CPU from sleep.  (btw which GCLK does it use?)

I've also got an RTC interrupt, clocked by external crystal so this would be asynchronous to the TC0, ie. every once in a while they'll overflow at the same time right?


Alright, onto the description.  I will try to edit this post as I get more info.  But if this rings a bell someone please reply!


if( is_wakeup_by_rtc() )
    ;//change state
    {while(1)blink();}//should never happen!

is_wakeup_by_rtc() returns the flag that is set by the RTC ISR callback.

Every once in a while, code gets to the else.  Literally, once in a while.  Sometimes it's 10 minutes after reset, sometimes an hour.  Different amount of time every time.  So to me it totally seems like it's the 10ms SYS_Timer and the 2second RTC hitting at the same time, which will always occur at a different amount of time after reset.  This is just based on my understanding of math, not understanding of CPUs.


But that's weird.  SYS_Timer does NOT wakeup CPU from sleep.  If it did, the CPU would hit the else statement on the first SYS_Timer interrupt after reset, every time.

I'm just shooting in the dark but my guess is that the SYS_Timer interrupts right before the call to sleepmgr_sleep(); and because of this the WFI didn't allow the CPU to sleep at all.  That might be a stupid guess but I have no idea what's happening sad

Someone please give me some info!  I am playing around with priorities and disabling interrupts.  If I show up Monday morning and I don't see a while(1)blink(); happening, then I may have solved it.  frown



Note:  I do use a level detect interrupt and a UART interrupt and other timer interrupts but I never press the button and I commented out my UART_TaskHandler() and the other timers are 1 shots that interrupt before this sleep happens.  So I'm almost positive I'm aware of every interrupt that can happen around the time of this sleep.  It's just the RTC and SYS_Timer.


Note:  I read something about PRIMASK but I didn't touch it and I'm pretty sure LWMesh and ASF don't either, right?


Last Edited: Fri. Oct 16, 2015 - 12:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Any asynchronous peripheral that has Run in Standby enabled will wake up the MCU even if the actual interrupt handler is not enabled and is not executed. So check all other peripherals you initialize.


I don't see why interrupt right before sleepmgr_sleep() will not let MCU go to sleep.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.