|
5 | 5 |
|
6 | 6 | #define SCHEDULED_FN_MAX_COUNT 32 |
7 | 7 |
|
| 8 | +// The purpose of scheduled functions is to trigger, from SYS stack (like in |
| 9 | +// an interrupt or a system event), registration of user code to be executed |
| 10 | +// in user stack (called CONT stack) without the common restrictions from |
| 11 | +// system context. Details are below. |
| 12 | + |
| 13 | +// The purpose of recurrent scheduled function is to independantly execute |
| 14 | +// user code in CONT stack on a regular basis. |
| 15 | +// It has been introduced with ethernet service in mind, it can also be used |
| 16 | +// for all libraries in the need of a regular `libdaemon_handlestuff()`. |
| 17 | +// It allows these services to be run even from a user loop not going back |
| 18 | +// to `loop()`. |
| 19 | +// Ticker + scheduled function offer the same service but recurrent |
| 20 | +// scheduled function happen more often: every yield() (vs every loop()), |
| 21 | +// and time resolution is microsecond (vs millisecond). Details are below. |
| 22 | + |
8 | 23 | // scheduled functions called once: |
9 | 24 | // |
10 | 25 | // * internal queue is FIFO. |
|
17 | 32 | // * There is no mechanism for cancelling scheduled functions. |
18 | 33 | // * `yield` can be called from inside lambdas. |
19 | 34 | // * Returns false if the number of scheduled functions exceeds |
20 | | -// SCHEDULED_FN_MAX_COUNT. |
| 35 | +// SCHEDULED_FN_MAX_COUNT (or memory shortage). |
21 | 36 | // * Run the lambda only once next time. |
| 37 | +// * A scheduled function can schedule a function. |
22 | 38 |
|
23 | 39 | bool schedule_function (const std::function<void(void)>& fn); |
24 | 40 |
|
25 | 41 | // Run all scheduled functions. |
26 | | -// Use this function if your are not using `loop`, or `loop` does not return |
27 | | -// on a regular basis. |
| 42 | +// Use this function if your are not using `loop`, |
| 43 | +// or `loop` does not return on a regular basis. |
28 | 44 |
|
29 | 45 | void run_scheduled_functions(); |
30 | 46 |
|
31 | 47 | // recurrent scheduled function: |
32 | 48 | // |
33 | | -// * internal queue if not FIFO. |
| 49 | +// * Internal queue may not be a FIFO. |
34 | 50 | // * Run the lambda periodically about every <repeat_us> microseconds until |
35 | 51 | // it returns false. |
36 | 52 | // * Note that it may be more than <repeat_us> microseconds between calls if |
37 | 53 | // `yield` is not called frequently, and therefore should not be used for |
38 | 54 | // timing critical operations. |
39 | | -// * There is no mechanism for cancelling recurrent scheduled functions. |
40 | | -// * long running operations or yield() or delay() are not allowed in the lambda. |
| 55 | +// * Please ensure variables or instances used from inside lambda will exist |
| 56 | +// when lambda is later called. |
| 57 | +// * There is no mechanism for externally cancelling recurrent scheduled |
| 58 | +// functions. However a user function returning false will cancel itself. |
| 59 | +// * Long running operations or yield() or delay() are not allowed in the |
| 60 | +// recurrent function. |
| 61 | +// * A recurrent function currently must not schedule another recurrent |
| 62 | +// functions. |
41 | 63 |
|
42 | 64 | bool schedule_recurrent_function_us (const std::function<bool(void)>& fn, uint32_t repeat_us); |
43 | 65 |
|
|
0 commit comments