mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
add regular scheduled functions, now also callable on yield()
(#6039)
* add regular scheduled functions, now also callable on `yield()` added bool schedule_function_us(std::function<bool(void)> fn, uint32_t repeat_us) lambda must return true to be not removed from the schedule function list if repeat_us is 0, then the function is called only once. Legacy schedule_function() is preserved This addition allows network drivers like ethernet chips on lwIP to be regularly called - even if some user code loops on receiving data without getting out from main loop (callable from yield()) - without the need to call the driver handling function (transparent) This may be also applicable with common libraries (mDNS, Webserver, )
This commit is contained in:
@ -143,26 +143,12 @@ extern "C" {
|
||||
#define __STRINGIFY(a) #a
|
||||
#endif
|
||||
|
||||
// these low level routines provide a replacement for SREG interrupt save that AVR uses
|
||||
// but are esp8266 specific. A normal use pattern is like
|
||||
//
|
||||
//{
|
||||
// uint32_t savedPS = xt_rsil(1); // this routine will allow level 2 and above
|
||||
// // do work here
|
||||
// xt_wsr_ps(savedPS); // restore the state
|
||||
//}
|
||||
//
|
||||
// level (0-15), interrupts of the given level and above will be active
|
||||
// level 15 will disable ALL interrupts,
|
||||
// level 0 will enable ALL interrupts,
|
||||
//
|
||||
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
|
||||
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
|
||||
|
||||
#define xt_rsil(level) (level)
|
||||
#define xt_wsr_ps(state) do { (void)(state); } while (0)
|
||||
|
||||
#define interrupts() xt_rsil(0)
|
||||
#define noInterrupts() xt_rsil(15)
|
||||
|
||||
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||
|
Reference in New Issue
Block a user