Stefan Roese | 4736bec | 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 |
Weizhao Ouyang | 6cc9c3d | 2023-10-07 10:52:36 +0000 | [diff] [blame] | 11 | delayed too much. To detect cyclic functions with an excessive execution |
| 12 | time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` was introduced. |
| 13 | It defines the maximum allowable execution time for such a cyclic function. The |
| 14 | first time the execution of a cyclic function exceeds this interval, a warning |
| 15 | will be displayed indicating the problem to the user. |
Stefan Roese | 4736bec | 2022-09-02 13:57:53 +0200 | [diff] [blame] | 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. |