1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * A general-purpose cyclic execution infrastructure, to allow "small"
4 * (run-time wise) functions to be executed at a specified frequency.
5 * Things like LED blinking or watchdog triggering are examples for such
14 #include <linux/list.h>
15 #include <asm/types.h>
16 #include <u-boot/schedule.h> // to be removed later
19 * struct cyclic_info - Information about cyclic execution function
21 * @func: Function to call periodically
22 * @name: Name of the cyclic function, e.g. shown in the commands
23 * @delay_us: Delay is us after which this function shall get executed
24 * @start_time_us: Start time in us, when this function started its execution
25 * @cpu_time_us: Total CPU time of this function
26 * @run_cnt: Counter of executions occurances
27 * @next_call: Next time in us, when the function shall be executed again
29 * @already_warned: Flag that we've warned about exceeding CPU time usage
31 * When !CONFIG_CYCLIC, this struct is empty.
34 #if defined(CONFIG_CYCLIC)
35 void (*func)(struct cyclic_info *c);
38 uint64_t start_time_us;
42 struct hlist_node list;
47 /** Function type for cyclic functions */
48 typedef void (*cyclic_func_t)(struct cyclic_info *c);
50 #if CONFIG_IS_ENABLED(CYCLIC)
53 * cyclic_register - Register a new cyclic function
55 * @cyclic: Cyclic info structure
56 * @func: Function to call periodically
57 * @delay_us: Delay is us after which this function shall get executed
58 * @name: Cyclic function name/id
60 * The function @func will be called with @cyclic as its
61 * argument. @cyclic will usually be embedded in some device-specific
62 * structure, which the callback can retrieve using container_of().
64 void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
65 uint64_t delay_us, const char *name);
68 * cyclic_unregister - Unregister a cyclic function
70 * @cyclic: Pointer to cyclic_struct of the function that shall be removed
72 void cyclic_unregister(struct cyclic_info *cyclic);
75 * cyclic_unregister_all() - Clean up cyclic functions
77 * This removes all cyclic functions
79 int cyclic_unregister_all(void);
82 * cyclic_get_list() - Get cyclic list pointer
84 * Return the cyclic list pointer
86 * @return: pointer to cyclic_list
88 struct hlist_head *cyclic_get_list(void);
92 static inline void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
93 uint64_t delay_us, const char *name)
97 static inline void cyclic_unregister(struct cyclic_info *cyclic)
101 static inline int cyclic_unregister_all(void)