Stefan Roese | 00275f5 | 2022-09-02 13:57:53 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | Cyclic functions |
| 4 | ================ |
| 5 | |
| 6 | The cyclic function execution infrastruture provides a way to periodically |
| 7 | execute code, e.g. every 100ms. Examples for such functions might be LED |
| 8 | blinking etc. The functions that are hooked into this cyclic list should |
| 9 | be small timewise as otherwise the execution of the other code that relies |
| 10 | on a high frequent polling (e.g. UART rx char ready check) might be |
| 11 | delayed too much. To detect cyclic functions with a too long execution |
| 12 | time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` is introduced, |
| 13 | which configures the max allowed time for such a cyclic function. If it's |
| 14 | execution time exceeds this time, this cyclic function will get removed |
| 15 | from the cyclic list. |
| 16 | |
| 17 | Registering a cyclic function |
| 18 | ----------------------------- |
| 19 | |
| 20 | To register a cyclic function, use something like this:: |
| 21 | |
| 22 | static void cyclic_demo(void *ctx) |
| 23 | { |
| 24 | /* Just a small dummy delay here */ |
| 25 | udelay(10); |
| 26 | } |
| 27 | |
| 28 | int board_init(void) |
| 29 | { |
| 30 | struct cyclic_info *cyclic; |
| 31 | |
| 32 | /* Register demo cyclic function */ |
| 33 | cyclic = cyclic_register(cyclic_demo, 10 * 1000, "cyclic_demo", NULL); |
| 34 | if (!cyclic) |
| 35 | printf("Registering of cyclic_demo failed\n"); |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | This will register the function `cyclic_demo()` to be periodically |
| 41 | executed all 10ms. |
| 42 | |
| 43 | How is this cyclic functionality integrated / executed? |
| 44 | -------------------------------------------------------- |
| 45 | |
| 46 | The cyclic infrastructure integrates the main function responsible for |
| 47 | calling all registered cyclic functions cyclic_run() into the common |
| 48 | WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed |
| 49 | very often, which is necessary for the cyclic functions to get scheduled |
| 50 | and executed at their configured periods. |