diff options
| author | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
| commit | c95c296e9915a38a666ae1a2575c2a4d0ba1d376 (patch) | |
| tree | c6e5a1ffe4ceb997e853ba0c3daffc9dc60c8b79 /src | |
| parent | f7ba146a01fcf23a2b06a141d1b1a56cb27b878c (diff) | |
| parent | 32a5668593c578b85560338c29d76f3a252c8dbc (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
# Conflicts:
# bsp/gd32/gd32107c-eval/rtconfig.h
Diffstat (limited to 'src')
| -rw-r--r-- | src/Kconfig | 4 | ||||
| -rw-r--r-- | src/device.c | 21 | ||||
| -rw-r--r-- | src/idle.c | 4 | ||||
| -rwxr-xr-x | src/ipc.c | 35 | ||||
| -rw-r--r-- | src/irq.c | 10 | ||||
| -rw-r--r-- | src/kservice.c | 19 | ||||
| -rw-r--r-- | src/mempool.c | 10 | ||||
| -rw-r--r-- | src/object.c | 19 | ||||
| -rw-r--r-- | src/scheduler.c | 11 | ||||
| -rw-r--r-- | src/thread.c | 60 | ||||
| -rw-r--r-- | src/timer.c | 58 |
11 files changed, 177 insertions, 74 deletions
diff --git a/src/Kconfig b/src/Kconfig index 69edd20641..6dc73bc400 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -8,10 +8,6 @@ config RT_NAME_MAX Each kernel object, such as thread, timer, semaphore etc, has a name, the RT_NAME_MAX is the maximal size of this object name. -config RT_USING_BIG_ENDIAN - bool - default n - config RT_USING_ARCH_DATA_TYPE bool "Use the data types defined in ARCH_CPU" default n diff --git a/src/device.c b/src/device.c index ebb8f26854..9bfaf776d6 100644 --- a/src/device.c +++ b/src/device.c @@ -82,6 +82,7 @@ RTM_EXPORT(rt_device_register); */ rt_err_t rt_device_unregister(rt_device_t dev) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); RT_ASSERT(rt_object_is_systemobject(&dev->parent)); @@ -143,6 +144,7 @@ RTM_EXPORT(rt_device_create); */ void rt_device_destroy(rt_device_t dev) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); RT_ASSERT(rt_object_is_systemobject(&dev->parent) == RT_FALSE); @@ -202,6 +204,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) { rt_err_t result = RT_EOK; + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -267,6 +270,7 @@ rt_err_t rt_device_close(rt_device_t dev) { rt_err_t result = RT_EOK; + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -312,6 +316,7 @@ rt_size_t rt_device_read(rt_device_t dev, void *buffer, rt_size_t size) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -354,6 +359,7 @@ rt_size_t rt_device_write(rt_device_t dev, const void *buffer, rt_size_t size) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -389,6 +395,7 @@ RTM_EXPORT(rt_device_write); */ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -412,10 +419,11 @@ RTM_EXPORT(rt_device_control); * * @return RT_EOK */ -rt_err_t -rt_device_set_rx_indicate(rt_device_t dev, - rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size)) +rt_err_t rt_device_set_rx_indicate(rt_device_t dev, + rt_err_t (*rx_ind)(rt_device_t dev, + rt_size_t size)) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -435,10 +443,11 @@ RTM_EXPORT(rt_device_set_rx_indicate); * * @return RT_EOK */ -rt_err_t -rt_device_set_tx_complete(rt_device_t dev, - rt_err_t (*tx_done)(rt_device_t dev, void *buffer)) +rt_err_t rt_device_set_tx_complete(rt_device_t dev, + rt_err_t (*tx_done)(rt_device_t dev, + void *buffer)) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); diff --git a/src/idle.c b/src/idle.c index f1db468e26..7ea0cd15de 100644 --- a/src/idle.c +++ b/src/idle.c @@ -45,7 +45,7 @@ #define _CPUS_NR 1 #endif /* RT_USING_SMP */ -static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);; +static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct); static struct rt_thread idle[_CPUS_NR]; ALIGN(RT_ALIGN_SIZE) @@ -241,7 +241,6 @@ static void rt_defunct_execute(void) } } -extern void rt_system_power_manager(void); static void rt_thread_idle_entry(void *parameter) { #ifdef RT_USING_SMP @@ -275,6 +274,7 @@ static void rt_thread_idle_entry(void *parameter) #endif /* RT_USING_SMP */ #ifdef RT_USING_PM + void rt_system_power_manager(void); rt_system_power_manager(); #endif /* RT_USING_PM */ } @@ -39,12 +39,24 @@ * 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 + * 2022-01-24 THEWON let rt_mutex_take return thread->error when using signal */ #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); @@ -714,8 +726,7 @@ RTM_EXPORT(rt_sem_control); * * @param flag is the mutex flag, which determines the queuing way of how multiple threads wait * when the mutex is not available. - * NOTE: The mutex flag can ONLY be RT_IPC_FLAG_PRIO. Using RT_IPC_FLAG_FIFO will seriously affect - * the real-time performance of the system. + * NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL. * * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. * If the return value is any other values, it represents the initialization failed. @@ -724,7 +735,8 @@ RTM_EXPORT(rt_sem_control); */ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) { - (void)flag; + /* flag parameter has been obsoleted */ + RT_UNUSED(flag); /* parameter check */ RT_ASSERT(mutex != RT_NULL); @@ -796,8 +808,7 @@ RTM_EXPORT(rt_mutex_detach); * * @param flag is the mutex flag, which determines the queuing way of how multiple threads wait * when the mutex is not available. - * NOTE: The mutex flag can ONLY be RT_IPC_FLAG_PRIO. Using RT_IPC_FLAG_FIFO will seriously affect - * the real-time performance of the system. + * NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL. * * @return Return a pointer to the mutex object. When the return value is RT_NULL, it means the creation failed. * @@ -806,7 +817,9 @@ RTM_EXPORT(rt_mutex_detach); rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) { struct rt_mutex *mutex; - (void)flag; + + /* flag parameter has been obsoleted */ + RT_UNUSED(flag); RT_DEBUG_NOT_IN_INTERRUPT; @@ -935,9 +948,6 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) } else { -#ifdef RT_USING_SIGNALS -__again: -#endif /* RT_USING_SIGNALS */ /* The value of mutex is 1 in initial status. Therefore, if the * value is great than 0, it indicates the mutex is avaible. */ @@ -1014,11 +1024,6 @@ __again: if (thread->error != RT_EOK) { -#ifdef RT_USING_SIGNALS - /* interrupt by signal, try it again */ - if (thread->error == -RT_EINTR) goto __again; -#endif /* RT_USING_SIGNALS */ - /* return error */ return thread->error; } @@ -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 459109ce75..d39d3c614e 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> @@ -460,7 +461,17 @@ RTM_EXPORT(rt_strncpy); */ char *rt_strcpy(char *dst, const char *src) { - return rt_strncpy(dst, src, (rt_size_t)-1); + char *dest = dst; + + while (*src != '\0') + { + *dst = *src; + dst++; + src++; + } + + *dst = '\0'; + return dest; } RTM_EXPORT(rt_strcpy); @@ -602,7 +613,7 @@ void rt_show_version(void) rt_kprintf("- RT - Thread Operating System\n"); rt_kprintf(" / | \\ %d.%d.%d build %s %s\n", RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__, __TIME__); - rt_kprintf(" 2006 - 2021 Copyright by rt-thread team\n"); + rt_kprintf(" 2006 - 2022 Copyright by RT-Thread team\n"); } RTM_EXPORT(rt_show_version); @@ -1745,6 +1756,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/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 6367119091..6123aaf42a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -27,7 +27,7 @@ * 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 - * + * 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 090f5f1ef7..30208f1dd1 100644 --- a/src/thread.c +++ b/src/thread.c @@ -28,13 +28,26 @@ * add support for tasks bound to cpu * 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 + * 2022-01-24 THEWON let rt_thread_sleep return thread->error when using signal */ #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); @@ -118,7 +131,7 @@ static void _thread_timeout(void *parameter) thread = (struct rt_thread *)parameter; - /* thread check */ + /* parameter 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); @@ -175,7 +188,6 @@ static rt_err_t _thread_init(struct rt_thread *thread, /* priority init */ RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX); - thread->init_priority = priority; thread->current_priority = priority; thread->number_mask = 0; @@ -278,7 +290,7 @@ rt_err_t rt_thread_init(struct rt_thread *thread, rt_uint8_t priority, rt_uint32_t tick) { - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(stack_start != RT_NULL); @@ -329,14 +341,11 @@ RTM_EXPORT(rt_thread_self); */ rt_err_t rt_thread_startup(rt_thread_t thread) { - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - /* set current priority to initialize priority */ - thread->current_priority = thread->init_priority; - /* calculate priority attribute */ #if RT_THREAD_PRIORITY_MAX > 32 thread->number = thread->current_priority >> 3; /* 5bit */ @@ -347,7 +356,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread) #endif /* RT_THREAD_PRIORITY_MAX > 32 */ RT_DEBUG_LOG(RT_DEBUG_THREAD, ("startup a thread:%s with priority:%d\n", - thread->name, thread->init_priority)); + thread->name, thread->current_priority)); /* change thread stat */ thread->stat = RT_THREAD_SUSPEND; /* then resume it */ @@ -375,7 +384,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread) { rt_base_t lock; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); @@ -478,7 +487,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) { rt_base_t lock; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); @@ -558,6 +567,9 @@ rt_err_t rt_thread_sleep(rt_tick_t tick) /* disable interrupt */ temp = rt_hw_interrupt_disable(); + /* reset thread error */ + thread->error = RT_EOK; + /* suspend thread */ rt_thread_suspend(thread); @@ -574,7 +586,7 @@ rt_err_t rt_thread_sleep(rt_tick_t tick) if (thread->error == -RT_ETIMEOUT) thread->error = RT_EOK; - return RT_EOK; + return thread->error; } /** @@ -617,6 +629,9 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) /* disable interrupt */ level = rt_hw_interrupt_disable(); + /* reset thread error */ + thread->error = RT_EOK; + cur_tick = rt_tick_get(); if (cur_tick - *tick < inc_tick) { @@ -649,7 +664,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) rt_hw_interrupt_enable(level); } - return RT_EOK; + return thread->error; } RTM_EXPORT(rt_thread_delay_until); @@ -695,7 +710,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) { register rt_base_t temp; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); @@ -797,7 +812,11 @@ RTM_EXPORT(rt_thread_control); /** * @brief This function will suspend the specified thread and change it to suspend state. * - * @note This function only can suspend current thread itself. + * @note This function ONLY can suspend current thread itself. + * Do not use the rt_thread_suspend and rt_thread_resume functions to synchronize the activities of threads. + * You have no way of knowing what code a thread is executing when you suspend it. + * If you suspend a thread while it is executing a critical area which is protected by a mutex, + * other threads attempt to use that mutex and have to wait. Deadlocks can occur very easily. * * @param thread is the thread to be suspended. * @@ -809,7 +828,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread) register rt_base_t stat; register rt_base_t temp; - /* thread check */ + /* parameter 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()); @@ -825,11 +844,6 @@ rt_err_t rt_thread_suspend(rt_thread_t thread) /* disable interrupt */ temp = rt_hw_interrupt_disable(); - if (stat == RT_THREAD_RUNNING) - { - /* not suspend running status thread on other core */ - RT_ASSERT(thread == rt_thread_self()); - } /* change thread stat */ rt_schedule_remove_thread(thread); @@ -849,6 +863,8 @@ RTM_EXPORT(rt_thread_suspend); /** * @brief This function will resume a thread and put it to system ready queue. * + * @note Do not use the rt_thread_suspend and rt_thread_resume functions to synchronize the activities of threads. + * * @param thread is the thread to be resumed. * * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed. @@ -858,7 +874,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread) { register rt_base_t temp; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); diff --git a/src/timer.c b/src/timer.c index 846c33263b..5d54f85dbd 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); @@ -232,9 +246,12 @@ void rt_timer_dump(rt_list_t timer_heads[]) * * @param parameter is the param of the callback * - * @param time is the ticks of timer + * @param time is timeout ticks of timer + * + * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1). * * @param flag is the flag of timer + * */ void rt_timer_init(rt_timer_t timer, const char *name, @@ -243,8 +260,10 @@ void rt_timer_init(rt_timer_t timer, rt_tick_t time, rt_uint8_t flag) { - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); + RT_ASSERT(timeout != RT_NULL); + RT_ASSERT(time < RT_TICK_MAX / 2); /* timer object initialization */ rt_object_init(&(timer->parent), RT_Object_Class_Timer, name); @@ -264,7 +283,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); RT_ASSERT(rt_object_is_systemobject(&timer->parent)); @@ -289,15 +308,17 @@ RTM_EXPORT(rt_timer_detach); /** * @brief This function will create a timer * - * @param name the name of timer + * @param name is the name of timer * - * @param timeout the timeout function + * @param timeout is the timeout function * - * @param parameter the parameter of timeout function + * @param parameter is the parameter of timeout function * - * @param time the tick of timer + * @param time is timeout ticks of the timer * - * @param flag the flag of timer + * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1). + * + * @param flag is the flag of timer * * @return the created timer object */ @@ -309,6 +330,10 @@ rt_timer_t rt_timer_create(const char *name, { struct rt_timer *timer; + /* parameter check */ + RT_ASSERT(timeout != RT_NULL); + RT_ASSERT(time < RT_TICK_MAX / 2); + /* allocate a object */ timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name); if (timer == RT_NULL) @@ -333,7 +358,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); RT_ASSERT(rt_object_is_systemobject(&timer->parent) == RT_FALSE); @@ -372,7 +397,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) unsigned int tst_nr; static unsigned int random_nr; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); @@ -387,11 +412,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent))); - /* - * get timeout tick, - * the max timeout tick shall not great than RT_TICK_MAX/2 - */ - RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); timer->timeout_tick = rt_tick_get() + timer->init_tick; #ifdef RT_USING_TIMER_SOFT @@ -497,7 +517,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); @@ -533,7 +553,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); @@ -567,6 +587,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) /*timer is stop*/ *(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED; } + case RT_TIMER_CTRL_GET_REMAIN_TIME: + *(rt_tick_t *)arg = timer->timeout_tick; break; default: |
