From 83b7b763b7b40f53f4fcb39483fc6e387d5d4632 Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 2 Nov 2018 10:14:08 +0800 Subject: The dbg_log API is DISCARDED. Change all dbg_log to LOG_X. --- src/signal.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/signal.c b/src/signal.c index c783420514..890f16f497 100644 --- a/src/signal.c +++ b/src/signal.c @@ -41,7 +41,7 @@ void rt_thread_handle_sig(rt_bool_t clean_state); static void _signal_default_handler(int signo) { - dbg_log(DBG_INFO, "handled signo[%d] with default action.\n", signo); + LOG_I("handled signo[%d] with default action.", signo); return ; } @@ -60,7 +60,7 @@ static void _signal_entry(void *parameter) tid->sp = tid->sig_ret; tid->sig_ret = RT_NULL; - dbg_log(DBG_LOG, "switch back to: 0x%08x\n", tid->sp); + LOG_D("switch back to: 0x%08x", tid->sp); tid->stat &= ~RT_THREAD_STAT_SIGNAL; rt_hw_context_switch_to((rt_uint32_t) & (tid->sp)); @@ -119,7 +119,7 @@ static void _signal_deliver(rt_thread_t tid) (void *)((char *)tid->sig_ret - 32), RT_NULL); rt_hw_interrupt_enable(level); - dbg_log(DBG_LOG, "signal stack pointer @ 0x%08x\n", tid->sp); + LOG_D("signal stack pointer @ 0x%08x", tid->sp); /* re-schedule */ rt_schedule(); @@ -268,7 +268,7 @@ __done: { *si = si_node->si; - dbg_log(DBG_LOG, "sigwait: %d sig raised!\n", signo); + LOG_D("sigwait: %d sig raised!", signo); if (si_prev) si_prev->list.next = si_node->list.next; else tid->si_list = si_node->list.next; @@ -320,7 +320,7 @@ void rt_thread_handle_sig(rt_bool_t clean_state) handler = tid->sig_vectors[signo]; rt_hw_interrupt_enable(level); - dbg_log(DBG_LOG, "handle signal: %d, handler 0x%08x\n", signo, handler); + LOG_D("handle signal: %d, handler 0x%08x", signo, handler); if (handler) handler(signo); level = rt_hw_interrupt_disable(); @@ -378,7 +378,7 @@ void rt_thread_free_sig(rt_thread_t tid) struct rt_slist_node *node; struct siginfo_node *si_node; - dbg_log(DBG_LOG, "free signal info list\n"); + LOG_D("free signal info list"); node = &(si_list->list); do { @@ -404,7 +404,7 @@ int rt_thread_kill(rt_thread_t tid, int sig) RT_ASSERT(tid != RT_NULL); if (!sig_valid(sig)) return -RT_EINVAL; - dbg_log(DBG_INFO, "send signal: %d\n", sig); + LOG_I("send signal: %d", sig); si.si_signo = sig; si.si_code = SI_USER; si.si_value.sival_ptr = RT_NULL; @@ -462,7 +462,7 @@ int rt_thread_kill(rt_thread_t tid, int sig) } else { - dbg_log(DBG_ERROR, "The allocation of signal info node failed.\n"); + LOG_E("The allocation of signal info node failed."); } /* deliver signal to this thread */ @@ -476,7 +476,7 @@ int rt_system_signal_init(void) _rt_siginfo_pool = rt_mp_create("signal", RT_SIG_INFO_MAX, sizeof(struct siginfo_node)); if (_rt_siginfo_pool == RT_NULL) { - dbg_log(DBG_ERROR, "create memory pool for signal info failed.\n"); + LOG_E("create memory pool for signal info failed."); RT_ASSERT(0); } -- cgit v1.3.1 From 1b8d7b3557f43d393b35810f6351cc95ba047b97 Mon Sep 17 00:00:00 2001 From: geniusgogo Date: Thu, 8 Nov 2018 22:25:47 +0800 Subject: fixed Kconfig IDLE hook config --- src/Kconfig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index d3889f4211..79205e0a5a 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -51,11 +51,16 @@ config RT_USING_OVERFLOW_CHECK config RT_USING_HOOK bool "Enable system hook" default y + select RT_USING_IDLE_HOOK help Enable the hook function when system running, such as idle thread hook, thread context switch etc. - if RT_USING_HOOK +config RT_USING_IDLE_HOOK + bool "Enable IDLE Task hook" + default y if RT_USING_HOOK + + if RT_USING_IDLE_HOOK config RT_IDEL_HOOK_LIST_SIZE int "The max size of idel hook list" default 4 -- cgit v1.3.1 From d1c177f48b6c53cc007c4a37954b42b50a813620 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 9 Nov 2018 09:17:43 +0800 Subject: [Kernel] Fix typo. --- src/components.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components.c b/src/components.c index 679a88ef11..68e5799f59 100644 --- a/src/components.c +++ b/src/components.c @@ -44,7 +44,7 @@ * * rti_end --> 6.end * - * These automatically initializaiton, the driver or component initial function must + * These automatically initialization, the driver or component initial function must * be defined with: * INIT_BOARD_EXPORT(fn); * INIT_DEVICE_EXPORT(fn); @@ -109,7 +109,7 @@ void rt_components_init(void) int result; const struct rt_init_desc *desc; - rt_kprintf("do components intialization.\n"); + rt_kprintf("do components initialization.\n"); for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc ++) { rt_kprintf("initialize %s", desc->fn_name); @@ -215,7 +215,7 @@ int rtthread_startup(void) { rt_hw_interrupt_disable(); - /* board level initalization + /* board level initialization * NOTE: please initialize heap inside board initialization. */ rt_hw_board_init(); -- cgit v1.3.1 From 379451c081a25358f8bbb598414b8afff8e189ca Mon Sep 17 00:00:00 2001 From: geniusgogo Date: Sat, 10 Nov 2018 10:45:36 +0800 Subject: code indent --- src/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index 79205e0a5a..78a3bf6d67 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -51,14 +51,14 @@ config RT_USING_OVERFLOW_CHECK config RT_USING_HOOK bool "Enable system hook" default y - select RT_USING_IDLE_HOOK + select RT_USING_IDLE_HOOK help Enable the hook function when system running, such as idle thread hook, thread context switch etc. config RT_USING_IDLE_HOOK - bool "Enable IDLE Task hook" - default y if RT_USING_HOOK + bool "Enable IDLE Task hook" + default y if RT_USING_HOOK if RT_USING_IDLE_HOOK config RT_IDEL_HOOK_LIST_SIZE -- cgit v1.3.1 From 00a655ac1c24d3707a5af376ec756e42406cd6bb Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Nov 2018 15:56:02 +0800 Subject: [Kernel] Add ARCH_CPU_STACK_GROWS_UPWARD option --- components/finsh/cmd.c | 16 ++++++++++++++-- libcpu/Kconfig | 4 ++++ src/scheduler.c | 10 +++++++++- src/thread.c | 6 ++++++ 4 files changed, 33 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index a97ef3caab..c66f72e650 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -101,16 +101,28 @@ static long _list_thread(struct rt_list_node *list) else if (stat == RT_THREAD_INIT) rt_kprintf(" init "); else if (stat == RT_THREAD_CLOSE) rt_kprintf(" close "); +#if defined(ARCH_CPU_STACK_GROWS_UPWARD) + ptr = (rt_uint8_t *)thread->stack_addr + thread->stack_size; + while (*ptr == '#')ptr --; + + rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", + ((rt_uint32_t)thread->sp - (rt_uint32_t)thread->stack_addr), + thread->stack_size, + ((rt_uint32_t)ptr - (rt_uint32_t)thread->stack_addr) * 100 / thread->stack_size, + thread->remaining_tick, + thread->error); +#else ptr = (rt_uint8_t *)thread->stack_addr; while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", - thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), + (thread->stack_size + (rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), thread->stack_size, - (thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t) thread->stack_addr)) * 100 + (thread->stack_size + (rt_uint32_t)thread->stack_addr - (rt_uint32_t) ptr) * 100 / thread->stack_size, thread->remaining_tick, thread->error); +#endif } return 0; diff --git a/libcpu/Kconfig b/libcpu/Kconfig index 0a280d4b5c..3c80428b5d 100644 --- a/libcpu/Kconfig +++ b/libcpu/Kconfig @@ -88,3 +88,7 @@ config ARCH_IA32 config ARCH_HOST_SIMULATOR bool + +config ARCH_CPU_STACK_GROWS_UPWARD + bool + default n diff --git a/src/scheduler.c b/src/scheduler.c index 95b5d487df..0b8b54ae92 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -91,11 +91,19 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) level = rt_hw_interrupt_disable(); while (level); } +#if defined(ARCH_CPU_STACK_GROWS_UPWARD) + else if ((rt_uint32_t)thread->sp > ((rt_uint32_t)thread->stack_addr + thread->stack_size)) + { + rt_kprintf("warning: %s stack is close to the top of stack address.\n", + thread->name); + } +#else else if ((rt_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32)) { - rt_kprintf("warning: %s stack is close to end of stack address.\n", + rt_kprintf("warning: %s stack is close to the bottom of stack address.\n", thread->name); } +#endif } #endif diff --git a/src/thread.c b/src/thread.c index 6d79ece54b..687852e92e 100644 --- a/src/thread.c +++ b/src/thread.c @@ -136,9 +136,15 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, /* init thread stack */ rt_memset(thread->stack_addr, '#', thread->stack_size); +#ifdef ARCH_CPU_STACK_GROWS_UPWARD + thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, + (void *)((char *)thread->stack_addr), + (void *)rt_thread_exit); +#else thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, (void *)((char *)thread->stack_addr + thread->stack_size - 4), (void *)rt_thread_exit); +#endif /* priority init */ RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX); -- cgit v1.3.1 From d343c6578a0c12c4bdc98e7634907fb9779ba0d7 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 13 Nov 2018 11:32:01 +0800 Subject: [kernel]Change 'rt_timer_timeout_hook' function to 'rt_timer_enter_hook' and add 'rt_timer_exit_hook' hook function. --- include/rtthread.h | 3 ++- src/timer.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/include/rtthread.h b/include/rtthread.h index fc5029a220..96ebe1940a 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -100,7 +100,8 @@ rt_tick_t rt_timer_next_timeout_tick(void); void rt_timer_check(void); #ifdef RT_USING_HOOK -void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer)); +void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)); +void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)); #endif /**@}*/ diff --git a/src/timer.c b/src/timer.c index dc489a2d0d..fd938065db 100644 --- a/src/timer.c +++ b/src/timer.c @@ -43,7 +43,8 @@ static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #ifdef RT_USING_HOOK extern void (*rt_object_take_hook)(struct rt_object *object); extern void (*rt_object_put_hook)(struct rt_object *object); -static void (*rt_timer_timeout_hook)(struct rt_timer *timer); +static void (*rt_timer_enter_hook)(struct rt_timer *timer); +static void (*rt_timer_exit_hook)(struct rt_timer *timer); /** * @addtogroup Hook @@ -52,14 +53,25 @@ static void (*rt_timer_timeout_hook)(struct rt_timer *timer); /**@{*/ /** - * This function will set a hook function, which will be invoked when timer - * is timeout. + * This function will set a hook function, which will be invoked when enter + * timer timeout callback function. * * @param hook the hook function */ -void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer)) +void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { - rt_timer_timeout_hook = hook; + rt_timer_enter_hook = hook; +} + +/** + * This function will set a hook function, which will be invoked when exit + * timer timeout callback function. + * + * @param hook the hook function + */ +void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) +{ + rt_timer_exit_hook = hook; } /**@}*/ @@ -503,7 +515,7 @@ void rt_timer_check(void) */ if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2) { - RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t)); + RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ _rt_timer_remove(t); @@ -514,6 +526,7 @@ void rt_timer_check(void) /* 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)); if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && @@ -578,7 +591,7 @@ void rt_soft_timer_check(void) */ if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2) { - RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t)); + RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* move node to the next */ n = n->next; @@ -594,6 +607,7 @@ void rt_soft_timer_check(void) /* 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)); /* lock scheduler */ -- cgit v1.3.1