blob: 43bedacb9f88884cf56acb57ff4a129441f1d28c [file] [log] [blame]
Stefan Roese4736bec2022-09-02 13:57:53 +02001.. SPDX-License-Identifier: GPL-2.0+
2
3Cyclic functions
4================
5
6The cyclic function execution infrastruture provides a way to periodically
7execute code, e.g. every 100ms. Examples for such functions might be LED
8blinking etc. The functions that are hooked into this cyclic list should
9be small timewise as otherwise the execution of the other code that relies
10on a high frequent polling (e.g. UART rx char ready check) might be
11delayed too much. To detect cyclic functions with a too long execution
12time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` is introduced,
13which configures the max allowed time for such a cyclic function. If it's
14execution time exceeds this time, this cyclic function will get removed
15from the cyclic list.
16
17Registering a cyclic function
18-----------------------------
19
20To 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
40This will register the function `cyclic_demo()` to be periodically
41executed all 10ms.
42
43How is this cyclic functionality integrated / executed?
44--------------------------------------------------------
45
46The cyclic infrastructure integrates the main function responsible for
47calling all registered cyclic functions cyclic_run() into the common
48WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed
49very often, which is necessary for the cyclic functions to get scheduled
50and executed at their configured periods.