Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By mkarliner
#25796 The ticker library is a very nice addition to the platform.
I wonder if the addition of a simple way to define critical sections, where
Tickers will not fire, would be a) possible, b) desirable. That would open the way
to a a signalling or even messaging mechanism.

On a wider note, has anyone worked on coroutines, or even porting one of the RTOS's
to the platform?

MIke
User avatar
By igrr
#25808 Actually the whole thing relies on coroutines to wrap blocking Arduino network APIs over asynchronous lwIP network APIs. This is mostly implemented in cont.h/cont.S in the core.
Disabling Tickers is possible, just need to stop all the timers and restart them upon exit from critical section.
User avatar
By bateau62
#32184 Hi,
sorry for reviving an old thread, but this is the closest I've seen to what I'm looking for.
Being new in this arduino environment (but not new in the embedded world), I am missing some info regarding this whole setup/loop/ticker thing.

ticker looks like a very good addition, allowing a way out of the uncertainties regarding timing of loop(), but the only doc I found --the ticker section of reference.md-- is a bit light. Where can I find a better doc?

Is there any in depth documentation regarding the timing of loop and ticker?
My main questions are:
* how reliable is the timing of the callbacks? What situations would cause a delay or even skipping of a callback?
* when can callbacks be fired? Any time, or only in delay() + end of loop() or ...
* would it be safe/functional to call delay() from inside a ticker callback? The fact that the callback itself would need to be protected against re-entry is something else.

And if someone has the following info, it would be nice:
* what libraries/functions are known safe regarding being called from a ticker callback? I'm especially interested in SPI, GFX and OneWire libs.
* what libraries are known unsafe? I know about the predictable incompatibility with network, serial and file, but others must exist.
User avatar
By igrr
#32319 ESP8266 SDK has a task-event scheduler, which allows to run certain functions when corresponding events arrive. There are multiple priorities (32, in fact), with one task per priority.
Arduino setup and loop functions are run from one of the tasks. Setup is run once, and loop is run on each successive call to the task. When the task handler completes (i.e. at the end of loop function), an event is posted to the scheduler to run the same task again. However the task will not necessarily run immediately, if there are higher-priority tasks pending. So the timing of loop invocation depends on other tasks (most notably the ones which handle network activity).

Ticker also relies on SDK software timer functionality. Since this is a software timer, there are no guarantees regarding accuracy.

Regarding things which you can call from ticker callbacks, there is no definitive list. You can not call delay or anything else which relies on coroutines (i.e. blocking IO methods of Serial and WiFi libraries), because ticker callbacks do not have their own continuation stack.

OneWire and SPI should work fine. As for GFX, i don't know. If it doesn't call yield() or delay(), it should be okay.