summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Kconfig15
-rwxr-xr-xsrc/ipc.c13
-rw-r--r--src/irq.c10
-rw-r--r--src/kservice.c15
-rw-r--r--src/memheap.c54
-rw-r--r--src/mempool.c10
-rw-r--r--src/object.c19
-rw-r--r--src/scheduler.c13
-rw-r--r--src/thread.c97
-rw-r--r--src/timer.c16
10 files changed, 183 insertions, 79 deletions
diff --git a/src/Kconfig b/src/Kconfig
index 7c22752ed0..69edd20641 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -84,6 +84,11 @@ config RT_USING_HOOK
help
Enable the hook function when system running, such as idle thread hook,
thread context switch etc.
+ if RT_USING_HOOK
+ config RT_HOOK_USING_FUNC_PTR
+ bool "Using function pointers as system hook"
+ default y
+ endif
config RT_USING_IDLE_HOOK
bool "Enable IDLE Task hook"
@@ -130,6 +135,16 @@ menu "kservice optimization"
bool "Enable kservice to use standard C library"
default n
+ if RT_KSERVICE_USING_STDLIB
+ config RT_KSERVICE_USING_STDLIB_MEMCPY
+ bool "Use memcpy to replace rt_memcpy (faster, but not safe)"
+ default n
+
+ config RT_KSERVICE_USING_STDLIB_MEMSET
+ bool "Use memset to replace rt_memset (faster, but not safe)"
+ default n
+ endif
+
config RT_KSERVICE_USING_TINY_SIZE
bool "Enable kservice to use tiny size"
default n
diff --git a/src/ipc.c b/src/ipc.c
index 2853590501..09cc74e103 100755
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -39,12 +39,23 @@
* 2020-10-11 Meco Man add value overflow-check code
* 2021-01-03 Meco Man implement rt_mb_urgent()
* 2021-05-30 Meco Man implement rt_mutex_trytake()
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to ipc.c
*/
#include <rtthread.h>
#include <rthw.h>
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_object_trytake_hook
+ #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent))
+#endif
+#ifndef __on_rt_object_take_hook
+ #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
+#endif
+#ifndef __on_rt_object_put_hook
+ #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
extern void (*rt_object_trytake_hook)(struct rt_object *object);
extern void (*rt_object_take_hook)(struct rt_object *object);
extern void (*rt_object_put_hook)(struct rt_object *object);
diff --git a/src/irq.c b/src/irq.c
index 3889a2a2c8..bc604718b2 100644
--- a/src/irq.c
+++ b/src/irq.c
@@ -10,12 +10,20 @@
* 2016-08-09 ArdaFu add interrupt enter and leave hook.
* 2018-11-22 Jesven rt_interrupt_get_nest function add disable irq
* 2021-08-15 Supperthomas fix the comment
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to irq.c
*/
#include <rthw.h>
#include <rtthread.h>
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_interrupt_enter_hook
+ #define __on_rt_interrupt_enter_hook() __ON_HOOK_ARGS(rt_interrupt_enter_hook, ())
+#endif
+#ifndef __on_rt_interrupt_leave_hook
+ #define __on_rt_interrupt_leave_hook() __ON_HOOK_ARGS(rt_interrupt_leave_hook, ())
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
static void (*rt_interrupt_enter_hook)(void);
static void (*rt_interrupt_leave_hook)(void);
diff --git a/src/kservice.c b/src/kservice.c
index fa0da4c7c4..f112ec92de 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -19,6 +19,7 @@
* 2015-07-06 Bernard Add rt_assert_handler routine.
* 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB
* 2021-12-20 Meco Man implement rt_strcpy()
+ * 2022-01-07 Gabriel add __on_rt_assert_hook
*/
#include <rtthread.h>
@@ -116,6 +117,7 @@ int *_rt_errno(void)
}
RTM_EXPORT(_rt_errno);
+#ifndef RT_KSERVICE_USING_STDLIB_MEMSET
/**
* This function will set the content of memory to specified value.
*
@@ -201,7 +203,9 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count)
#endif /* RT_KSERVICE_USING_TINY_SIZE */
}
RTM_EXPORT(rt_memset);
+#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */
+#ifndef RT_KSERVICE_USING_STDLIB_MEMCPY
/**
* This function will copy memory content from source address to destination address.
*
@@ -285,6 +289,7 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
#endif /* RT_KSERVICE_USING_TINY_SIZE */
}
RTM_EXPORT(rt_memcpy);
+#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */
#ifndef RT_KSERVICE_USING_STDLIB
@@ -1558,9 +1563,9 @@ RTM_EXPORT(rt_free);
*
* @param max_used is a pointer to get the maximum memory used.
*/
-RT_WEAK void rt_memory_info(rt_uint32_t *total,
- rt_uint32_t *used,
- rt_uint32_t *max_used)
+RT_WEAK void rt_memory_info(rt_size_t *total,
+ rt_size_t *used,
+ rt_size_t *max_used)
{
rt_base_t level;
@@ -1741,6 +1746,10 @@ int __rt_ffs(int value)
#endif /* RT_USING_TINY_FFS */
#endif /* RT_USING_CPU_FFS */
+#ifndef __on_rt_assert_hook
+ #define __on_rt_assert_hook(ex, func, line) __ON_HOOK_ARGS(rt_assert_hook, (ex, func, line))
+#endif
+
#ifdef RT_DEBUG
/* RT_ASSERT(EX)'s hook */
diff --git a/src/memheap.c b/src/memheap.c
index 62b42f73ed..71e43580f4 100644
--- a/src/memheap.c
+++ b/src/memheap.c
@@ -27,7 +27,7 @@
/* dynamic pool magic and mask */
#define RT_MEMHEAP_MAGIC 0x1ea01ea0
-#define RT_MEMHEAP_MASK 0xfffffffe
+#define RT_MEMHEAP_MASK 0xFFFFFFFE
#define RT_MEMHEAP_USED 0x01
#define RT_MEMHEAP_FREED 0x00
@@ -38,6 +38,16 @@
#define MEMITEM_SIZE(item) ((rt_ubase_t)item->next - (rt_ubase_t)item - RT_MEMHEAP_SIZE)
#define MEMITEM(ptr) (struct rt_memheap_item*)((rt_uint8_t*)ptr - RT_MEMHEAP_SIZE)
+static void _remove_next_ptr(struct rt_memheap_item *next_ptr)
+{
+ /* Fix the crash problem after opening Oz optimization on ac6 */
+ /* Fix IAR compiler warning */
+ next_ptr->next_free->prev_free = next_ptr->prev_free;
+ next_ptr->prev_free->next_free = next_ptr->next_free;
+ next_ptr->next->prev = next_ptr->prev;
+ next_ptr->prev->next = next_ptr->next;
+}
+
/**
* @brief This function initializes a piece of memory called memheap.
*
@@ -173,7 +183,7 @@ RTM_EXPORT(rt_memheap_detach);
void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size)
{
rt_err_t result;
- rt_uint32_t free_size;
+ rt_size_t free_size;
struct rt_memheap_item *header_ptr;
RT_ASSERT(heap != RT_NULL);
@@ -382,8 +392,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
if (newsize > oldsize)
{
void *new_ptr;
- /* Fix the crash problem after opening Oz optimization on ac6 */
- volatile struct rt_memheap_item *next_ptr;
+ struct rt_memheap_item *next_ptr;
if (heap->locked == RT_FALSE)
{
@@ -432,10 +441,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
next_ptr->next_free,
next_ptr->prev_free));
- next_ptr->next_free->prev_free = next_ptr->prev_free;
- next_ptr->prev_free->next_free = next_ptr->next_free;
- next_ptr->next->prev = next_ptr->prev;
- next_ptr->prev->next = next_ptr->next;
+ _remove_next_ptr(next_ptr);
/* build a new one on the right place */
next_ptr = (struct rt_memheap_item *)((char *)ptr + newsize);
@@ -593,13 +599,13 @@ void rt_memheap_free(void *ptr)
rt_err_t result;
struct rt_memheap *heap;
struct rt_memheap_item *header_ptr, *new_ptr;
- rt_uint32_t insert_header;
+ rt_bool_t insert_header;
/* NULL check */
if (ptr == RT_NULL) return;
/* set initial status as OK */
- insert_header = 1;
+ insert_header = RT_TRUE;
new_ptr = RT_NULL;
header_ptr = (struct rt_memheap_item *)
((rt_uint8_t *)ptr - RT_MEMHEAP_SIZE);
@@ -657,7 +663,7 @@ void rt_memheap_free(void *ptr)
/* move header pointer to previous. */
header_ptr = header_ptr->prev;
/* don't insert header to free list */
- insert_header = 0;
+ insert_header = RT_FALSE;
}
/* determine if the block can be merged with the next neighbor. */
@@ -685,10 +691,10 @@ void rt_memheap_free(void *ptr)
{
struct rt_memheap_item *n = heap->free_list->next_free;;
#if defined(RT_MEMHEAP_BSET_MODE)
- rt_uint32_t blk_size = MEMITEM_SIZE(header_ptr);
+ rt_size_t blk_size = MEMITEM_SIZE(header_ptr);
for (;n != heap->free_list; n = n->next_free)
{
- rt_uint32_t m = MEMITEM_SIZE(n);
+ rt_size_t m = MEMITEM_SIZE(n);
if (blk_size <= m)
{
break;
@@ -732,9 +738,9 @@ RTM_EXPORT(rt_memheap_free);
* @param max_used is a pointer to get the maximum memory used.
*/
void rt_memheap_info(struct rt_memheap *heap,
- rt_uint32_t *total,
- rt_uint32_t *used,
- rt_uint32_t *max_used)
+ rt_size_t *total,
+ rt_size_t *used,
+ rt_size_t *max_used)
{
rt_err_t result;
@@ -898,10 +904,10 @@ int memheapcheck(int argc, char *argv[])
break;
}
/* check next and prev */
- if (!((rt_uint32_t)item->next <= (rt_uint32_t)((rt_uint32_t)heap->start_addr + heap->pool_size) &&
- (rt_uint32_t)item->prev >= (rt_uint32_t)heap->start_addr) &&
- (rt_uint32_t)item->next == RT_ALIGN((rt_uint32_t)item->next, RT_ALIGN_SIZE) &&
- (rt_uint32_t)item->prev == RT_ALIGN((rt_uint32_t)item->prev, RT_ALIGN_SIZE))
+ if (!((rt_ubase_t)item->next <= (rt_ubase_t)((rt_ubase_t)heap->start_addr + heap->pool_size) &&
+ (rt_ubase_t)item->prev >= (rt_ubase_t)heap->start_addr) &&
+ (rt_ubase_t)item->next == RT_ALIGN((rt_ubase_t)item->next, RT_ALIGN_SIZE) &&
+ (rt_ubase_t)item->prev == RT_ALIGN((rt_ubase_t)item->prev, RT_ALIGN_SIZE))
{
has_bad = RT_TRUE;
break;
@@ -919,7 +925,7 @@ int memheapcheck(int argc, char *argv[])
{
rt_kprintf("Memory block wrong:\n");
rt_kprintf("name: %s\n", heap->parent.name);
- rt_kprintf("item: 0x%08x\n", item);
+ rt_kprintf("item: 0x%p\n", item);
}
return 0;
}
@@ -948,7 +954,7 @@ int memheaptrace(int argc, char *argv[])
/* memheap dump */
rt_kprintf("\nmemory heap address:\n");
rt_kprintf("name : %s\n", mh->parent.name);
- rt_kprintf("heap_ptr: 0x%08x\n", mh->start_addr);
+ rt_kprintf("heap_ptr: 0x%p\n", mh->start_addr);
rt_kprintf("free : 0x%08x\n", mh->available_size);
rt_kprintf("max_used: 0x%08x\n", mh->max_used_size);
rt_kprintf("size : 0x%08x\n", mh->pool_size);
@@ -960,7 +966,7 @@ int memheaptrace(int argc, char *argv[])
{
if ((header_ptr->magic & RT_MEMHEAP_MASK) != RT_MEMHEAP_MAGIC)
{
- rt_kprintf("[0x%08x - incorrect magic: 0x%08x\n",
+ rt_kprintf("[0x%p - incorrect magic: 0x%08x\n",
header_ptr, header_ptr->magic);
break;
}
@@ -969,7 +975,7 @@ int memheaptrace(int argc, char *argv[])
if (block_size < 0)
break;
- rt_kprintf("[0x%08x - ", header_ptr);
+ rt_kprintf("[0x%p - ", header_ptr);
if (block_size < 1024)
rt_kprintf("%5d", block_size);
else if (block_size < 1024 * 1024)
diff --git a/src/mempool.c b/src/mempool.c
index 09a4955eee..ea0ea94cfa 100644
--- a/src/mempool.c
+++ b/src/mempool.c
@@ -14,6 +14,7 @@
* 2010-10-26 yi.qiu add module support in rt_mp_delete
* 2011-01-24 Bernard add object allocation check.
* 2012-03-22 Bernard fix align issue in rt_mp_init and rt_mp_create.
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to mempool.c
*/
#include <rthw.h>
@@ -21,7 +22,14 @@
#ifdef RT_USING_MEMPOOL
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_mp_alloc_hook
+ #define __on_rt_mp_alloc_hook(mp, block) __ON_HOOK_ARGS(rt_mp_alloc_hook, (mp, block))
+#endif
+#ifndef __on_rt_mp_free_hook
+ #define __on_rt_mp_free_hook(mp, block) __ON_HOOK_ARGS(rt_mp_free_hook, (mp, block))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
static void (*rt_mp_alloc_hook)(struct rt_mempool *mp, void *block);
static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block);
diff --git a/src/object.c b/src/object.c
index 76534f4566..259d82fc62 100644
--- a/src/object.c
+++ b/src/object.c
@@ -13,6 +13,7 @@
* 2010-10-26 yi.qiu add module support in rt_object_allocate and rt_object_free
* 2017-12-10 Bernard Add object_info enum.
* 2018-01-25 Bernard Fix the object find issue when enable MODULE.
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to object.c
*/
#include <rtthread.h>
@@ -113,7 +114,23 @@ static struct rt_object_information _object_container[RT_Object_Info_Unknown] =
#endif
};
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_object_attach_hook
+ #define __on_rt_object_attach_hook(obj) __ON_HOOK_ARGS(rt_object_attach_hook, (obj))
+#endif
+#ifndef __on_rt_object_detach_hook
+ #define __on_rt_object_detach_hook(obj) __ON_HOOK_ARGS(rt_object_detach_hook, (obj))
+#endif
+#ifndef __on_rt_object_trytake_hook
+ #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent))
+#endif
+#ifndef __on_rt_object_take_hook
+ #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
+#endif
+#ifndef __on_rt_object_put_hook
+ #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
static void (*rt_object_attach_hook)(struct rt_object *object);
static void (*rt_object_detach_hook)(struct rt_object *object);
void (*rt_object_trytake_hook)(struct rt_object *object);
diff --git a/src/scheduler.c b/src/scheduler.c
index 6ef02f3d3c..6123aaf42a 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -26,8 +26,8 @@
* add _scheduler_get_highest_priority_thread to find highest priority task
* rt_schedule_insert_thread won't insert current task to ready queue
* in smp version, rt_hw_context_switch_interrupt maybe switch to
- * new task directly
- *
+ * new task directly
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to scheduler.c
*/
#include <rtthread.h>
@@ -47,7 +47,14 @@ struct rt_thread *rt_current_thread = RT_NULL;
rt_uint8_t rt_current_priority;
#endif /* RT_USING_SMP */
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_scheduler_hook
+ #define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to))
+#endif
+#ifndef __on_rt_scheduler_switch_hook
+ #define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to);
static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);
diff --git a/src/thread.c b/src/thread.c
index 2f06cedd44..d1cc848777 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -29,13 +29,24 @@
* 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it
* 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit
* 2021-12-27 Meco Man remove .init_priority
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to thread.c
*/
#include <rthw.h>
#include <rtthread.h>
#include <stddef.h>
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_thread_inited_hook
+ #define __on_rt_thread_inited_hook(thread) __ON_HOOK_ARGS(rt_thread_inited_hook, (thread))
+#endif
+#ifndef __on_rt_thread_suspend_hook
+ #define __on_rt_thread_suspend_hook(thread) __ON_HOOK_ARGS(rt_thread_suspend_hook, (thread))
+#endif
+#ifndef __on_rt_thread_resume_hook
+ #define __on_rt_thread_resume_hook(thread) __ON_HOOK_ARGS(rt_thread_resume_hook, (thread))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
static void (*rt_thread_suspend_hook)(rt_thread_t thread);
static void (*rt_thread_resume_hook) (rt_thread_t thread);
static void (*rt_thread_inited_hook) (rt_thread_t thread);
@@ -106,6 +117,43 @@ static void _thread_exit(void)
rt_schedule();
}
+/**
+ * @brief This function is the timeout function for thread, normally which is invoked
+ * when thread is timeout to wait some resource.
+ *
+ * @param parameter is the parameter of thread timeout function
+ */
+static void _thread_timeout(void *parameter)
+{
+ struct rt_thread *thread;
+ register rt_base_t temp;
+
+ thread = (struct rt_thread *)parameter;
+
+ /* thread check */
+ RT_ASSERT(thread != RT_NULL);
+ RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND);
+ RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
+
+ /* disable interrupt */
+ temp = rt_hw_interrupt_disable();
+
+ /* set error number */
+ thread->error = -RT_ETIMEOUT;
+
+ /* remove from suspend list */
+ rt_list_remove(&(thread->tlist));
+
+ /* insert to schedule ready list */
+ rt_schedule_insert_thread(thread);
+
+ /* enable interrupt */
+ rt_hw_interrupt_enable(temp);
+
+ /* do schedule */
+ rt_schedule();
+}
+
static rt_err_t _thread_init(struct rt_thread *thread,
const char *name,
void (*entry)(void *parameter),
@@ -173,7 +221,7 @@ static rt_err_t _thread_init(struct rt_thread *thread,
/* initialize thread timer */
rt_timer_init(&(thread->thread_timer),
thread->name,
- rt_thread_timeout,
+ _thread_timeout,
thread,
0,
RT_TIMER_FLAG_ONE_SHOT);
@@ -757,8 +805,7 @@ RTM_EXPORT(rt_thread_control);
/**
* @brief This function will suspend the specified thread and change it to suspend state.
*
- * @note If suspend self thread, after this function call, the
- * rt_schedule() must be invoked.
+ * @note This function only can suspend current thread itself.
*
* @param thread is the thread to be suspended.
*
@@ -773,14 +820,14 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
/* thread check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
+ RT_ASSERT(thread == rt_thread_self());
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: %s\n", thread->name));
stat = thread->stat & RT_THREAD_STAT_MASK;
if ((stat != RT_THREAD_READY) && (stat != RT_THREAD_RUNNING))
{
- RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: thread disorder, 0x%2x\n",
- thread->stat));
+ RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: thread disorder, 0x%2x\n", thread->stat));
return -RT_ERROR;
}
@@ -853,44 +900,6 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
RTM_EXPORT(rt_thread_resume);
/**
- * @brief This function is the timeout function for thread, normally which is invoked
- * when thread is timeout to wait some resource.
- *
- * @param parameter is the parameter of thread timeout function
- */
-void rt_thread_timeout(void *parameter)
-{
- struct rt_thread *thread;
- register rt_base_t temp;
-
- thread = (struct rt_thread *)parameter;
-
- /* thread check */
- RT_ASSERT(thread != RT_NULL);
- RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND);
- RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
-
- /* disable interrupt */
- temp = rt_hw_interrupt_disable();
-
- /* set error number */
- thread->error = -RT_ETIMEOUT;
-
- /* remove from suspend list */
- rt_list_remove(&(thread->tlist));
-
- /* insert to schedule ready list */
- rt_schedule_insert_thread(thread);
-
- /* enable interrupt */
- rt_hw_interrupt_enable(temp);
-
- /* do schedule */
- rt_schedule();
-}
-RTM_EXPORT(rt_thread_timeout);
-
-/**
* @brief This function will find the specified thread.
*
* @note Please don't invoke this function in interrupt status.
diff --git a/src/timer.c b/src/timer.c
index 846c33263b..da113298da 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -17,6 +17,7 @@
* 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
* timeout function.
* 2021-08-15 supperthomas add the comment
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to timer.c
*/
#include <rtthread.h>
@@ -47,7 +48,20 @@ ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
#endif /* RT_USING_TIMER_SOFT */
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_object_take_hook
+ #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
+#endif
+#ifndef __on_rt_object_put_hook
+ #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
+#endif
+#ifndef __on_rt_timer_enter_hook
+ #define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t))
+#endif
+#ifndef __on_rt_timer_exit_hook
+ #define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
extern void (*rt_object_take_hook)(struct rt_object *object);
extern void (*rt_object_put_hook)(struct rt_object *object);
static void (*rt_timer_enter_hook)(struct rt_timer *timer);