SAMD21 tickless implementation fixed by sync before sleep?

cajjed wrote on Friday, January 06, 2017:

I have implemented tickless on my samd21 chip based off the ASF tickless.c.

My sleep will wake up after 8 ms instead of about 1000 ms on occasion and think that it has sleeped for the entire duration. If I add a timer/counter sync then the erroneous wake up goes away. Any insight on why?

			while (tc_is_syncing(&tc45)) {
				/* Wait for sync */

I am thinking this is probably more of a samd21 question so I have cross posted it ( However, I wanted to ask here as well.

heinbali01 wrote on Friday, January 06, 2017:

Is this timer tc45 dedicated for the Tickless Idle sleep?

If so, can’t you set it (initialise it) to wake up the CPU after a given period of time? When called, FreeRTOS will advise you how many ticks it wants to be idle (at most).

A second remark: if you’re using ‘Tickless Idle’ to save energy, you should better try to sleep much longer periods of time, like 30 seconds or more.

cajjed wrote on Friday, January 06, 2017:

tc45 is the freeRTOS system tick, which fires the interrupt every millisecond (every 32 counts of the 32 kHz external oscillator). For Tickless idle, the timer/counter is switched to be the sleep timer and sleeps as much as xEpectedIdleTime dictates. In my test case I have it waking every second to toggle a test pin and output debug data. In my actual system the sleep times will be on the scale of 20 seconds.

The oddity is that for some reason the timer/counter wakes very quickly and thinks it has fired the interrupt indicating that it has matched. Adding the sync fixes the problem. Just trying to understand why, concerned it it just a bandaid and will show up again down the road.

edwards3 wrote on Friday, January 06, 2017:

I dont know what the timer sync does but if the function exists maybe you are meant to use it. Check the hardware ref manual.

cajjed wrote on Saturday, January 07, 2017:

The sync just waits until the hardware module has synched to the bus. You call this before writing or reading the timer/counter and so forth. Just don’t know why checking it before sleep will fix an error where the timer/counter wakes up after 8 ms instead of 1000 ms.