ESP8266 Developer Zone The Official ESP8266 Forum 2015-08-24T18:23:31+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=995 2015-08-24T18:23:31+08:00 2015-08-24T18:23:31+08:00 https://bbs.espressif.com:443/viewtopic.php?t=995&p=3412#p3412 <![CDATA[Re: Is the os_timer_setfn() hardware or software driven?]]> I think we have a asynchronisity in our understanding ;) I will try again.

Suppose you have three logical timers (comparable to the "javascript" timer or the os_timer_fn timers), one should fire every 1ms, one every 2ms and one every 5 ms.

At the lowest level you can easily implement something like that using one "hardware" timer. From time offset 0 ms, the first timer to fire is timer 0 (every 1ms), at 1 ms. So it is programmed to be fire at offset 1 ms. In the meantime the cpu can go do anything it likes including going into a power saving mode. At time offset 1 ms, the hardware timer fires an interrupt and the low level code (in this case: the code from SDK) will recognise it's the first timer that should be called. When it has done so, it checks what timer should fire next. In this case it's both timer 0 and timer 1 at offset 2 ms. So the timer is programmed for 2 ms. At the interrupt the code for timer 0 is called and the code for timer 1 is called. This goes on for a while, until we reach 5 ms, where the timer 0 and timer 2 code should be called.

The crux of the story is that the cpu doesn't need to do anyhing (no busy loops, etc.) between moment in time "x" where the timer is started OR where the previous timer fired and moment in time "y" where the next timer should fire. The only difference between having only one hardware timer and having an infinite amount of hardware timers is that you need to program the single hardware timer every time it has fired. Usually this is very "light", just a few lines of code. So in the end it's not really that useful to have more than one timer, unless you do "complex" things like hardware pwms on different frequencies, compare&capture etc.

Statistics: Posted by eriksl — Mon Aug 24, 2015 6:23 pm


]]>
2015-08-24T02:08:43+08:00 2015-08-24T02:08:43+08:00 https://bbs.espressif.com:443/viewtopic.php?t=995&p=3381#p3381 <![CDATA[Re: Is the os_timer_setfn() hardware or software driven?]]> My words probably aren't working for me today :-)

By busy loop, what I mean is that code is actively checking to see if a timer is ready ... as opposed to hardware assist where no code is needed to check if a timer is ready ... instead, a hardware clock is ticking internally at microcode level and causes an interrupt when the timer expires.

As for the JavaScript runtime ... the one I am using is called Espruino and the relevant idle loop processing can be found starting at line 1439 here ... https://github.com/espruino/Espruino/bl ... eractive.c

This is as much an academic question as anything. Not a vital need on my part to understand this ... just curious.

Neil

Statistics: Posted by kolban — Mon Aug 24, 2015 2:08 am


]]>
2015-08-24T01:46:29+08:00 2015-08-24T01:46:29+08:00 https://bbs.espressif.com:443/viewtopic.php?t=995&p=3380#p3380 <![CDATA[Re: Is the os_timer_setfn() hardware or software driven?]]> Statistics: Posted by eriksl — Mon Aug 24, 2015 1:46 am


]]>
2015-08-24T01:26:44+08:00 2015-08-24T01:26:44+08:00 https://bbs.espressif.com:443/viewtopic.php?t=995&p=3379#p3379 <![CDATA[Re: Is the os_timer_setfn() hardware or software driven?]]>
Neil

Statistics: Posted by kolban — Mon Aug 24, 2015 1:26 am


]]>
2015-08-24T00:45:56+08:00 2015-08-24T00:45:56+08:00 https://bbs.espressif.com:443/viewtopic.php?t=995&p=3376#p3376 <![CDATA[Re: Is the os_timer_setfn() hardware or software driven?]]> ). Works over here.

What it DOES is simply call your callback function at some time in the future, minimal x timespan from what you specified. In the meantime the cpu simply keeps running, setting a timer function is not blocking execution. So you can install multiple timers and that just works, no problem. It's very comparable to a timer compare interrupt on a "regular" microcontroller. If you're done with your business, just return from all of your functions and the SDK code will make sure the cpu does "nothing" (at least: not on your code) and it will only return to your code when the timer fires. Whether the SDK code will put the cpu in a somewhat lower power sleeping state or not, I cannot confirm, but I assume it does, so it may be beneficial.

I think the timer code inside the SDK is actually built around a list of timers, the (one) hardware timer is programmed to fire when the first next timer function should be called, when that happens, the timer is reprogrammed to fire for the next timer function to be called, etc. So it all revolves around one hardware timer. AFAIK there is only one timer in the esp8266 anyway, so it should be used shared nicely.

Statistics: Posted by eriksl — Mon Aug 24, 2015 12:45 am


]]>
2015-08-24T00:16:49+08:00 2015-08-24T00:16:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=995&p=3375#p3375 <![CDATA[Is the os_timer_setfn() hardware or software driven?]]>
Neil

Statistics: Posted by kolban — Mon Aug 24, 2015 12:16 am


]]>