From 160811b77a26ff6324adc46fbfdec38901f68adc Mon Sep 17 00:00:00 2001 From: David Lin Date: Thu, 23 Jul 2020 19:35:31 +0800 Subject: Minor optimization for mempool.c 1. Improve code readability, unify the variable name in functions "rt_hw_interrupt_enable(level);" and "rt_hw_interrupt_enable(level);", so changed variable "temp" to "level"; --- src/mempool.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mempool.c b/src/mempool.c index 00471efb35..db614032aa 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -134,7 +134,7 @@ RTM_EXPORT(rt_mp_init); rt_err_t rt_mp_detach(struct rt_mempool *mp) { struct rt_thread *thread; - register rt_ubase_t temp; + register rt_ubase_t level; /* parameter check */ RT_ASSERT(mp != RT_NULL); @@ -145,7 +145,7 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp) while (!rt_list_isempty(&(mp->suspend_thread))) { /* disable interrupt */ - temp = rt_hw_interrupt_disable(); + level = rt_hw_interrupt_disable(); /* get next suspend thread */ thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist); @@ -160,7 +160,7 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp) rt_thread_resume(thread); /* enable interrupt */ - rt_hw_interrupt_enable(temp); + rt_hw_interrupt_enable(level); } /* detach object */ @@ -250,7 +250,7 @@ RTM_EXPORT(rt_mp_create); rt_err_t rt_mp_delete(rt_mp_t mp) { struct rt_thread *thread; - register rt_ubase_t temp; + register rt_ubase_t level; RT_DEBUG_NOT_IN_INTERRUPT; @@ -263,7 +263,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp) while (!rt_list_isempty(&(mp->suspend_thread))) { /* disable interrupt */ - temp = rt_hw_interrupt_disable(); + level = rt_hw_interrupt_disable(); /* get next suspend thread */ thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist); @@ -278,7 +278,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp) rt_thread_resume(thread); /* enable interrupt */ - rt_hw_interrupt_enable(temp); + rt_hw_interrupt_enable(level); } /* release allocated room */ -- cgit v1.3.1 From 3ed84b8d03dc9778f1c262278e2b8653de834408 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 24 Jul 2020 21:13:56 +0800 Subject: 解决yield操作不能及时释放cpu的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 3 +-- src/scheduler.c | 6 +++--- src/thread.c | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 97a09ddeaf..a91cd829b6 100644 --- a/src/clock.c +++ b/src/clock.c @@ -91,8 +91,7 @@ void rt_tick_increase(void) thread->stat |= RT_THREAD_STAT_YIELD; - /* yield */ - rt_thread_yield(); + rt_schedule(); } /* check timer */ diff --git a/src/scheduler.c b/src/scheduler.c index 6baaa9627a..d0859e745a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -350,9 +350,9 @@ void rt_schedule(void) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) @@ -448,9 +448,9 @@ void rt_schedule(void) } else { - rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; need_insert_from_thread = 1; } + rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } if (to_thread != rt_current_thread) @@ -599,9 +599,9 @@ void rt_scheduler_do_irq_switch(void *context) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) diff --git a/src/thread.c b/src/thread.c index 715596b132..60aa17f381 100644 --- a/src/thread.c +++ b/src/thread.c @@ -478,7 +478,15 @@ RTM_EXPORT(rt_thread_delete); */ rt_err_t rt_thread_yield(void) { + struct rt_thread *thread; + rt_base_t lock; + + thread = rt_thread_self(); + lock = rt_hw_interrupt_disable(); + thread->remaining_tick = thread->init_tick; + thread->stat |= RT_THREAD_STAT_YIELD; rt_schedule(); + rt_hw_interrupt_enable(lock); return RT_EOK; } -- cgit v1.3.1 From b328c1cbac55d6ed9ab4708611e20961a28f27f1 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 11:36:57 +0800 Subject: [modify] if ... else if constructs to be terminated with an else clause, which other option is invalid and delete surplus space. --- src/ipc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..876d8df3a1 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1080,6 +1080,13 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set) status = RT_EOK; } } + else + { + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + return -RT_EINVAL; + } /* move node to the next */ n = n->next; @@ -1186,10 +1193,10 @@ rt_err_t rt_event_recv(rt_event_t event, { /* no waiting */ thread->error = -RT_ETIMEOUT; - + /* enable interrupt */ rt_hw_interrupt_enable(level); - + return -RT_ETIMEOUT; } else -- cgit v1.3.1 From 55cfefd90a58e7e0d33e13714f21fb75a9718010 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 11:49:52 +0800 Subject: [add] switch default clause --- src/ipc.c | 3 +++ src/timer.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..dd681f2892 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -117,6 +117,9 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, rt_list_insert_before(list, &(thread->tlist)); } break; + + default: + break; } return RT_EOK; diff --git a/src/timer.c b/src/timer.c index 28a5a9e494..4d12c7ec78 100644 --- a/src/timer.c +++ b/src/timer.c @@ -500,7 +500,10 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) /*timer is stop*/ *(rt_tick_t *)arg = RT_TIMER_FLAG_DEACTIVATED; } - break; + break; + + default: + break; } return RT_EOK; -- cgit v1.3.1 From a78c6bedea2bb4e9833fdb2cc22f3af813724609 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 14:01:30 +0800 Subject: [add] a macro to be isolated while using signals in rt_mutex_take function. --- src/ipc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..b0efdd1320 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -685,7 +685,9 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) } else { +#ifdef RT_USING_SIGNALS __again: +#endif /* end of 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. */ @@ -754,8 +756,10 @@ __again: if (thread->error != RT_EOK) { +#ifdef RT_USING_SIGNALS /* interrupt by signal, try it again */ if (thread->error == -RT_EINTR) goto __again; +#endif /* end of RT_USING_SIGNALS */ /* return error */ return thread->error; -- cgit v1.3.1 From 9f41cbced8058faf40b54353b1d9d981650b1b3e Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 14:18:16 +0800 Subject: [format] code style of rt_strcmp function --- src/kservice.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 1705ce5283..dd7458f106 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -456,7 +456,10 @@ RTM_EXPORT(rt_strncmp); rt_int32_t rt_strcmp(const char *cs, const char *ct) { while (*cs && *cs == *ct) - cs++, ct++; + { + cs++; + ct++; + } return (*cs - *ct); } -- cgit v1.3.1 From 984e8e5651d98be190c4607b087ca6907026e96a Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Fri, 24 Jul 2020 11:53:57 +0800 Subject: [modify] internal function 'isdigit' name to '_ISDIGIT' --- src/kservice.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 1705ce5283..cf03fb59b1 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -543,7 +543,7 @@ void rt_show_version(void) RTM_EXPORT(rt_show_version); /* private function */ -#define isdigit(c) ((unsigned)((c) - '0') < 10) +#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10) #ifdef RT_PRINTF_LONGLONG rt_inline int divide(long long *n, int base) @@ -588,7 +588,7 @@ rt_inline int divide(long *n, int base) rt_inline int skip_atoi(const char **s) { register int i = 0; - while (isdigit(**s)) + while (_ISDIGIT(**s)) i = i * 10 + *((*s)++) - '0'; return i; @@ -834,7 +834,7 @@ rt_int32_t rt_vsnprintf(char *buf, /* get field width */ field_width = -1; - if (isdigit(*fmt)) field_width = skip_atoi(&fmt); + if (_ISDIGIT(*fmt)) field_width = skip_atoi(&fmt); else if (*fmt == '*') { ++ fmt; @@ -853,7 +853,7 @@ rt_int32_t rt_vsnprintf(char *buf, if (*fmt == '.') { ++ fmt; - if (isdigit(*fmt)) precision = skip_atoi(&fmt); + if (_ISDIGIT(*fmt)) precision = skip_atoi(&fmt); else if (*fmt == '*') { ++ fmt; -- cgit v1.3.1 From 0e619491163d2e2b4c1cc262f0faee3b1ced55b7 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Tue, 28 Jul 2020 09:55:01 +0800 Subject: avoid deadlock (rt_hw_interrupt_disable and rt_enter_critical when enable smp) --- src/scheduler.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/scheduler.c b/src/scheduler.c index 6baaa9627a..0c1bf1e506 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -33,10 +33,6 @@ #include #include -#ifdef RT_USING_SMP -rt_hw_spinlock_t _rt_critical_lock; -#endif /*RT_USING_SMP*/ - rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX]; rt_uint32_t rt_thread_ready_priority_group; #if RT_THREAD_PRIORITY_MAX > 32 @@ -851,7 +847,7 @@ void rt_enter_critical(void) if (!current_thread) { rt_hw_local_irq_enable(level); - return ; + return; } /* @@ -859,12 +855,15 @@ void rt_enter_critical(void) * enough and does not check here */ - /* lock scheduler for all cpus */ - if (current_thread->critical_lock_nest == 0) { - rt_hw_spin_lock(&_rt_critical_lock); + register rt_uint16_t lock_nest = current_thread->cpus_lock_nest; + current_thread->cpus_lock_nest++; + if (lock_nest == 0) + { + current_thread->scheduler_lock_nest ++; + rt_hw_spin_lock(&_cpus_lock); + } } - /* critical for local cpu */ current_thread->critical_lock_nest ++; @@ -910,16 +909,18 @@ void rt_exit_critical(void) if (!current_thread) { rt_hw_local_irq_enable(level); - return ; + return; } current_thread->scheduler_lock_nest --; current_thread->critical_lock_nest --; - if (current_thread->critical_lock_nest == 0) + current_thread->cpus_lock_nest--; + if (current_thread->cpus_lock_nest == 0) { - rt_hw_spin_unlock(&_rt_critical_lock); + current_thread->scheduler_lock_nest --; + rt_hw_spin_unlock(&_cpus_lock); } if (current_thread->scheduler_lock_nest <= 0) -- cgit v1.3.1 From 1fe077a0be8636a3aeb39b897373f493da06f9c6 Mon Sep 17 00:00:00 2001 From: Meco <920369182@qq.com> Date: Wed, 29 Jul 2020 09:57:32 +0800 Subject: fix在rt_event_recv函数中,如果事件已经满足无需阻塞的情况下,没有给thread->event_set/event_info赋值的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..c67909cfe0 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -34,6 +34,8 @@ * 2013-09-14 Grissiom add an option check in rt_event_recv * 2018-10-02 Bernard add 64bit support for mailbox * 2019-09-16 tyx add send wait support for message queue + * 2020-07-29 Meco Man fix thread->event_set/event_info when received an + event without pending */ #include @@ -1177,7 +1179,11 @@ rt_err_t rt_event_recv(rt_event_t event, /* set received event */ if (recved) *recved = (event->set & set); - + + /* fill thread event info */ + thread->event_set = (event->set & set); + thread->event_info = option; + /* received event */ if (option & RT_EVENT_FLAG_CLEAR) event->set &= ~set; -- cgit v1.3.1 From 76d1651a7463eb4bdf1215bd28dd289647fd11eb Mon Sep 17 00:00:00 2001 From: xieyangrun Date: Sat, 15 Aug 2020 20:15:29 +0800 Subject: fixed the iterator failure for softtimer list timeout check. --- src/timer.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 4d12c7ec78..52707f2306 100644 --- a/src/timer.c +++ b/src/timer.c @@ -595,20 +595,19 @@ rt_tick_t rt_timer_next_timeout_tick(void) void rt_soft_timer_check(void) { rt_tick_t current_tick; - rt_list_t *n; struct rt_timer *t; RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n")); - current_tick = rt_tick_get(); - /* lock scheduler */ rt_enter_critical(); - for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next; - n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]);) + while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { - t = rt_list_entry(n, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); + t = rt_list_entry(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); + + current_tick = rt_tick_get(); /* * It supposes that the new tick shall less than the half duration of @@ -618,9 +617,6 @@ void rt_soft_timer_check(void) { RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); - /* move node to the next */ - n = n->next; - /* remove timer from timer list firstly */ _rt_timer_remove(t); @@ -629,9 +625,6 @@ void rt_soft_timer_check(void) /* call timeout function */ t->timeout_func(t->parameter); - /* re-get tick */ - current_tick = rt_tick_get(); - RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); -- cgit v1.3.1 From c15a7858c9a7bc1f978faa5f0ea3f618fbd3bc03 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Fri, 14 Aug 2020 15:52:35 +0800 Subject: [fix] thread control bug about RT_THREAD_CTRL_CLOSE command --- src/thread.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 715596b132..9f80482b20 100644 --- a/src/thread.c +++ b/src/thread.c @@ -679,9 +679,17 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) case RT_THREAD_CTRL_STARTUP: return rt_thread_startup(thread); -#ifdef RT_USING_HEAP case RT_THREAD_CTRL_CLOSE: - return rt_thread_delete(thread); + + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + return rt_thread_detach(thread); + } +#ifdef RT_USING_HEAP + else + { + return rt_thread_delete(thread); + } #endif #ifdef RT_USING_SMP -- cgit v1.3.1 From 731e64f0c5e451f9408ad94da5de64f74bf4639b Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 4 Sep 2020 12:12:01 +0800 Subject: 修正多核rt_schedule_remove_thread时pcpu的ready_table判断问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scheduler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/scheduler.c b/src/scheduler.c index 0c1bf1e506..699c817270 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -784,7 +784,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread) { #if RT_THREAD_PRIORITY_MAX > 32 pcpu->ready_table[thread->number] &= ~thread->high_mask; - if (rt_thread_ready_table[thread->number] == 0) + if (pcpu->ready_table[thread->number] == 0) { pcpu->priority_group &= ~thread->number_mask; } -- cgit v1.3.1 From 1c6700acfdc6df71e14361d1c586ca32bb731e44 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 30 Sep 2020 23:50:18 +0800 Subject: [kernel] fix the timer issue --- src/timer.c | 85 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 52707f2306..4b9003794c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -25,6 +25,10 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #ifdef RT_USING_TIMER_SOFT + +#define RT_SOFT_TIMER_IDLE 1 +#define RT_SOFT_TIMER_BUSY 0 + #ifndef RT_TIMER_THREAD_STACK_SIZE #define RT_TIMER_THREAD_STACK_SIZE 512 #endif @@ -33,6 +37,8 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #define RT_TIMER_THREAD_PRIO 0 #endif +/* soft timer status */ +static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE; /* soft timer list */ static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; static struct rt_thread timer_thread; @@ -221,6 +227,8 @@ rt_err_t rt_timer_detach(rt_timer_t timer) level = rt_hw_interrupt_disable(); _rt_timer_remove(timer); + /* stop timer */ + timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -284,6 +292,8 @@ rt_err_t rt_timer_delete(rt_timer_t timer) level = rt_hw_interrupt_disable(); _rt_timer_remove(timer); + /* stop timer */ + timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -408,7 +418,8 @@ rt_err_t rt_timer_start(rt_timer_t timer) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { /* check whether timer thread is ready */ - if ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND) + if ((soft_timer_status == RT_SOFT_TIMER_IDLE) && + ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume timer thread to check soft timer */ rt_thread_resume(&timer_thread); @@ -445,13 +456,12 @@ rt_err_t rt_timer_stop(rt_timer_t timer) level = rt_hw_interrupt_disable(); _rt_timer_remove(timer); + /* change status */ + timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* enable interrupt */ rt_hw_interrupt_enable(level); - /* change stat */ - timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - return RT_EOK; } RTM_EXPORT(rt_timer_stop); @@ -467,10 +477,13 @@ RTM_EXPORT(rt_timer_stop); */ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { + register rt_base_t level; + /* timer check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); + level = rt_hw_interrupt_disable(); switch (cmd) { case RT_TIMER_CTRL_GET_TIME: @@ -505,6 +518,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) default: break; } + rt_hw_interrupt_enable(level); return RT_EOK; } @@ -521,6 +535,7 @@ void rt_timer_check(void) struct rt_timer *t; rt_tick_t current_tick; register rt_base_t level; + rt_list_t list = RT_LIST_OBJECT_INIT(list); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n")); @@ -544,7 +559,12 @@ void rt_timer_check(void) /* remove timer from timer list firstly */ _rt_timer_remove(t); - + if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) + { + t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; + } + /* add timer to temporary list */ + rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); /* call timeout function */ t->timeout_func(t->parameter); @@ -554,6 +574,12 @@ void rt_timer_check(void) RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); + /* Check whether the timer object is detached or started again */ + if (rt_list_isempty(&list)) + { + continue; + } + if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && (t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) { @@ -561,14 +587,8 @@ void rt_timer_check(void) t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; rt_timer_start(t); } - else - { - /* stop timer */ - t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - } } - else - break; + else break; } /* enable interrupt */ @@ -589,18 +609,20 @@ rt_tick_t rt_timer_next_timeout_tick(void) #ifdef RT_USING_TIMER_SOFT /** - * This function will check timer list, if a timeout event happens, the + * This function will check software-timer list, if a timeout event happens, the * corresponding timeout function will be invoked. */ void rt_soft_timer_check(void) { rt_tick_t current_tick; struct rt_timer *t; + register rt_base_t level; + rt_list_t list = RT_LIST_OBJECT_INIT(list); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n")); - /* lock scheduler */ - rt_enter_critical(); + /* disable interrupt */ + level = rt_hw_interrupt_disable(); while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { @@ -619,17 +641,32 @@ void rt_soft_timer_check(void) /* remove timer from timer list firstly */ _rt_timer_remove(t); + if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) + { + t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; + } + /* add timer to temporary list */ + rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); + + soft_timer_status = RT_SOFT_TIMER_BUSY; + /* enable interrupt */ + rt_hw_interrupt_enable(level); - /* not lock scheduler when performing timeout function */ - rt_exit_critical(); /* call timeout function */ t->timeout_func(t->parameter); RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); - /* lock scheduler */ - rt_enter_critical(); + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + + soft_timer_status = RT_SOFT_TIMER_IDLE; + /* Check whether the timer object is detached or started again */ + if (rt_list_isempty(&list)) + { + continue; + } if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && (t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) @@ -638,17 +675,11 @@ void rt_soft_timer_check(void) t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; rt_timer_start(t); } - else - { - /* stop timer */ - t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - } } else break; /* not check anymore */ } - - /* unlock scheduler */ - rt_exit_critical(); + /* enable interrupt */ + rt_hw_interrupt_enable(level); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n")); } -- cgit v1.3.1 From 2469335e213d6f2875d0b61575ceebd1f2a26509 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sun, 11 Oct 2020 17:54:39 +0800 Subject: [fix bug] #3951 --- src/ipc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 5646fc7f40..dc347119ae 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -35,7 +35,9 @@ * 2018-10-02 Bernard add 64bit support for mailbox * 2019-09-16 tyx add send wait support for message queue * 2020-07-29 Meco Man fix thread->event_set/event_info when received an - event without pending + * event without pending + * 2020-10-11 Meco Man add semaphore values' overflow-check code + * in the function of rt_sem_release */ #include @@ -463,7 +465,17 @@ rt_err_t rt_sem_release(rt_sem_t sem) need_schedule = RT_TRUE; } else - sem->value ++; /* increase value */ + { + if(sem->value < 65535u) + { + sem->value ++; /* increase value */ + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + } /* enable interrupt */ rt_hw_interrupt_enable(temp); -- cgit v1.3.1 From b93b4942390dbcf0834f762145c7784d6b32075c Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 21 Oct 2020 17:15:43 +0800 Subject: [bug fixed] add mutex values' overflow-check code --- src/ipc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index dc347119ae..129d3eea44 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -37,7 +37,7 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add semaphore values' overflow-check code - * in the function of rt_sem_release + * 2020-10-21 Meco Man add mutex values' overflow-check code */ #include @@ -697,8 +697,16 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) if (mutex->owner == thread) { - /* it's the same thread */ - mutex->hold ++; + if(mutex->hold < 255u) + { + /* it's the same thread */ + mutex->hold ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } } else { -- cgit v1.3.1 From b43f7365a45d34829326d54d81f1efc69d848437 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Thu, 22 Oct 2020 07:13:49 +0800 Subject: [bug fixed] add mb mq value overflow-check code --- src/ipc.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 129d3eea44..9cd2b8846d 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -36,8 +36,7 @@ * 2019-09-16 tyx add send wait support for message queue * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending - * 2020-10-11 Meco Man add semaphore values' overflow-check code - * 2020-10-21 Meco Man add mutex values' overflow-check code + * 2020-10-11 Meco Man add value overflow-check code */ #include @@ -724,7 +723,15 @@ __again: /* set mutex owner and original priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - mutex->hold ++; + if(mutex->hold < 255u) + { + mutex->hold ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } } else { @@ -881,7 +888,15 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - mutex->hold ++; + if(mutex->hold < 255u) + { + mutex->hold ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } /* resume thread */ rt_ipc_list_resume(&(mutex->parent.suspend_thread)); @@ -890,9 +905,17 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } else { - /* increase value */ - mutex->value ++; - + if(mutex->value < 65535u) + { + /* increase value */ + mutex->value ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + /* clear owner */ mutex->owner = RT_NULL; mutex->original_priority = 0xff; @@ -1583,9 +1606,18 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, ++ mb->in_offset; if (mb->in_offset >= mb->size) mb->in_offset = 0; - /* increase message entry */ - mb->entry ++; - + + if(mb->entry < 65535u) + { + /* increase message entry */ + mb->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { @@ -2147,8 +2179,16 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, if (mq->msg_queue_head == RT_NULL) mq->msg_queue_head = msg; - /* increase message entry */ - mq->entry ++; + if(mq->entry < 65535u) + { + /* increase message entry */ + mq->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) @@ -2247,9 +2287,17 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) if (mq->msg_queue_tail == RT_NULL) mq->msg_queue_tail = msg; - /* increase message entry */ - mq->entry ++; - + if(mq->entry < 65535u) + { + /* increase message entry */ + mq->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { -- cgit v1.3.1 From 0776b36a4f17239740c0a4d0254330c0e5ff9824 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 22 Oct 2020 22:44:58 +0800 Subject: [Kernel] fix the delay_until issue --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 7a90e57f25..49e2022bf7 100644 --- a/src/thread.c +++ b/src/thread.c @@ -569,7 +569,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) if (rt_tick_get() - *tick < inc_tick) { - *tick = rt_tick_get() - *tick + inc_tick; + *tick = *tick + inc_tick - rt_tick_get(); /* suspend thread */ rt_thread_suspend(thread); -- cgit v1.3.1 From 98f0cfbf6e37a072ddf3aa2ae6a600c5dee964aa Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 23 Oct 2020 01:04:06 +0800 Subject: define maximum value of ipc type --- include/rtdef.h | 8 ++++++++ src/ipc.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/include/rtdef.h b/include/rtdef.h index 5543b80ab7..0690371c6d 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -33,6 +33,7 @@ * 2019-05-17 Bernard change version number to v4.0.2 * 2019-12-20 Bernard change version number to v4.0.3 * 2020-08-10 Meco Man add macro for struct rt_device_ops + * 2020-10-23 Meco Man define maximum value of ipc type */ #ifndef __RT_DEF_H__ @@ -102,6 +103,13 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */ #define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */ +/* maximum value of ipc type */ +#define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maxium number of semaphore .value */ +#define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maxium number of mutex .value */ +#define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maxium number of mutex .hold */ +#define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of mailbox .entry */ +#define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of message queue .entry */ + #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #define __CLANG_ARM #endif diff --git a/src/ipc.c b/src/ipc.c index 9cd2b8846d..454fcb5439 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -465,7 +465,7 @@ rt_err_t rt_sem_release(rt_sem_t sem) } else { - if(sem->value < 65535u) + if(sem->value < RT_SEM_VALUE_MAX) { sem->value ++; /* increase value */ } @@ -696,7 +696,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) if (mutex->owner == thread) { - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { /* it's the same thread */ mutex->hold ++; @@ -723,7 +723,7 @@ __again: /* set mutex owner and original priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -888,7 +888,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -905,7 +905,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } else { - if(mutex->value < 65535u) + if(mutex->value < RT_MUTEX_VALUE_MAX) { /* increase value */ mutex->value ++; @@ -1607,7 +1607,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, if (mb->in_offset >= mb->size) mb->in_offset = 0; - if(mb->entry < 65535u) + if(mb->entry < RT_MB_ENTRY_MAX) { /* increase message entry */ mb->entry ++; @@ -2179,7 +2179,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, if (mq->msg_queue_head == RT_NULL) mq->msg_queue_head = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; @@ -2287,7 +2287,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) if (mq->msg_queue_tail == RT_NULL) mq->msg_queue_tail = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; -- cgit v1.3.1 From 55c0a9f27900d19556d52110be6397f3ee15a6c3 Mon Sep 17 00:00:00 2001 From: tmmdh <921889738@qq.com> Date: Sun, 25 Oct 2020 11:54:06 +0800 Subject: fix the conflicting file. --- examples/kernel/SConscript | 1 + examples/kernel/mutex_priority.c | 425 +++++++++++++++++++++++++++++++++++++++ src/ipc.c | 43 ++++ 3 files changed, 469 insertions(+) mode change 100644 => 100755 examples/kernel/SConscript create mode 100755 examples/kernel/mutex_priority.c mode change 100644 => 100755 src/ipc.c (limited to 'src') diff --git a/examples/kernel/SConscript b/examples/kernel/SConscript old mode 100644 new mode 100755 index 4cffe1c38c..5f58f0fcc0 --- a/examples/kernel/SConscript +++ b/examples/kernel/SConscript @@ -19,6 +19,7 @@ semaphore_priority.c semaphore_buffer_worker.c semaphore_producer_consumer.c mutex_simple.c +mutex_priority.c event_simple.c mbox_simple.c mbox_send_wait.c diff --git a/examples/kernel/mutex_priority.c b/examples/kernel/mutex_priority.c new file mode 100755 index 0000000000..f647fc4039 --- /dev/null +++ b/examples/kernel/mutex_priority.c @@ -0,0 +1,425 @@ +/* + * 创建7个进程,tid20、tid21、tid22、tid23、tid24、tid25、tid26、tid27、tid28、tid29 + * 各任务优先级分别为20、21、22、23、24、25、26、27、28、29, + * 其中tid26最先获得锁,tid22不需要使用到互斥锁,其他所有进程均需要使用互斥锁, + * 通过各个进程的打印信息,观察各个进程获取到互斥锁后,优先级变化情况 + */ +#include +#include "tc_comm.h" + +static rt_thread_t tid20 = RT_NULL; +static rt_thread_t tid21 = RT_NULL; +static rt_thread_t tid22 = RT_NULL; +static rt_thread_t tid23 = RT_NULL; +static rt_thread_t tid24 = RT_NULL; +static rt_thread_t tid25 = RT_NULL; +static rt_thread_t tid26 = RT_NULL; +static rt_thread_t tid27 = RT_NULL; +static rt_thread_t tid28 = RT_NULL; +static rt_thread_t tid29 = RT_NULL; + +static rt_mutex_t mutex = RT_NULL; + +static void thread20_entry(void* parameter) +{ + rt_err_t result; + rt_tick_t tick; + + rt_kprintf("[%d] thread20 run!\n", rt_tick_get()); + rt_thread_delay(30); + rt_kprintf("[%d] thread20 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread20 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread20, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid20->init_priority, tid20->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread20 exit!\n", rt_tick_get()); +} + +static void thread21_entry(void* parameter) +{ + rt_err_t result; + rt_tick_t tick; + rt_kprintf("[%d] thread21 run!\n", rt_tick_get()); + rt_thread_delay(25); + rt_kprintf("[%d] thread21 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread21 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread21, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid21->init_priority, tid21->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread21 exit!\n", rt_tick_get()); + +} + +static void thread22_entry(void* parameter) +{ + rt_tick_t tick; + + rt_kprintf("[%d] thread22 run!\n", rt_tick_get()); + rt_thread_delay(20); + rt_kprintf("[%d] thread22 wake!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 100) + { + rt_kprintf("[%d] thread22 running..., init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid22->init_priority, tid22->current_priority); + rt_thread_delay(2); + } + rt_kprintf("[%d] thread22 exit!\n", rt_tick_get()); +} + +static void thread23_entry(void* parameter) +{ + rt_err_t result; + rt_tick_t tick; + rt_kprintf("[%d] thread23 run!\n", rt_tick_get()); + rt_thread_delay(15); + rt_kprintf("[%d] thread23 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread23 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread23, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid23->init_priority, tid23->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread23 exit!\n", rt_tick_get()); +} + +static void thread24_entry(void* parameter) +{ + rt_err_t result; + rt_tick_t tick; + + rt_kprintf("[%d] thread24 run!\n", rt_tick_get()); + rt_thread_delay(10); + rt_kprintf("[%d] thread24 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread24 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread24, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid24->init_priority, tid24->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread24 exit!\n", rt_tick_get()); +} + +static void thread25_entry(void* parameter) +{ + rt_err_t result; + rt_tick_t tick; + rt_kprintf("[%d] thread25 run!\n", rt_tick_get()); + rt_thread_delay(5); + rt_kprintf("[%d] thread25 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread25 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread25, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid25->init_priority, tid25->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread25 exit!\n", rt_tick_get()); +} + +static void thread26_entry(void* parameter) +{ + rt_tick_t tick; + rt_err_t result; + + rt_kprintf("[%d] thread26 run!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread26 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 50) + { + rt_kprintf("[%d] thread26, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid26->init_priority, tid26->current_priority); + rt_thread_delay(1); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread26 exit!\n", rt_tick_get()); +} + +static void thread27_entry(void* parameter) +{ + rt_tick_t tick; + rt_err_t result; + + rt_kprintf("[%d] thread27 run!\n", rt_tick_get()); + rt_thread_delay(35); + rt_kprintf("[%d] thread27 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread27 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread27, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid27->init_priority, tid27->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread27 exit!\n", rt_tick_get()); +} + +static void thread28_entry(void* parameter) +{ + rt_tick_t tick; + rt_err_t result; + + rt_kprintf("[%d] thread28 run!\n", rt_tick_get()); + rt_thread_delay(40); + rt_kprintf("[%d] thread28 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread28 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread28, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid28->init_priority, tid28->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread28 exit!\n", rt_tick_get()); +} + +static void thread29_entry(void* parameter) +{ + rt_tick_t tick; + rt_err_t result; + + rt_kprintf("[%d] thread29 run!\n", rt_tick_get()); + rt_thread_delay(45); + rt_kprintf("[%d] thread29 wake!\n", rt_tick_get()); + + result = rt_mutex_take(mutex, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + } + rt_kprintf("[%d] thread29 take!\n", rt_tick_get()); + + tick = rt_tick_get(); + while (rt_tick_get() - tick < 5) + { + rt_kprintf("[%d] thread29, init_priority=%d, current_priority=%d\n", + rt_tick_get(), tid29->init_priority, tid29->current_priority); + } + rt_mutex_release(mutex); + rt_kprintf("[%d] thread29 exit!\n", rt_tick_get()); +} + +static int mutex_simple_init() +{ + /* 创建互斥锁 */ + mutex = rt_mutex_create("mutex", RT_IPC_FLAG_FIFO); + if (mutex == RT_NULL) + { + tc_stat(TC_STAT_END | TC_STAT_FAILED); + return 0; + } + + tid29 = rt_thread_create("t29", + thread29_entry, RT_NULL, + THREAD_STACK_SIZE, 29, THREAD_TIMESLICE); + if (tid29 != RT_NULL) + rt_thread_startup(tid29); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid28 = rt_thread_create("t28", + thread28_entry, RT_NULL, + THREAD_STACK_SIZE, 28, THREAD_TIMESLICE); + if (tid28 != RT_NULL) + rt_thread_startup(tid28); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid27 = rt_thread_create("t27", + thread27_entry, RT_NULL, + THREAD_STACK_SIZE, 27, THREAD_TIMESLICE); + if (tid27 != RT_NULL) + rt_thread_startup(tid27); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid26 = rt_thread_create("t26", + thread26_entry, RT_NULL, + THREAD_STACK_SIZE, 26, THREAD_TIMESLICE); + if (tid26 != RT_NULL) + rt_thread_startup(tid26); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid25 = rt_thread_create("t25", + thread25_entry, RT_NULL, + THREAD_STACK_SIZE, 25, THREAD_TIMESLICE); + if (tid25 != RT_NULL) + rt_thread_startup(tid25); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid24 = rt_thread_create("t24", + thread24_entry, RT_NULL, + THREAD_STACK_SIZE, 24, THREAD_TIMESLICE); + if (tid24 != RT_NULL) + rt_thread_startup(tid24); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid23 = rt_thread_create("t23", + thread23_entry, RT_NULL, + THREAD_STACK_SIZE, 23, THREAD_TIMESLICE); + if (tid23 != RT_NULL) + rt_thread_startup(tid23); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid22 = rt_thread_create("t22", + thread22_entry, RT_NULL, + THREAD_STACK_SIZE, 22, THREAD_TIMESLICE); + if (tid22 != RT_NULL) + rt_thread_startup(tid22); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid21 = rt_thread_create("t21", + thread21_entry, RT_NULL, + THREAD_STACK_SIZE, 21, THREAD_TIMESLICE); + if (tid21 != RT_NULL) + rt_thread_startup(tid21); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + tid20 = rt_thread_create("t20", + thread20_entry, RT_NULL, + THREAD_STACK_SIZE, 20, THREAD_TIMESLICE); + if (tid20 != RT_NULL) + rt_thread_startup(tid20); + else + tc_stat(TC_STAT_END | TC_STAT_FAILED); + + return 0; +} + +#ifdef RT_USING_TC +static void _tc_cleanup() +{ + /* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */ + rt_enter_critical(); + + /* 删除线程 */ + if (tid20 != RT_NULL && tid20->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid20); + if (tid21 != RT_NULL && tid21->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid21); + if (tid22 != RT_NULL && tid22->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid22); + if (tid23 != RT_NULL && tid23->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid23); + if (tid24 != RT_NULL && tid24->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid24); + if (tid25 != RT_NULL && tid25->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid25); + if (tid26 != RT_NULL && tid26->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid26); + if (tid27 != RT_NULL && tid27->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid27); + if (tid28 != RT_NULL && tid28->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid28); + if (tid29 != RT_NULL && tid29->stat != RT_THREAD_CLOSE) + rt_thread_delete(tid29); + + if (mutex != RT_NULL) + { + rt_mutex_delete(mutex); + } + rt_kprintf("test_done!\n"); + + /* 调度器解锁 */ + rt_exit_critical(); + + /* 设置TestCase状态 */ + tc_done(TC_STAT_PASSED); +} + +int _tc_mutex_priority() +{ + /* 设置TestCase清理回调函数 */ + tc_cleanup(_tc_cleanup); + mutex_simple_init(); + + /* 返回TestCase运行的最长时间 */ + return 100; +} +/* 输出函数命令到finsh shell中 */ +FINSH_FUNCTION_EXPORT(_tc_mutex_priority, a priority rollover example of mutex); +#else +/* 用户应用入口 */ +int rt_application_init() +{ + mutex_simple_init(); + + return 0; +} +#endif diff --git a/src/ipc.c b/src/ipc.c old mode 100644 new mode 100755 index 454fcb5439..4c1d4a756a --- a/src/ipc.c +++ b/src/ipc.c @@ -37,6 +37,7 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add value overflow-check code + * 2020-10-25 hupu fix priority inversion bug of mutex */ #include @@ -190,6 +191,31 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) return RT_EOK; } +/** + * This function will get the highest priority from the specified + * list of threads + * + * @param list of the threads + * + * @return the highest priority + */ +rt_uint8_t rt_ipc_get_highest_priority(rt_list_t *list) +{ + struct rt_list_node *n; + struct rt_thread *sthread; + rt_uint8_t priority = RT_THREAD_PRIORITY_MAX - 1; + + for (n = list->next; n != list; n = n->next) + { + sthread = rt_list_entry(n, struct rt_thread, tlist); + + priority = priority < sthread->current_priority ? + priority : + sthread->current_priority; + } + return priority; +} + #ifdef RT_USING_SEMAPHORE /** * This function will initialize a semaphore and put it under control of @@ -828,6 +854,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) register rt_base_t temp; struct rt_thread *thread; rt_bool_t need_schedule; + rt_uint8_t max_priority_in_queue = RT_THREAD_PRIORITY_MAX - 1; /* parameter check */ RT_ASSERT(mutex != RT_NULL); @@ -888,6 +915,22 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; + + /* Priority adjustment occurs only when the following conditions + * are met simultaneously: + * 1.The type of mutex is RT_IPC_FLAG_FIFO; + * 2.The priority of the thread to be resumed is not equal to the + * highest priority in the queue; + */ + max_priority_in_queue = rt_ipc_get_highest_priority(&mutex->parent.suspend_thread); + if (mutex->parent.parent.flag == RT_IPC_FLAG_FIFO && + thread->current_priority != max_priority_in_queue) + { + rt_thread_control(thread, + RT_THREAD_CTRL_CHANGE_PRIORITY, + &(max_priority_in_queue)); + } + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; -- cgit v1.3.1 From ea89767f2ce50078f6dc161189c4a15720ccee7f Mon Sep 17 00:00:00 2001 From: thread-liu Date: Fri, 30 Oct 2020 10:32:44 +0800 Subject: [update] check whether it's a same console device. --- src/kservice.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 7caf43ce28..0a74f05268 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1116,7 +1116,7 @@ RTM_EXPORT(rt_console_get_device); * * @param name the name of new console device * - * @return the old console device handler + * @return the old console device handler on successful, or RT_NULL on failure. */ rt_device_t rt_console_set_device(const char *name) { @@ -1127,6 +1127,10 @@ rt_device_t rt_console_set_device(const char *name) /* find new console device */ new_device = rt_device_find(name); + + /* check whether it's a same device */ + if (new_device == old_device) return RT_NULL; + if (new_device != RT_NULL) { if (_console_device != RT_NULL) -- cgit v1.3.1 From b9a186952cc619bc24ac55d150bca1f52be9c3e2 Mon Sep 17 00:00:00 2001 From: minghao_wang Date: Mon, 16 Nov 2020 15:10:22 +0800 Subject: fix bug of rt_memheap_detach --- src/memheap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/memheap.c b/src/memheap.c index aef56e1a74..0ff6925696 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -126,8 +126,8 @@ rt_err_t rt_memheap_detach(struct rt_memheap *heap) RT_ASSERT(heap); RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); RT_ASSERT(rt_object_is_systemobject(&heap->parent)); - - rt_object_detach(&(heap->lock.parent.parent)); + + rt_sem_detach(&heap->lock); rt_object_detach(&(heap->parent)); /* Return a successful completion. */ -- cgit v1.3.1 From b082c91d8be95603a3ddfc18e63bd5f3d2c5a517 Mon Sep 17 00:00:00 2001 From: yangjie11 Date: Wed, 18 Nov 2020 20:36:42 +0800 Subject: [src] add a __RTTHREAD__ global macro definition --- src/SConscript | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/SConscript b/src/SConscript index 82c3b8aaf1..c03d997cd1 100644 --- a/src/SConscript +++ b/src/SConscript @@ -29,6 +29,8 @@ if GetDepend('RT_USING_DEVICE') == False: if GetDepend('RT_USING_SMP') == False: SrcRemove(src, ['cpu.c']) -group = DefineGroup('Kernel', src, depend = [''], CPPPATH = CPPPATH) +CPPDEFINES = ['__RTTHREAD__'] + +group = DefineGroup('Kernel', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') -- cgit v1.3.1 From 1784c8be31da4a6b0eb42f3b08ff0447a3c993e8 Mon Sep 17 00:00:00 2001 From: yangjie11 Date: Sat, 21 Nov 2020 14:53:30 +0800 Subject: [src][scheduler] remove RT_USING_FINSH in kernel, remove list_thread() --- src/scheduler.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src') diff --git a/src/scheduler.c b/src/scheduler.c index 2250c4a006..677be6cff7 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -90,12 +90,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) rt_ubase_t level; rt_kprintf("thread:%s stack overflow\n", thread->name); -#ifdef RT_USING_FINSH - { - extern long list_thread(void); - list_thread(); - } -#endif + level = rt_hw_interrupt_disable(); while (level); } -- cgit v1.3.1 From d79802b942e77389e1f885d9fe27a62434c652f9 Mon Sep 17 00:00:00 2001 From: yangjie11 Date: Sat, 21 Nov 2020 17:56:02 +0800 Subject: [src][SConscript] Provide user heap options --- src/Kconfig | 14 +++++++++++++- src/SConscript | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index 63a7a67887..803c827e51 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -270,6 +270,18 @@ menu "Memory Management" config RT_USING_MEMHEAP_AS_HEAP bool "Use all of memheap objects as heap" endif + + config RT_USING_USERHEAP + bool "Use user heap" + help + If this option is selected, please implement these functions: + rt_malloc(), rt_malloc_sethook() + rt_free(), rt_free_sethook() + rt_calloc(), rt_realloc() + rt_system_heap_init() + + And if FinSH is used at the same time, please implement list_mem() + endchoice if RT_USING_SMALL_MEM @@ -294,7 +306,7 @@ menu "Memory Management" default y if RT_USING_SMALL_MEM default y if RT_USING_SLAB default y if RT_USING_MEMHEAP_AS_HEAP - + default y if RT_USING_USERHEAP endmenu menu "Kernel Device Object" diff --git a/src/SConscript b/src/SConscript index c03d997cd1..806cdef2c5 100644 --- a/src/SConscript +++ b/src/SConscript @@ -23,6 +23,9 @@ if GetDepend('RT_USING_MEMHEAP') == False: if GetDepend('RT_USING_MEMHEAP_AS_HEAP'): SrcRemove(src, ['mem.c']) +if GetDepend('RT_USING_USERHEAP'): + SrcRemove(src, ['mem.c', 'slab.c', 'memheap.c']) + if GetDepend('RT_USING_DEVICE') == False: SrcRemove(src, ['device.c']) -- cgit v1.3.1 From a22decb71ba92fdd879914be50809c97f0defb07 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Mon, 23 Nov 2020 11:36:04 +0800 Subject: 【优化】在代码中移除 rt_system_object_init/rt_system_tick_init 的调用。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/CME_M7/applications/startup.c | 6 ------ bsp/avr32uc3b0/startup.c | 2 -- bsp/bf533/startup.c | 6 ------ bsp/efm32/startup.c | 6 ------ bsp/fh8620/platform/fh8620/iot_cam/startup.c | 6 ------ bsp/frdm-k64f/applications/startup.c | 6 ------ bsp/gkipc/armv6/rtos_lib.c | 5 ----- bsp/lm3s8962/applications/startup.c | 6 ------ bsp/lm3s9b9x/applications/startup.c | 6 ------ bsp/lm4f232/applications/startup.c | 6 ------ bsp/lpc2148/applications/startup.c | 6 ------ bsp/lpc2478/applications/startup.c | 6 ------ bsp/lpc5410x/applications/startup.c | 6 ------ bsp/lpc824/applications/startup.c | 6 ------ bsp/m16c62p/applications/startup.c | 8 +------- bsp/mb9bf500r/startup.c | 6 ------ bsp/microblaze/startup.c | 6 ------ bsp/mini4020/applications/startup.c | 6 ------ bsp/nios_ii/startup.c | 6 ------ bsp/nrf51822/applications/startup.c | 6 ------ bsp/nrf52832/applications/startup.c | 6 ------ bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c | 6 ------ bsp/pic32ethernet/startup.c | 6 ------ bsp/rm48x50/application/startup.c | 6 ------ bsp/sam7x/applications/startup.c | 6 ------ bsp/samd21/applications/startup.c | 6 ------ bsp/sep6200/application/startup.c | 6 ------ bsp/simulator/applications/startup.c | 6 ------ bsp/stm32f20x/applications/startup.c | 6 ------ bsp/taihu/applications/startup.c | 3 --- bsp/tms320f28379d/applications/startup.c | 6 ------ bsp/upd70f3454/applications/startup.c | 8 +------- bsp/wh44b0/startup.c | 6 ------ bsp/x86/applications/startup.c | 6 ------ documentation/doxygen/systeminit.h | 6 ------ include/rtthread.h | 2 -- src/clock.c | 11 ----------- src/object.c | 12 ------------ 38 files changed, 2 insertions(+), 229 deletions(-) (limited to 'src') diff --git a/bsp/CME_M7/applications/startup.c b/bsp/CME_M7/applications/startup.c index edff582d1f..44f439690b 100644 --- a/bsp/CME_M7/applications/startup.c +++ b/bsp/CME_M7/applications/startup.c @@ -47,12 +47,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/avr32uc3b0/startup.c b/bsp/avr32uc3b0/startup.c index 6f1a3d3ada..0411b5d1ce 100644 --- a/bsp/avr32uc3b0/startup.c +++ b/bsp/avr32uc3b0/startup.c @@ -30,8 +30,6 @@ int main(void) #endif rt_hw_board_init(); - rt_system_tick_init(); - rt_system_object_init(); rt_system_timer_init(); #ifdef RT_USING_HEAP diff --git a/bsp/bf533/startup.c b/bsp/bf533/startup.c index 8f1b83912a..7d90dd2493 100644 --- a/bsp/bf533/startup.c +++ b/bsp/bf533/startup.c @@ -35,12 +35,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/efm32/startup.c b/bsp/efm32/startup.c index f997c6aadd..9a70f1278a 100644 --- a/bsp/efm32/startup.c +++ b/bsp/efm32/startup.c @@ -102,12 +102,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/fh8620/platform/fh8620/iot_cam/startup.c b/bsp/fh8620/platform/fh8620/iot_cam/startup.c index 52c4775da5..6f5cd6defa 100644 --- a/bsp/fh8620/platform/fh8620/iot_cam/startup.c +++ b/bsp/fh8620/platform/fh8620/iot_cam/startup.c @@ -93,12 +93,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* initialize tick */ - rt_system_tick_init(); - - /* initialize kernel object */ - rt_system_object_init(); - /* initialize timer system */ rt_system_timer_init(); diff --git a/bsp/frdm-k64f/applications/startup.c b/bsp/frdm-k64f/applications/startup.c index 3627cb993b..d16aefddb2 100644 --- a/bsp/frdm-k64f/applications/startup.c +++ b/bsp/frdm-k64f/applications/startup.c @@ -65,12 +65,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/gkipc/armv6/rtos_lib.c b/bsp/gkipc/armv6/rtos_lib.c index 7d7aec5c51..c4b4285fbe 100644 --- a/bsp/gkipc/armv6/rtos_lib.c +++ b/bsp/gkipc/armv6/rtos_lib.c @@ -1095,14 +1095,9 @@ U32 RTOS_InitKernel(U32 Heap_size) /* show version */ //rt_show_version(); - /* initialize tick */ - //rt_system_tick_init(); RTOS_HwTickInit(); //rt_kprintf("set tick\n"); - /* initialize kernel object */ - rt_system_object_init(); - /* initialize timer system */ rt_system_timer_init(); diff --git a/bsp/lm3s8962/applications/startup.c b/bsp/lm3s8962/applications/startup.c index d598ee8fc7..e78cfa7eca 100644 --- a/bsp/lm3s8962/applications/startup.c +++ b/bsp/lm3s8962/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/lm3s9b9x/applications/startup.c b/bsp/lm3s9b9x/applications/startup.c index 2e8ad05d7b..4d374824e7 100644 --- a/bsp/lm3s9b9x/applications/startup.c +++ b/bsp/lm3s9b9x/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/lm4f232/applications/startup.c b/bsp/lm4f232/applications/startup.c index e1f3b6efd1..8d9eb54611 100644 --- a/bsp/lm4f232/applications/startup.c +++ b/bsp/lm4f232/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/lpc2148/applications/startup.c b/bsp/lpc2148/applications/startup.c index 5b699a8613..cc16a5c12b 100644 --- a/bsp/lpc2148/applications/startup.c +++ b/bsp/lpc2148/applications/startup.c @@ -52,12 +52,6 @@ void rtthread_startup(void) /* init board */ rt_hw_board_init(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - rt_show_version(); /* init timer system */ diff --git a/bsp/lpc2478/applications/startup.c b/bsp/lpc2478/applications/startup.c index 270312f7ae..0b961e4f94 100644 --- a/bsp/lpc2478/applications/startup.c +++ b/bsp/lpc2478/applications/startup.c @@ -38,12 +38,6 @@ void rtthread_startup(void) /* init board */ rt_hw_board_init(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - rt_show_version(); /* init timer system */ diff --git a/bsp/lpc5410x/applications/startup.c b/bsp/lpc5410x/applications/startup.c index 6589dc6b46..6f4ab94e82 100644 --- a/bsp/lpc5410x/applications/startup.c +++ b/bsp/lpc5410x/applications/startup.c @@ -27,12 +27,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* initialize tick */ - rt_system_tick_init(); - - /* initialize kernel object */ - rt_system_object_init(); - /* initialize timer system */ rt_system_timer_init(); diff --git a/bsp/lpc824/applications/startup.c b/bsp/lpc824/applications/startup.c index 5e95382ba0..e165242f86 100644 --- a/bsp/lpc824/applications/startup.c +++ b/bsp/lpc824/applications/startup.c @@ -52,12 +52,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/m16c62p/applications/startup.c b/bsp/m16c62p/applications/startup.c index 95b9484c1f..1802ecadee 100644 --- a/bsp/m16c62p/applications/startup.c +++ b/bsp/m16c62p/applications/startup.c @@ -48,13 +48,7 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - + /* init timer system */ rt_system_timer_init(); diff --git a/bsp/mb9bf500r/startup.c b/bsp/mb9bf500r/startup.c index dc65496ba6..bc96eb5dca 100644 --- a/bsp/mb9bf500r/startup.c +++ b/bsp/mb9bf500r/startup.c @@ -44,12 +44,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/microblaze/startup.c b/bsp/microblaze/startup.c index b9dc03e588..c900973bb7 100755 --- a/bsp/microblaze/startup.c +++ b/bsp/microblaze/startup.c @@ -55,12 +55,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/mini4020/applications/startup.c b/bsp/mini4020/applications/startup.c index 575bd6f306..ae84f8b461 100644 --- a/bsp/mini4020/applications/startup.c +++ b/bsp/mini4020/applications/startup.c @@ -49,12 +49,6 @@ void rtthread_startup() /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nios_ii/startup.c b/bsp/nios_ii/startup.c index 8f2512630d..e2bbaaa996 100644 --- a/bsp/nios_ii/startup.c +++ b/bsp/nios_ii/startup.c @@ -45,12 +45,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nrf51822/applications/startup.c b/bsp/nrf51822/applications/startup.c index 660105ee48..1e7729fc83 100644 --- a/bsp/nrf51822/applications/startup.c +++ b/bsp/nrf51822/applications/startup.c @@ -48,12 +48,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nrf52832/applications/startup.c b/bsp/nrf52832/applications/startup.c index a48524814c..78a5ef7f65 100644 --- a/bsp/nrf52832/applications/startup.c +++ b/bsp/nrf52832/applications/startup.c @@ -48,12 +48,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c b/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c index a48524814c..78a5ef7f65 100644 --- a/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c +++ b/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c @@ -48,12 +48,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/pic32ethernet/startup.c b/bsp/pic32ethernet/startup.c index b841da98f3..e139dfefca 100644 --- a/bsp/pic32ethernet/startup.c +++ b/bsp/pic32ethernet/startup.c @@ -35,12 +35,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/rm48x50/application/startup.c b/bsp/rm48x50/application/startup.c index 31c2f92fa9..40b69e2c95 100644 --- a/bsp/rm48x50/application/startup.c +++ b/bsp/rm48x50/application/startup.c @@ -81,12 +81,6 @@ void rtthread_startup(void) /* init board */ rt_hw_board_init(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - rt_show_version(); /* init timer system */ diff --git a/bsp/sam7x/applications/startup.c b/bsp/sam7x/applications/startup.c index ddf194b1d1..d167d9ebcb 100644 --- a/bsp/sam7x/applications/startup.c +++ b/bsp/sam7x/applications/startup.c @@ -82,12 +82,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/samd21/applications/startup.c b/bsp/samd21/applications/startup.c index aaa75d3f1c..ecbe617d2e 100644 --- a/bsp/samd21/applications/startup.c +++ b/bsp/samd21/applications/startup.c @@ -68,12 +68,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/sep6200/application/startup.c b/bsp/sep6200/application/startup.c index fc12985ce1..e714675699 100644 --- a/bsp/sep6200/application/startup.c +++ b/bsp/sep6200/application/startup.c @@ -63,12 +63,6 @@ void rtthread_startup() /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/simulator/applications/startup.c b/bsp/simulator/applications/startup.c index cc2144d64f..900d774844 100644 --- a/bsp/simulator/applications/startup.c +++ b/bsp/simulator/applications/startup.c @@ -47,12 +47,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/stm32f20x/applications/startup.c b/bsp/stm32f20x/applications/startup.c index 77f915cbbd..92be9bd2ce 100644 --- a/bsp/stm32f20x/applications/startup.c +++ b/bsp/stm32f20x/applications/startup.c @@ -61,12 +61,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/taihu/applications/startup.c b/bsp/taihu/applications/startup.c index f52a185495..9f7d9415b5 100644 --- a/bsp/taihu/applications/startup.c +++ b/bsp/taihu/applications/startup.c @@ -40,9 +40,6 @@ void rtthread_startup(void) rt_hw_board_init(); rt_show_version(); - /* init tick */ - rt_system_tick_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/tms320f28379d/applications/startup.c b/bsp/tms320f28379d/applications/startup.c index 301e63a00a..da5c31e237 100644 --- a/bsp/tms320f28379d/applications/startup.c +++ b/bsp/tms320f28379d/applications/startup.c @@ -50,12 +50,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/upd70f3454/applications/startup.c b/bsp/upd70f3454/applications/startup.c index d25ca73f28..409b3cc615 100644 --- a/bsp/upd70f3454/applications/startup.c +++ b/bsp/upd70f3454/applications/startup.c @@ -49,13 +49,7 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - + /* init timer system */ rt_system_timer_init(); diff --git a/bsp/wh44b0/startup.c b/bsp/wh44b0/startup.c index 4ea7a4f03d..5e62200a19 100644 --- a/bsp/wh44b0/startup.c +++ b/bsp/wh44b0/startup.c @@ -58,12 +58,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/x86/applications/startup.c b/bsp/x86/applications/startup.c index 72a4eb0a96..475273267f 100644 --- a/bsp/x86/applications/startup.c +++ b/bsp/x86/applications/startup.c @@ -69,12 +69,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/documentation/doxygen/systeminit.h b/documentation/doxygen/systeminit.h index d62aca59bb..c45eda4079 100644 --- a/documentation/doxygen/systeminit.h +++ b/documentation/doxygen/systeminit.h @@ -21,12 +21,6 @@ * - show version * rt_show_version(); * - * - initialize system tick - * rt_system_tick_init(); - * - * - initialize kernel object [deprecated] - * rt_system_object_init(); - * * - initialize timer system * rt_system_timer_init(); * diff --git a/include/rtthread.h b/include/rtthread.h index a76601a3bf..27cfea19e0 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -38,7 +38,6 @@ extern "C" { /* * kernel object interface */ -void rt_system_object_init(void); struct rt_object_information * rt_object_get_information(enum rt_object_class_type type); int rt_object_get_length(enum rt_object_class_type type); @@ -74,7 +73,6 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object)); /* * clock & timer interface */ -void rt_system_tick_init(void); rt_tick_t rt_tick_get(void); void rt_tick_set(rt_tick_t tick); void rt_tick_increase(void); diff --git a/src/clock.c b/src/clock.c index a91cd829b6..9fd276cf6f 100644 --- a/src/clock.c +++ b/src/clock.c @@ -24,17 +24,6 @@ static rt_tick_t rt_tick = 0; #endif -/** - * This function will initialize system tick and set it to zero. - * @ingroup SystemInit - * - * @deprecated since 1.1.0, this function does not need to be invoked - * in the system initialization. - */ -void rt_system_tick_init(void) -{ -} - /** * @addtogroup Clock */ diff --git a/src/object.c b/src/object.c index 6866d805ca..fbd3879f67 100644 --- a/src/object.c +++ b/src/object.c @@ -191,18 +191,6 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object)) /**@}*/ #endif -/** - * @ingroup SystemInit - * - * This function will initialize system object management. - * - * @deprecated since 0.3.0, this function does not need to be invoked - * in the system initialization. - */ -void rt_system_object_init(void) -{ -} - /** * @addtogroup KernelObject */ -- cgit v1.3.1 From 05f631aa3a4f398d9a326a6f61d3bd9309dd2d39 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 24 Nov 2020 04:17:50 +0800 Subject: [kernel] rt_object_delete函数优化重置object->type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit object->type = 0; 改为 object->type = RT_Object_Class_Null; 一个东西,但是提高源码可读性 --- src/object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/object.c b/src/object.c index 6866d805ca..dc3354f76d 100644 --- a/src/object.c +++ b/src/object.c @@ -485,7 +485,7 @@ void rt_object_delete(rt_object_t object) RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object)); /* reset object type */ - object->type = 0; + object->type = RT_Object_Class_Null; /* lock interrupt */ temp = rt_hw_interrupt_disable(); -- cgit v1.3.1 From 077ac68661dc199946aaa37918d9bcc2db8e831e Mon Sep 17 00:00:00 2001 From: yangjie11 Date: Wed, 25 Nov 2020 15:45:35 +0800 Subject: [src/SConscript]update --- src/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/SConscript b/src/SConscript index 806cdef2c5..c3a7775d75 100644 --- a/src/SConscript +++ b/src/SConscript @@ -24,7 +24,7 @@ if GetDepend('RT_USING_MEMHEAP') == False: SrcRemove(src, ['mem.c']) if GetDepend('RT_USING_USERHEAP'): - SrcRemove(src, ['mem.c', 'slab.c', 'memheap.c']) + SrcRemove(src, ['mem.c', 'slab.c']) if GetDepend('RT_USING_DEVICE') == False: SrcRemove(src, ['device.c']) -- cgit v1.3.1 From 7b28bc6edee6480559d5fc28c7addf2f0664426d Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Fri, 27 Nov 2020 10:33:36 +0800 Subject: Fixed an issue with rt_timer_start being broken and destroying the timer list --- src/timer.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 4b9003794c..4d021ab367 100644 --- a/src/timer.c +++ b/src/timer.c @@ -331,7 +331,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) _rt_timer_remove(timer); /* change status of timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - rt_hw_interrupt_enable(level); RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent))); @@ -342,9 +341,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); timer->timeout_tick = rt_tick_get() + timer->init_tick; - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - #ifdef RT_USING_TIMER_SOFT if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { -- cgit v1.3.1 From 014105025a5c73a2aa58cd703ad157d29d5c6aff Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Thu, 3 Dec 2020 09:43:09 +0800 Subject: [timer] Fix the bug that the linked list is still mounted when the single timer is not modified --- src/timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 4b9003794c..fc8053e90e 100644 --- a/src/timer.c +++ b/src/timer.c @@ -579,7 +579,7 @@ void rt_timer_check(void) { continue; } - + rt_list_remove(&(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && (t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) { @@ -667,7 +667,7 @@ void rt_soft_timer_check(void) { continue; } - + rt_list_remove(&(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && (t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) { -- cgit v1.3.1 From f91089b57809543afe0b40257002efbe41f8c089 Mon Sep 17 00:00:00 2001 From: tangweikang Date: Tue, 8 Dec 2020 10:48:22 +0800 Subject: [BSP][STM32] update void HAL_Delay(__IO uint32_t Delay) --- bsp/stm32/libraries/HAL_Drivers/drv_common.c | 24 ++++++++++++++++++------ src/scheduler.c | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index f150d81fef..bf7ed20e94 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -30,7 +30,7 @@ void rt_hw_systick_init(void) #if defined (SOC_SERIES_STM32H7) HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / RT_TICK_PER_SECOND); #elif defined (SOC_SERIES_STM32MP1) - HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND); + HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND); #else HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND); #endif @@ -71,7 +71,17 @@ void HAL_ResumeTick(void) void HAL_Delay(__IO uint32_t Delay) { - rt_thread_mdelay(Delay); + if (rt_thread_self()) + { + rt_thread_mdelay(Delay); + } + else + { + for (rt_uint32_t count = 0; count < Delay; count++) + { + rt_hw_us_delay(1000); + } + } } /* re-implement tick interface for STM32 HAL */ @@ -90,7 +100,7 @@ void _Error_Handler(char *s, int num) { /* USER CODE BEGIN Error_Handler */ /* User can add his own implementation to report the HAL error return state */ - while(1) + while (1) { } /* USER CODE END Error_Handler */ @@ -107,10 +117,12 @@ void rt_hw_us_delay(rt_uint32_t us) start = SysTick->VAL; reload = SysTick->LOAD; us_tick = SystemCoreClock / 1000000UL; - do { + do + { now = SysTick->VAL; - delta = start > now ? start - now : reload + start - now; - } while(delta < us_tick * us); + delta = start >= now ? start - now : reload + start - now; + } + while (delta < us_tick * us); } /** diff --git a/src/scheduler.c b/src/scheduler.c index 677be6cff7..06f305ea0b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -43,7 +43,7 @@ rt_uint8_t rt_thread_ready_table[32]; #ifndef RT_USING_SMP extern volatile rt_uint8_t rt_interrupt_nest; static rt_int16_t rt_scheduler_lock_nest; -struct rt_thread *rt_current_thread; +struct rt_thread *rt_current_thread = RT_NULL; rt_uint8_t rt_current_priority; #endif /*RT_USING_SMP*/ -- cgit v1.3.1 From b71a0eb1d433530046fba732d0a506de7a67a6ee Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 25 Dec 2020 15:06:55 +0800 Subject: add rt_memory_info() for memheap.c --- src/memheap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/memheap.c b/src/memheap.c index 0ff6925696..afa06fb9bf 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -712,6 +712,20 @@ void *rt_calloc(rt_size_t count, rt_size_t size) } RTM_EXPORT(rt_calloc); +void rt_memory_info(rt_uint32_t *total, + rt_uint32_t *used, + rt_uint32_t *max_used) +{ + if (total != RT_NULL) + *total = _heap.pool_size; + + if (used != RT_NULL) + *used = _heap.pool_size - _heap.available_size; + + if (max_used != RT_NULL) + *max_used = _heap.max_used_size; +} + #endif #endif -- cgit v1.3.1 From c2e15e003c60fd0aeb412dbc7c6deb1c1f55a0ef Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 29 Dec 2020 00:08:24 +0800 Subject: add function rt_hw_1ms_tick_get() --- bsp/stm32/libraries/HAL_Drivers/drv_common.c | 2 +- components/net/lwip-1.4.1/src/arch/sys_arch.c | 3 ++- components/net/lwip-2.0.2/src/arch/sys_arch.c | 3 ++- components/net/lwip-2.1.2/src/arch/sys_arch.c | 3 ++- include/rthw.h | 5 +++++ src/clock.c | 17 +++++++++++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index f150d81fef..c6fb516b0e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -58,7 +58,7 @@ void SysTick_Handler(void) uint32_t HAL_GetTick(void) { - return rt_tick_get() * 1000 / RT_TICK_PER_SECOND; + return rt_hw_1ms_tick_get(); } void HAL_SuspendTick(void) diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index 2392dde2fa..0919c29e01 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -32,6 +32,7 @@ */ #include +#include #include "lwip/sys.h" #include "lwip/opt.h" @@ -617,7 +618,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_tick_get() * (1000 / RT_TICK_PER_SECOND); + return rt_hw_1ms_tick_get(); } #ifdef RT_LWIP_PPP diff --git a/components/net/lwip-2.0.2/src/arch/sys_arch.c b/components/net/lwip-2.0.2/src/arch/sys_arch.c index 40c79011ec..1404628a60 100644 --- a/components/net/lwip-2.0.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.0.2/src/arch/sys_arch.c @@ -32,6 +32,7 @@ */ #include +#include #include "lwip/sys.h" #include "lwip/opt.h" @@ -627,7 +628,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_tick_get() * (1000 / RT_TICK_PER_SECOND); + return rt_hw_1ms_tick_get(); } diff --git a/components/net/lwip-2.1.2/src/arch/sys_arch.c b/components/net/lwip-2.1.2/src/arch/sys_arch.c index 0633501bb6..8905765440 100644 --- a/components/net/lwip-2.1.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.1.2/src/arch/sys_arch.c @@ -33,6 +33,7 @@ */ #include +#include #include "lwip/sys.h" #include "lwip/opt.h" @@ -641,7 +642,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_tick_get() * (1000 / RT_TICK_PER_SECOND); + return rt_hw_1ms_tick_get(); } #if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK diff --git a/include/rthw.h b/include/rthw.h index 89877faf90..c3960350b8 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -134,6 +134,11 @@ void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context)); */ void rt_hw_us_delay(rt_uint32_t us); +/* + * provides a tick value ALWAYS in millisecond + */ +rt_tick_t rt_hw_1ms_tick_get(void); + #ifdef RT_USING_SMP typedef union { unsigned long slock; diff --git a/src/clock.c b/src/clock.c index 9fd276cf6f..778126fb23 100644 --- a/src/clock.c +++ b/src/clock.c @@ -13,6 +13,7 @@ * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca * 2011-06-26 Bernard add rt_tick_set function. * 2018-11-22 Jesven add per cpu tick + * 2020-12-29 Meco Man add function rt_hw_1ms_tick_get() */ #include @@ -116,5 +117,21 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) } RTM_EXPORT(rt_tick_from_millisecond); +/** + * This function provides a tick value ALWAYS in millisecond + * + * @return 1ms-based tick + */ +RT_WEAK rt_tick_t rt_hw_1ms_tick_get(void) +{ +#if 1000 % RT_TICK_PER_SECOND == 0 + return rt_tick_get() * (1000U / RT_TICK_PER_SECOND); +#else + #warning "rt-thread cannot provide a correct 1ms-based tick any longer,\ + please redefine this function in another file by using a high-precision hard-timer." + return 0; +#endif +} + /**@}*/ -- cgit v1.3.1 From 3d5e79248d284dd277f4c93126fc0f1a4ca0969e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 29 Dec 2020 00:49:18 +0800 Subject: [kernel] 对IPC中减减进行摸排,防止出现减出一个很大的数 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 454fcb5439..4261f617b0 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1764,8 +1764,12 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) ++ mb->out_offset; if (mb->out_offset >= mb->size) mb->out_offset = 0; + /* decrease message entry */ - mb->entry --; + if(mb->entry > 0) + { + mb->entry --; + } /* resume suspended thread */ if (!rt_list_isempty(&(mb->suspend_sender_thread))) @@ -2439,7 +2443,10 @@ rt_err_t rt_mq_recv(rt_mq_t mq, mq->msg_queue_tail = RT_NULL; /* decrease message entry */ - mq->entry --; + if(mq->entry > 0) + { + mq->entry --; + } /* enable interrupt */ rt_hw_interrupt_enable(temp); -- cgit v1.3.1 From 63cd26b0d1a876cb8d87c3d60d5591d89dfbf297 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 30 Dec 2020 16:32:20 +0800 Subject: update --- bsp/stm32/libraries/HAL_Drivers/drv_common.c | 2 +- components/net/lwip-1.4.1/src/arch/sys_arch.c | 2 +- components/net/lwip-2.0.2/src/arch/sys_arch.c | 2 +- components/net/lwip-2.1.2/src/arch/sys_arch.c | 2 +- include/rthw.h | 5 ----- include/rtthread.h | 1 + src/clock.c | 10 +++++----- 7 files changed, 10 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index c6fb516b0e..d868d63dfc 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -58,7 +58,7 @@ void SysTick_Handler(void) uint32_t HAL_GetTick(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } void HAL_SuspendTick(void) diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index 0919c29e01..2f6dbb4143 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -618,7 +618,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } #ifdef RT_LWIP_PPP diff --git a/components/net/lwip-2.0.2/src/arch/sys_arch.c b/components/net/lwip-2.0.2/src/arch/sys_arch.c index 1404628a60..fbf02cad0a 100644 --- a/components/net/lwip-2.0.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.0.2/src/arch/sys_arch.c @@ -628,7 +628,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } diff --git a/components/net/lwip-2.1.2/src/arch/sys_arch.c b/components/net/lwip-2.1.2/src/arch/sys_arch.c index 8905765440..a0eeed1073 100644 --- a/components/net/lwip-2.1.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.1.2/src/arch/sys_arch.c @@ -642,7 +642,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } #if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK diff --git a/include/rthw.h b/include/rthw.h index c3960350b8..89877faf90 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -134,11 +134,6 @@ void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context)); */ void rt_hw_us_delay(rt_uint32_t us); -/* - * provides a tick value ALWAYS in millisecond - */ -rt_tick_t rt_hw_1ms_tick_get(void); - #ifdef RT_USING_SMP typedef union { unsigned long slock; diff --git a/include/rtthread.h b/include/rtthread.h index 27cfea19e0..1e0094e73b 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -77,6 +77,7 @@ rt_tick_t rt_tick_get(void); 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); void rt_system_timer_init(void); void rt_system_timer_thread_init(void); diff --git a/src/clock.c b/src/clock.c index 778126fb23..24456fb23d 100644 --- a/src/clock.c +++ b/src/clock.c @@ -118,14 +118,14 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) RTM_EXPORT(rt_tick_from_millisecond); /** - * This function provides a tick value ALWAYS in millisecond + * This function will provide the passed millisecond from boot. * - * @return 1ms-based tick + * @return passed millisecond from boot */ -RT_WEAK rt_tick_t rt_hw_1ms_tick_get(void) +RT_WEAK rt_tick_t rt_tick_get_millisecond(void) { -#if 1000 % RT_TICK_PER_SECOND == 0 - return rt_tick_get() * (1000U / RT_TICK_PER_SECOND); +#if 1000 % RT_TICK_PER_SECOND == 0u + return rt_tick_get() * (1000u / RT_TICK_PER_SECOND); #else #warning "rt-thread cannot provide a correct 1ms-based tick any longer,\ please redefine this function in another file by using a high-precision hard-timer." -- cgit v1.3.1 From a1f4d93fc57364a7b161c6f57a35a8f05df9a401 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 30 Dec 2020 16:33:30 +0800 Subject: update --- src/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 24456fb23d..66923e5c00 100644 --- a/src/clock.c +++ b/src/clock.c @@ -13,7 +13,7 @@ * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca * 2011-06-26 Bernard add rt_tick_set function. * 2018-11-22 Jesven add per cpu tick - * 2020-12-29 Meco Man add function rt_hw_1ms_tick_get() + * 2020-12-29 Meco Man add function rt_tick_get_millisecond() */ #include -- cgit v1.3.1 From b4e57db1a8c7bd99373c9859bdca252645b11e96 Mon Sep 17 00:00:00 2001 From: bernard Date: Thu, 31 Dec 2020 09:47:55 +0800 Subject: [kernel] Use object_find to implement thread_find/device_find --- src/device.c | 33 +-------------------------------- src/thread.c | 33 +-------------------------------- 2 files changed, 2 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/device.c b/src/device.c index 32c06b380c..a4f004fb69 100644 --- a/src/device.c +++ b/src/device.c @@ -111,38 +111,7 @@ rt_err_t rt_device_init_all(void) */ rt_device_t rt_device_find(const char *name) { - struct rt_object *object; - struct rt_list_node *node; - struct rt_object_information *information; - - /* enter critical */ - if (rt_thread_self() != RT_NULL) - rt_enter_critical(); - - /* try to find device object */ - information = rt_object_get_information(RT_Object_Class_Device); - RT_ASSERT(information != RT_NULL); - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = rt_list_entry(node, struct rt_object, list); - if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) - { - /* leave critical */ - if (rt_thread_self() != RT_NULL) - rt_exit_critical(); - - return (rt_device_t)object; - } - } - - /* leave critical */ - if (rt_thread_self() != RT_NULL) - rt_exit_critical(); - - /* not found */ - return RT_NULL; + return (rt_device_t)rt_object_find(name, RT_Object_Class_Device); } RTM_EXPORT(rt_device_find); diff --git a/src/thread.c b/src/thread.c index 49e2022bf7..ce03ae25e9 100644 --- a/src/thread.c +++ b/src/thread.c @@ -862,38 +862,7 @@ RTM_EXPORT(rt_thread_timeout); */ rt_thread_t rt_thread_find(char *name) { - struct rt_object_information *information; - struct rt_object *object; - struct rt_list_node *node; - - /* enter critical */ - if (rt_thread_self() != RT_NULL) - rt_enter_critical(); - - /* try to find device object */ - information = rt_object_get_information(RT_Object_Class_Thread); - RT_ASSERT(information != RT_NULL); - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = rt_list_entry(node, struct rt_object, list); - if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) - { - /* leave critical */ - if (rt_thread_self() != RT_NULL) - rt_exit_critical(); - - return (rt_thread_t)object; - } - } - - /* leave critical */ - if (rt_thread_self() != RT_NULL) - rt_exit_critical(); - - /* not found */ - return RT_NULL; + return (rt_thread_t)rt_object_find(name, RT_Object_Class_Thread); } RTM_EXPORT(rt_thread_find); -- cgit v1.3.1 From 5957e157545e48b30d8a3fef504024cb5482a76e Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Thu, 31 Dec 2020 10:31:06 +0800 Subject: cleanup操作改由当前线程退出前执行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/idle.c | 79 +++++++++++++----------------------------------------------- src/thread.c | 37 +++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/idle.c b/src/idle.c index 99db64f571..aa14552a49 100644 --- a/src/idle.c +++ b/src/idle.c @@ -150,82 +150,37 @@ void rt_thread_idle_excute(void) { /* Loop until there is no dead thread. So one call to rt_thread_idle_excute * will do all the cleanups. */ - while (_has_defunct_thread()) + /* disable interrupt */ + + RT_DEBUG_NOT_IN_INTERRUPT; + +#ifdef RT_USING_HEAP + while (1) { rt_base_t lock; rt_thread_t thread; -#ifdef RT_USING_MODULE - struct rt_dlmodule *module = RT_NULL; -#endif - RT_DEBUG_NOT_IN_INTERRUPT; - /* disable interrupt */ lock = rt_hw_interrupt_disable(); - /* re-check whether list is empty */ - if (_has_defunct_thread()) - { - /* get defunct thread */ - thread = rt_list_entry(rt_thread_defunct.next, - struct rt_thread, - tlist); -#ifdef RT_USING_MODULE - module = (struct rt_dlmodule*)thread->module_id; - if (module) - { - dlmodule_destroy(module); - } -#endif - /* remove defunct thread */ - rt_list_remove(&(thread->tlist)); - - /* lock scheduler to prevent scheduling in cleanup function. */ - rt_enter_critical(); - - /* invoke thread cleanup */ - if (thread->cleanup != RT_NULL) - thread->cleanup(thread); - -#ifdef RT_USING_SIGNALS - rt_thread_free_sig(thread); -#endif - - /* if it's a system object, not delete it */ - if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) - { - /* detach this object */ - rt_object_detach((rt_object_t)thread); - /* unlock scheduler */ - rt_exit_critical(); - - /* enable interrupt */ - rt_hw_interrupt_enable(lock); - - return; - } - - /* unlock scheduler */ - rt_exit_critical(); - } - else + /* check whether list is empty */ + if (!_has_defunct_thread()) { - /* enable interrupt */ rt_hw_interrupt_enable(lock); - - /* may the defunct thread list is removed by others, just return */ - return; + break; } - - /* enable interrupt */ - rt_hw_interrupt_enable(lock); - -#ifdef RT_USING_HEAP + /* get defunct thread */ + thread = rt_list_entry(rt_thread_defunct.next, + struct rt_thread, + tlist); + /* remove defunct thread */ + rt_list_remove(&(thread->tlist)); /* release thread's stack */ RT_KERNEL_FREE(thread->stack_addr); /* delete thread object */ rt_object_delete((rt_object_t)thread); -#endif + rt_hw_interrupt_enable(lock); } +#endif } extern void rt_system_power_manager(void); diff --git a/src/thread.c b/src/thread.c index 49e2022bf7..a4cd3e9dd1 100644 --- a/src/thread.c +++ b/src/thread.c @@ -77,6 +77,31 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread)) #endif +/* must be invoke witch rt_hw_interrupt_disable */ +static void _thread_cleanup_execute(rt_thread_t thread) +{ + register rt_base_t level; +#ifdef RT_USING_MODULE + struct rt_dlmodule *module = RT_NULL; +#endif + level = rt_hw_interrupt_disable(); +#ifdef RT_USING_MODULE + module = (struct rt_dlmodule*)thread->module_id; + if (module) + { + dlmodule_destroy(module); + } +#endif + /* invoke thread cleanup */ + if (thread->cleanup != RT_NULL) + thread->cleanup(thread); + +#ifdef RT_USING_SIGNALS + rt_thread_free_sig(thread); +#endif + rt_hw_interrupt_enable(level); +} + void rt_thread_exit(void) { struct rt_thread *thread; @@ -88,6 +113,8 @@ void rt_thread_exit(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); + _thread_cleanup_execute(thread); + /* remove from schedule */ rt_schedule_remove_thread(thread); /* change stat */ @@ -96,8 +123,7 @@ void rt_thread_exit(void) /* remove it from timer list */ rt_timer_detach(&thread->thread_timer); - if ((rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) && - thread->cleanup == RT_NULL) + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) { rt_object_detach((rt_object_t)thread); } @@ -347,14 +373,15 @@ rt_err_t rt_thread_detach(rt_thread_t thread) rt_schedule_remove_thread(thread); } + _thread_cleanup_execute(thread); + /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); /* change stat */ thread->stat = RT_THREAD_CLOSE; - if ((rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) && - thread->cleanup == RT_NULL) + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) { rt_object_detach((rt_object_t)thread); } @@ -449,6 +476,8 @@ rt_err_t rt_thread_delete(rt_thread_t thread) rt_schedule_remove_thread(thread); } + _thread_cleanup_execute(thread); + /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); -- cgit v1.3.1 From 89cf5886aa19b96b02ebeeeb8f7b07a25318cd7d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 3 Jan 2021 06:19:14 +0800 Subject: add rt_mb_urgent() and rt_mb_urgent_wait() --- src/ipc.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 4261f617b0..a3069b1f37 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -37,6 +37,7 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add value overflow-check code + * 2021-01-03 Meco Man add rt_mb_urgent() and rt_mb_urgent_wait() */ #include @@ -1654,6 +1655,169 @@ rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value) } RTM_EXPORT(rt_mb_send); +/** + * This function will send an urgent mail to mailbox object. If the mailbox is full, + * current thread will be suspended until timeout. + * + * @param mb the mailbox object + * @param value the mail + * @param timeout the waiting time + * + * @return the error code + */ +rt_err_t rt_mb_urgent_wait(rt_mailbox_t mb, + rt_ubase_t value, + rt_int32_t timeout) +{ + struct rt_thread *thread; + register rt_ubase_t temp; + rt_uint32_t tick_delta; + + /* parameter check */ + RT_ASSERT(mb != RT_NULL); + RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox); + + /* initialize delta tick */ + tick_delta = 0; + /* get current thread */ + thread = rt_thread_self(); + + RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mb->parent.parent))); + + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + + /* for non-blocking call */ + if (mb->entry == mb->size && timeout == 0) + { + rt_hw_interrupt_enable(temp); + + return -RT_EFULL; + } + + /* mailbox is full */ + while (mb->entry == mb->size) + { + /* reset error number in thread */ + thread->error = RT_EOK; + + /* no waiting, return timeout */ + if (timeout == 0) + { + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + return -RT_EFULL; + } + + RT_DEBUG_IN_THREAD_CONTEXT; + /* suspend current thread */ + rt_ipc_list_suspend(&(mb->suspend_sender_thread), + thread, + mb->parent.parent.flag); + + /* has waiting time, start thread timer */ + if (timeout > 0) + { + /* get the start tick of timer */ + tick_delta = rt_tick_get(); + + RT_DEBUG_LOG(RT_DEBUG_IPC, ("mb_send_wait: start timer of thread:%s\n", + thread->name)); + + /* reset the timeout of thread timer and start it */ + rt_timer_control(&(thread->thread_timer), + RT_TIMER_CTRL_SET_TIME, + &timeout); + rt_timer_start(&(thread->thread_timer)); + } + + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + /* re-schedule */ + rt_schedule(); + + /* resume from suspend state */ + if (thread->error != RT_EOK) + { + /* return error */ + return thread->error; + } + + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + + /* if it's not waiting forever and then re-calculate timeout tick */ + if (timeout > 0) + { + tick_delta = rt_tick_get() - tick_delta; + timeout -= tick_delta; + if (timeout < 0) + timeout = 0; + } + } + + /* rewind to the previous position */ + if(mb->out_offset > 0) + { + mb->out_offset --; + } + else + { + mb->out_offset = mb->size - 1; + } + + /* set ptr */ + mb->msg_pool[mb->out_offset] = value; + + if(mb->entry < RT_MB_ENTRY_MAX) + { + /* increase message entry */ + mb->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + + /* resume suspended thread */ + if (!rt_list_isempty(&mb->parent.suspend_thread)) + { + rt_ipc_list_resume(&(mb->parent.suspend_thread)); + + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + rt_schedule(); + + return RT_EOK; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + return RT_EOK; +} +RTM_EXPORT(rt_mb_urgent_wait); + +/** + * This function will send an urgent mail to mailbox object, if there are threads + * suspended on mailbox object, it will be waked up. This function will return + * immediately, if you want blocking send, use rt_mb_urgent_wait instead. + * + * @param mb the mailbox object + * @param value the mail + * + * @return the error code + */ +rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) +{ + return rt_mb_urgent_wait(mb, value, 0); +} +RTM_EXPORT(rt_mb_urgent); + /** * This function will receive a mail from mailbox object, if there is no mail * in mailbox object, the thread shall wait for a specified time. -- cgit v1.3.1 From d7d663562e767c07a97e2046d45ffca84caf63cd Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 3 Jan 2021 07:23:50 +0800 Subject: [kernel] update sconscript --- src/SConscript | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/SConscript b/src/SConscript index c3a7775d75..8dd44f5df2 100644 --- a/src/SConscript +++ b/src/SConscript @@ -26,6 +26,9 @@ if GetDepend('RT_USING_MEMHEAP') == False: if GetDepend('RT_USING_USERHEAP'): SrcRemove(src, ['mem.c', 'slab.c']) +if GetDepend('RT_USING_SIGNALS') == False: + SrcRemove(src, ['signal.c']) + if GetDepend('RT_USING_DEVICE') == False: SrcRemove(src, ['device.c']) -- cgit v1.3.1 From 661f54d1e0ea6d7b3c05d43d493f660f58570cb2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 3 Jan 2021 23:28:15 +0800 Subject: update --- src/ipc.c | 106 +++----------------------------------------------------------- 1 file changed, 5 insertions(+), 101 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index a3069b1f37..d1c4474f14 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -37,7 +37,7 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add value overflow-check code - * 2021-01-03 Meco Man add rt_mb_urgent() and rt_mb_urgent_wait() + * 2021-01-03 Meco Man add rt_mb_urgent() */ #include @@ -1656,108 +1656,28 @@ rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value) RTM_EXPORT(rt_mb_send); /** - * This function will send an urgent mail to mailbox object. If the mailbox is full, - * current thread will be suspended until timeout. + * This function will send an urgent mail to mailbox object, if there are threads + * suspended on mailbox object, it will be waked up. This function will return + * immediately, if you want blocking send, use rt_mb_urgent_wait instead. * * @param mb the mailbox object * @param value the mail - * @param timeout the waiting time * * @return the error code */ -rt_err_t rt_mb_urgent_wait(rt_mailbox_t mb, - rt_ubase_t value, - rt_int32_t timeout) +rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) { - struct rt_thread *thread; register rt_ubase_t temp; - rt_uint32_t tick_delta; /* parameter check */ RT_ASSERT(mb != RT_NULL); RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox); - /* initialize delta tick */ - tick_delta = 0; - /* get current thread */ - thread = rt_thread_self(); - RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mb->parent.parent))); /* disable interrupt */ temp = rt_hw_interrupt_disable(); - /* for non-blocking call */ - if (mb->entry == mb->size && timeout == 0) - { - rt_hw_interrupt_enable(temp); - - return -RT_EFULL; - } - - /* mailbox is full */ - while (mb->entry == mb->size) - { - /* reset error number in thread */ - thread->error = RT_EOK; - - /* no waiting, return timeout */ - if (timeout == 0) - { - /* enable interrupt */ - rt_hw_interrupt_enable(temp); - - return -RT_EFULL; - } - - RT_DEBUG_IN_THREAD_CONTEXT; - /* suspend current thread */ - rt_ipc_list_suspend(&(mb->suspend_sender_thread), - thread, - mb->parent.parent.flag); - - /* has waiting time, start thread timer */ - if (timeout > 0) - { - /* get the start tick of timer */ - tick_delta = rt_tick_get(); - - RT_DEBUG_LOG(RT_DEBUG_IPC, ("mb_send_wait: start timer of thread:%s\n", - thread->name)); - - /* reset the timeout of thread timer and start it */ - rt_timer_control(&(thread->thread_timer), - RT_TIMER_CTRL_SET_TIME, - &timeout); - rt_timer_start(&(thread->thread_timer)); - } - - /* enable interrupt */ - rt_hw_interrupt_enable(temp); - - /* re-schedule */ - rt_schedule(); - - /* resume from suspend state */ - if (thread->error != RT_EOK) - { - /* return error */ - return thread->error; - } - - /* disable interrupt */ - temp = rt_hw_interrupt_disable(); - - /* if it's not waiting forever and then re-calculate timeout tick */ - if (timeout > 0) - { - tick_delta = rt_tick_get() - tick_delta; - timeout -= tick_delta; - if (timeout < 0) - timeout = 0; - } - } - /* rewind to the previous position */ if(mb->out_offset > 0) { @@ -1800,22 +1720,6 @@ rt_err_t rt_mb_urgent_wait(rt_mailbox_t mb, return RT_EOK; } -RTM_EXPORT(rt_mb_urgent_wait); - -/** - * This function will send an urgent mail to mailbox object, if there are threads - * suspended on mailbox object, it will be waked up. This function will return - * immediately, if you want blocking send, use rt_mb_urgent_wait instead. - * - * @param mb the mailbox object - * @param value the mail - * - * @return the error code - */ -rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) -{ - return rt_mb_urgent_wait(mb, value, 0); -} RTM_EXPORT(rt_mb_urgent); /** -- cgit v1.3.1 From 234f1aec99a4283e29aff1b2212d23d47aec54a7 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 3 Jan 2021 23:41:07 +0800 Subject: update --- src/ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index d1c4474f14..d8b9327795 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1658,7 +1658,7 @@ RTM_EXPORT(rt_mb_send); /** * This function will send an urgent mail to mailbox object, if there are threads * suspended on mailbox object, it will be waked up. This function will return - * immediately, if you want blocking send, use rt_mb_urgent_wait instead. + * immediately. * * @param mb the mailbox object * @param value the mail -- cgit v1.3.1 From 342dac48bda1c61bf848c3fac41ba545ee2ec697 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 4 Jan 2021 00:29:53 +0800 Subject: [kernel] [script] remove module.c --- src/SConscript | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/SConscript b/src/SConscript index 8dd44f5df2..68523978d6 100644 --- a/src/SConscript +++ b/src/SConscript @@ -6,9 +6,6 @@ src = Glob('*.c') CPPPATH = [RTT_ROOT + '/include'] -if GetDepend('RT_USING_MODULE') == False: - SrcRemove(src, ['module.c']) - if GetDepend('RT_USING_HEAP') == False or GetDepend('RT_USING_SMALL_MEM') == False: SrcRemove(src, ['mem.c']) -- cgit v1.3.1 From 7a5edbaabd95e9b5c86b10e1dc6ed079ee6f2ef6 Mon Sep 17 00:00:00 2001 From: iysheng Date: Mon, 4 Jan 2021 14:22:58 +0800 Subject: [src/kservice.c] 更新打印提示時間信息 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kservice.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 0a74f05268..3415a606eb 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -541,7 +541,7 @@ void rt_show_version(void) rt_kprintf("- RT - Thread Operating System\n"); rt_kprintf(" / | \\ %d.%d.%d build %s\n", RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__); - rt_kprintf(" 2006 - 2020 Copyright by rt-thread team\n"); + rt_kprintf(" 2006 - 2021 Copyright by rt-thread team\n"); } RTM_EXPORT(rt_show_version); -- cgit v1.3.1 From cd6ca24f88eb167486189eae7d742293203d60e5 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 4 Jan 2021 22:34:50 +0800 Subject: update --- src/ipc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index d8b9327795..11b7e266f9 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1534,7 +1534,6 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, if (mb->entry == mb->size && timeout == 0) { rt_hw_interrupt_enable(temp); - return -RT_EFULL; } @@ -1678,8 +1677,14 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) /* disable interrupt */ temp = rt_hw_interrupt_disable(); + if (mb->entry == mb->size) + { + rt_hw_interrupt_enable(temp); + return -RT_EFULL; + } + /* rewind to the previous position */ - if(mb->out_offset > 0) + if (mb->out_offset > 0) { mb->out_offset --; } @@ -1691,7 +1696,7 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) /* set ptr */ mb->msg_pool[mb->out_offset] = value; - if(mb->entry < RT_MB_ENTRY_MAX) + if (mb->entry < RT_MB_ENTRY_MAX) { /* increase message entry */ mb->entry ++; -- cgit v1.3.1 From 3f9b3f57ea7f166f19b7d49d071c01874506814d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 5 Jan 2021 09:20:53 +0800 Subject: update --- src/ipc.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 11b7e266f9..be2baee9b5 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1696,16 +1696,8 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) /* set ptr */ mb->msg_pool[mb->out_offset] = value; - if (mb->entry < RT_MB_ENTRY_MAX) - { - /* increase message entry */ - mb->entry ++; - } - else - { - rt_hw_interrupt_enable(temp); /* enable interrupt */ - return -RT_EFULL; /* value overflowed */ - } + /* increase message entry */ + mb->entry ++; /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) -- cgit v1.3.1 From 949aa71ad4fa11a04afbb15d5158d83819bdb2e8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 22 Jan 2021 11:02:14 +0800 Subject: [kernel][kservice] add RT_WEAK for several functions --- src/kservice.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 3415a606eb..423fe3ddb3 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -123,7 +123,7 @@ RTM_EXPORT(_rt_errno); * * @return the address of source memory */ -void *rt_memset(void *s, int c, rt_ubase_t count) +RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) { #ifdef RT_USING_TINY_SIZE char *xs = (char *)s; @@ -207,7 +207,7 @@ RTM_EXPORT(rt_memset); * * @return the address of destination memory */ -void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) +RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) { #ifdef RT_USING_TINY_SIZE char *tmp = (char *)dst, *s = (char *)src; @@ -321,7 +321,7 @@ RTM_EXPORT(rt_memmove); * * @return the result */ -rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count) +RT_WEAK rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count) { const unsigned char *su1, *su2; int res = 0; @@ -1187,7 +1187,7 @@ void rt_kputs(const char *str) * * @param fmt the format */ -void rt_kprintf(const char *fmt, ...) +RT_WEAK void rt_kprintf(const char *fmt, ...) { va_list args; rt_size_t length; -- cgit v1.3.1 From b1cdc3a2cbce88d9cd015eeaa5cfed09e75a1858 Mon Sep 17 00:00:00 2001 From: tangweikang Date: Fri, 5 Feb 2021 18:27:41 +0800 Subject: [toolchain] Added support for the TASKING toolchain. --- include/libc/libc_ioctl.h | 2 +- include/rtdef.h | 12 ++++++++++++ src/components.c | 9 ++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h index 812a119507..516c56b1f4 100644 --- a/include/libc/libc_ioctl.h +++ b/include/libc/libc_ioctl.h @@ -16,7 +16,7 @@ #define _IOC_WRITE 1U #define _IOC_READ 2U -#ifndef _WIN32 +#if !defined (_WIN32) && !defined (__TASKING__) #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) #define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) #define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) diff --git a/include/rtdef.h b/include/rtdef.h index e4ddbd37d3..1226b43020 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -192,6 +192,18 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_WEAK #define rt_inline static inline #define RTT_API +#elif defined (__TASKING__) + + #include + #define SECTION(x) + #define RT_UNUSED + #define RT_USED + #define PRAGMA(x) _Pragma(#x) + #define ALIGN(n) + #define RT_WEAK + #define rt_inline static inline + #define RTT_API + #else #error not supported tool chain #endif diff --git a/src/components.c b/src/components.c index e7824b65ef..8ea5654d0c 100644 --- a/src/components.c +++ b/src/components.c @@ -173,19 +173,22 @@ struct rt_thread main_thread; void main_thread_entry(void *parameter) { extern int main(void); - extern int $Super$$main(void); #ifdef RT_USING_COMPONENTS_INIT /* RT-Thread components initialization */ rt_components_init(); #endif + #ifdef RT_USING_SMP rt_hw_secondary_cpu_up(); #endif /* invoke system main function */ #if defined(__CC_ARM) || defined(__CLANG_ARM) - $Super$$main(); /* for ARMCC. */ -#elif defined(__ICCARM__) || defined(__GNUC__) + { + extern int $Super$$main(void); + $Super$$main(); /* for ARMCC. */ + } +#elif defined(__ICCARM__) || defined(__GNUC__) || defined(__TASKING__) main(); #endif } -- cgit v1.3.1 From be864bcdd11e2b5e9708d95942193012cec21be9 Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 20 Feb 2021 20:44:46 +0800 Subject: [ipc] fix IAR Compilation error --- src/ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index d037708979..37b05b9ae3 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -2203,7 +2203,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, } /* message queue is full */ - while ((msg = mq->msg_queue_free) == RT_NULL) + while ((msg = (struct rt_mq_message *)mq->msg_queue_free) == RT_NULL) { /* reset error number in thread */ thread->error = RT_EOK; -- cgit v1.3.1 From 2b98ac215a4e07401464bfcd6ad00957ff03bd72 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 24 Feb 2021 16:29:43 +0800 Subject: [kernel] rearrange rt_thread_control() - schedule the thread when close it --- components/libc/compilers/common/stdlib.c | 10 +-- src/thread.c | 141 ++++++++++++++++-------------- 2 files changed, 77 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c index 9f801ab966..48a86098cd 100644 --- a/components/libc/compilers/common/stdlib.c +++ b/components/libc/compilers/common/stdlib.c @@ -14,18 +14,10 @@ void __rt_libc_exit(int status) { rt_thread_t self = rt_thread_self(); -#ifdef RT_USING_MODULE - if (dlmodule_self()) - { - dlmodule_exit(status); - } -#endif - if (self != RT_NULL) { rt_kprintf("thread:%s exit:%d!\n", self->name, status); - rt_thread_suspend(self); - rt_schedule(); + rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); } } diff --git a/src/thread.c b/src/thread.c index 0db9dd8e4d..2681eca59f 100644 --- a/src/thread.c +++ b/src/thread.c @@ -26,6 +26,7 @@ * bug when thread has not startup. * 2018-11-22 Jesven yield is same to rt_schedule * add support for tasks bound to cpu + * 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it */ #include @@ -670,83 +671,93 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) switch (cmd) { - case RT_THREAD_CTRL_CHANGE_PRIORITY: - /* disable interrupt */ - temp = rt_hw_interrupt_disable(); - - /* for ready thread, change queue */ - if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY) + case RT_THREAD_CTRL_CHANGE_PRIORITY: { - /* remove thread from schedule queue first */ - rt_schedule_remove_thread(thread); - - /* change thread priority */ - thread->current_priority = *(rt_uint8_t *)arg; - - /* recalculate priority attribute */ -#if RT_THREAD_PRIORITY_MAX > 32 - thread->number = thread->current_priority >> 3; /* 5bit */ - thread->number_mask = 1 << thread->number; - thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */ -#else - thread->number_mask = 1 << thread->current_priority; -#endif - - /* insert thread to schedule queue again */ - rt_schedule_insert_thread(thread); + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + + /* for ready thread, change queue */ + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY) + { + /* remove thread from schedule queue first */ + rt_schedule_remove_thread(thread); + + /* change thread priority */ + thread->current_priority = *(rt_uint8_t *)arg; + + /* recalculate priority attribute */ + #if RT_THREAD_PRIORITY_MAX > 32 + thread->number = thread->current_priority >> 3; /* 5bit */ + thread->number_mask = 1 << thread->number; + thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */ + #else + thread->number_mask = 1 << thread->current_priority; + #endif + + /* insert thread to schedule queue again */ + rt_schedule_insert_thread(thread); + } + else + { + thread->current_priority = *(rt_uint8_t *)arg; + + /* recalculate priority attribute */ + #if RT_THREAD_PRIORITY_MAX > 32 + thread->number = thread->current_priority >> 3; /* 5bit */ + thread->number_mask = 1 << thread->number; + thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */ + #else + thread->number_mask = 1 << thread->current_priority; + #endif + } + + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + break; } - else - { - thread->current_priority = *(rt_uint8_t *)arg; - /* recalculate priority attribute */ -#if RT_THREAD_PRIORITY_MAX > 32 - thread->number = thread->current_priority >> 3; /* 5bit */ - thread->number_mask = 1 << thread->number; - thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */ -#else - thread->number_mask = 1 << thread->current_priority; -#endif + case RT_THREAD_CTRL_STARTUP: + { + return rt_thread_startup(thread); } - /* enable interrupt */ - rt_hw_interrupt_enable(temp); - break; - - case RT_THREAD_CTRL_STARTUP: - return rt_thread_startup(thread); - - case RT_THREAD_CTRL_CLOSE: - - if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + case RT_THREAD_CTRL_CLOSE: { - return rt_thread_detach(thread); + rt_err_t rt_err; + + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + rt_err = rt_thread_detach(thread); + } + #ifdef RT_USING_HEAP + else + { + rt_err = rt_thread_delete(thread); + } + #endif + rt_schedule(); + return rt_err; } -#ifdef RT_USING_HEAP - else + + #ifdef RT_USING_SMP + case RT_THREAD_CTRL_BIND_CPU: { - return rt_thread_delete(thread); - } -#endif + rt_uint8_t cpu; -#ifdef RT_USING_SMP - case RT_THREAD_CTRL_BIND_CPU: - { - rt_uint8_t cpu; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) + { + /* we only support bind cpu before started phase. */ + return RT_ERROR; + } - if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) - { - /* we only support bind cpu before started phase. */ - return RT_ERROR; + cpu = (rt_uint8_t)(size_t)arg; + thread->bind_cpu = cpu > RT_CPUS_NR? RT_CPUS_NR : cpu; + break; } + #endif /*RT_USING_SMP*/ - cpu = (rt_uint8_t)(size_t)arg; - thread->bind_cpu = cpu > RT_CPUS_NR? RT_CPUS_NR : cpu; - break; - } -#endif /*RT_USING_SMP*/ - default: - break; + default: + break; } return RT_EOK; -- cgit v1.3.1