blob: 67831496a70608b5af4c672c05da9ca8375e2224 [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
Weizhao Ouyang6cc9c3d2023-10-07 10:52:36 +000011delayed too much. To detect cyclic functions with an excessive execution
12time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` was introduced.
13It defines the maximum allowable execution time for such a cyclic function. The
14first time the execution of a cyclic function exceeds this interval, a warning
15will be displayed indicating the problem to the user.
Stefan Roese4736bec2022-09-02 13:57:53 +020016
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.