summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyustli <[email protected]>2022-02-13 14:50:51 +0800
committerGitHub <[email protected]>2022-02-13 14:50:51 +0800
commit5178e7ec0ba0bb65c1bc9bde4c9421e695abb50a (patch)
tree21a674f410b81d6d375299b940faf2256062cb4c
parentd4b5555b7e4901f4d643d74696050e10b510421e (diff)
[add] src/clock.c add hook for rt_tick_increase (#5569)
* [add] src/clock.c add hook for rt_tick_increase * [fix] clock.c rt_tick_incerase hook function * Update clock.c Co-authored-by: guo <[email protected]>
-rw-r--r--include/rtthread.h3
-rw-r--r--src/clock.c28
2 files changed, 31 insertions, 0 deletions
diff --git a/include/rtthread.h b/include/rtthread.h
index 45a7655be9..729ee4c405 100644
--- a/include/rtthread.h
+++ b/include/rtthread.h
@@ -85,6 +85,9 @@ void rt_tick_set(rt_tick_t tick);
void rt_tick_increase(void);
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms);
rt_tick_t rt_tick_get_millisecond(void);
+#ifdef RT_USING_HOOK
+void rt_tick_sethook(void (*hook)(void));
+#endif
void rt_system_timer_init(void);
void rt_system_timer_thread_init(void);
diff --git a/src/clock.c b/src/clock.c
index 21be3a4203..0e88bf4d61 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -26,6 +26,32 @@
static volatile rt_tick_t rt_tick = 0;
#endif /* RT_USING_SMP */
+#ifndef __on_rt_tick_hook
+ #define __on_rt_tick_hook() __ON_HOOK_ARGS(rt_tick_hook, ())
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
+static void (*rt_tick_hook)(void);
+
+/**
+ * @addtogroup Hook
+ */
+
+/**@{*/
+
+/**
+ * This function will set a hook function, which will be invoked when tick increase
+ *
+ *
+ * @param hook the hook function
+ */
+void rt_tick_sethook(void (*hook)(void))
+{
+ rt_tick_hook = hook;
+}
+/**@}*/
+#endif /* RT_USING_HOOK */
+
/**
* @addtogroup Clock
*/
@@ -67,6 +93,8 @@ void rt_tick_increase(void)
struct rt_thread *thread;
rt_base_t level;
+ RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
+
level = rt_hw_interrupt_disable();
/* increase the global tick */