-->
Page 2 of 2

Re: Ticker Library and Critical Sections

PostPosted: Wed Sep 19, 2018 2:25 pm
by dalbert
Is the Ticker callback called from an interrupt context? i.e. does the callback and everything it may call need to be decorated with ICACHE_RAM_ATTR?

Thanks!

Re: Ticker Library and Critical Sections

PostPosted: Thu Sep 20, 2018 9:26 am
by rudy
My understanding is that callbacks are not the same as interrupts. The task is scheduled to run. It does not interrupt the currently running code so I see no reason for ICACHE_RAM_ATTR.

(My understanding = I think)

Re: Ticker Library and Critical Sections

PostPosted: Thu Sep 20, 2018 1:13 pm
by McChubby007
I don't use the ticker library so I don't know its internals, but I assume it uses the esp8266/espressif timer api etc. Which triggers ticker's own callback function. In some (non-esp8266) architectures this timer would have been caused by a hardware interrupt and therefore the callback would be part of the code called during this hardware interrupt and so each api/function/callback in that chain of calls must adhere to any rules regarding ram/flash location etc.

However, I know for sure that the esp8266/espressif timer api does not use the hardware timer, it uses a 'soft' timer and so the requirements of having all interrupt routines resident in ram does not apply to the calling chain for timers. There is the possibility of using a hardware/interrupt timer in the esp8266 but it has strict limitations and so I don't believe it is generally used anywhere, as it can upset other things (can't remember the specifics of that right now, sorry).

Re: Ticker Library and Critical Sections

PostPosted: Sat Sep 22, 2018 9:30 pm
by mrburnette
IMO, using ticker is not necessary if you can keep the loop() code recycling every 30mS or so.
Good programming is to understand your code timing, if any function of section runs > 30mS, then you should utilize yield() or delay(0) to allow non-OS to refresh pending tasks in the RF section of the chip.

When you observe good timing within your code, the Arduino+Espressif code can coexist without conflict.

Ray