"Das U-Boot" Source Tree
at master 56 lines 2.0 kB view raw
1.. 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 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. 16 17Registering a cyclic function 18----------------------------- 19 20To register a cyclic function, use something like this:: 21 22 struct donkey { 23 struct cyclic_info cyclic; 24 void (*say)(const char *s); 25 }; 26 27 static void cyclic_demo(struct cyclic_info *c) 28 { 29 struct donkey *donkey = container_of(c, struct donkey, cyclic); 30 31 donkey->say("Are we there yet?"); 32 } 33 34 int donkey_init(void) 35 { 36 struct donkey *donkey; 37 38 /* Initialize donkey ... */ 39 40 /* Register demo cyclic function */ 41 cyclic_register(&donkey->cyclic, cyclic_demo, 10 * 1000, "cyclic_demo"); 42 43 return 0; 44 } 45 46This will register the function `cyclic_demo()` to be periodically 47executed all 10ms. 48 49How is this cyclic functionality integrated / executed? 50-------------------------------------------------------- 51 52The cyclic infrastructure integrates cyclic_run(), the main function 53responsible for calling all registered cyclic functions, into the 54common schedule() function. This guarantees that cyclic_run() is 55executed very often, which is necessary for the cyclic functions to 56get scheduled and executed at their configured periods.