Add reentrance check. Put kernel debug switch together.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1494 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
8c3d1e5eae
commit
864bd11802
|
@ -69,6 +69,8 @@ extern void finsh_system_init(void);
|
||||||
*/
|
*/
|
||||||
void rtthread_startup(void)
|
void rtthread_startup(void)
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_REENT_IN
|
||||||
|
|
||||||
/* enable cpu cache */
|
/* enable cpu cache */
|
||||||
rt_hw_cpu_icache_enable();
|
rt_hw_cpu_icache_enable();
|
||||||
rt_hw_cpu_dcache_enable();
|
rt_hw_cpu_dcache_enable();
|
||||||
|
@ -81,7 +83,7 @@ void rtthread_startup(void)
|
||||||
|
|
||||||
/* show version */
|
/* show version */
|
||||||
rt_show_version();
|
rt_show_version();
|
||||||
|
|
||||||
/* init tick */
|
/* init tick */
|
||||||
rt_system_tick_init();
|
rt_system_tick_init();
|
||||||
|
|
||||||
|
@ -116,11 +118,11 @@ void rtthread_startup(void)
|
||||||
rt_hw_serial_register(&uart2_device, "uart2",
|
rt_hw_serial_register(&uart2_device, "uart2",
|
||||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
||||||
&uart2);
|
&uart2);
|
||||||
|
|
||||||
#ifdef RT_USING_DFS
|
#ifdef RT_USING_DFS
|
||||||
rt_hw_sdcard_init();
|
rt_hw_sdcard_init();
|
||||||
#ifdef RT_USING_DFS_UFFS
|
#ifdef RT_USING_DFS_UFFS
|
||||||
rt_hw_nand_init();
|
rt_hw_nand_init();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -147,6 +149,8 @@ void rtthread_startup(void)
|
||||||
/* init idle thread */
|
/* init idle thread */
|
||||||
rt_thread_idle_init();
|
rt_thread_idle_init();
|
||||||
|
|
||||||
|
RT_DEBUG_REENT_OUT
|
||||||
|
|
||||||
/* start scheduler */
|
/* start scheduler */
|
||||||
rt_system_scheduler_start();
|
rt_system_scheduler_start();
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,8 @@ void led_flash()
|
||||||
*/
|
*/
|
||||||
void rtthread_startup(void)
|
void rtthread_startup(void)
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_REENT_IN
|
||||||
|
|
||||||
/* init hardware interrupt */
|
/* init hardware interrupt */
|
||||||
rt_hw_interrupt_init();
|
rt_hw_interrupt_init();
|
||||||
|
|
||||||
|
@ -133,6 +135,8 @@ void rtthread_startup(void)
|
||||||
/* init idle thread */
|
/* init idle thread */
|
||||||
rt_thread_idle_init();
|
rt_thread_idle_init();
|
||||||
|
|
||||||
|
RT_DEBUG_REENT_OUT
|
||||||
|
|
||||||
/* start scheduler */
|
/* start scheduler */
|
||||||
rt_system_scheduler_start();
|
rt_system_scheduler_start();
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ static void thread1_entry(void* parameter)
|
||||||
static void thread2_entry(void* parameter)
|
static void thread2_entry(void* parameter)
|
||||||
{
|
{
|
||||||
rt_uint8_t count;
|
rt_uint8_t count;
|
||||||
unsigned char *str;
|
char *str;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
while (1)
|
while (1)
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
#ifndef __RTDEBUG_H__
|
||||||
|
#define __RTDEBUG_H__
|
||||||
|
|
||||||
|
#include <rtconfig.h>
|
||||||
|
|
||||||
|
/* Using this macro to control all kernel debug features. */
|
||||||
|
#ifdef RT_DEBUG
|
||||||
|
|
||||||
|
/* Turn on some of these (set to non-zero) to debug kernel */
|
||||||
|
#define RT_DEBUG_MEM 0
|
||||||
|
#define RT_DEBUG_MODULE 0
|
||||||
|
#define RT_DEBUG_SCHEDULER 0
|
||||||
|
#define RT_DEBUG_SLAB 0
|
||||||
|
#define RT_DEBUG_THREAD 0
|
||||||
|
#define RT_DEBUG_TIMER 0
|
||||||
|
#define RT_DEBUG_IRQ 0
|
||||||
|
#define RT_DEBUG_IPC 0
|
||||||
|
|
||||||
|
/* Turn on this to enable reentrance check */
|
||||||
|
#define RT_DEBUG_REENT_CHK 1
|
||||||
|
|
||||||
|
#define RT_DEBUG_LOG(type,message) do{ if(type) rt_kprintf message;}while(0)
|
||||||
|
|
||||||
|
#define RT_ASSERT(EX) if (!(EX)) {volatile char dummy=0;\
|
||||||
|
rt_kprintf("(%s) assert failed at %s:%d \n", \
|
||||||
|
#EX, __FUNCTION__, __LINE__); while (dummy==0);}
|
||||||
|
|
||||||
|
/* Reentrance check */
|
||||||
|
/* counter */
|
||||||
|
extern rt_uint8_t rt_debug_reent_cnt;
|
||||||
|
|
||||||
|
#define RT_DEBUG_REENT_IN if(RT_DEBUG_REENT_CHK){\
|
||||||
|
rt_base_t level;\
|
||||||
|
level = rt_hw_interrupt_disable();\
|
||||||
|
rt_debug_reent_cnt++;\
|
||||||
|
rt_hw_interrupt_enable(level);}
|
||||||
|
|
||||||
|
#define RT_DEBUG_REENT_OUT if(RT_DEBUG_REENT_CHK){\
|
||||||
|
rt_base_t level;\
|
||||||
|
level = rt_hw_interrupt_disable();\
|
||||||
|
rt_debug_reent_cnt--;\
|
||||||
|
rt_hw_interrupt_enable(level);}
|
||||||
|
|
||||||
|
/* Mark those non-reentrant functions with this macro */
|
||||||
|
#define RT_DEBUG_NOT_REENT if(RT_DEBUG_REENT_CHK){\
|
||||||
|
rt_base_t level;\
|
||||||
|
level = rt_hw_interrupt_disable();\
|
||||||
|
if(rt_debug_reent_cnt != 0){\
|
||||||
|
rt_kprintf("Non-reentrant function used in critical area!\n");\
|
||||||
|
RT_ASSERT(0)}\
|
||||||
|
rt_hw_interrupt_enable(level);}
|
||||||
|
|
||||||
|
|
||||||
|
#else /* RT_DEBUG */
|
||||||
|
|
||||||
|
#define RT_ASSERT(EX)
|
||||||
|
#define RT_DEGUB_LOG(type,message)
|
||||||
|
#define RT_DEBUG_REENT_IN
|
||||||
|
#define RT_DEBUG_REENT_OUT
|
||||||
|
#define RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
|
#endif /* RT_DEBUG */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __RTDEBUG_H__ */
|
|
@ -149,12 +149,6 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
|
||||||
#define RT_EBUSY 7 /**< Busy */
|
#define RT_EBUSY 7 /**< Busy */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
#ifdef RT_DEBUG
|
|
||||||
#define RT_ASSERT(EX) if (!(EX)) {volatile char dummy=0; rt_kprintf("(%s) assert failed at %s:%d \n", \
|
|
||||||
#EX, __FUNCTION__, __LINE__); while (dummy==0);}
|
|
||||||
#else
|
|
||||||
#define RT_ASSERT(EX)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup BasicDef
|
* @ingroup BasicDef
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define __RT_THREAD_H__
|
#define __RT_THREAD_H__
|
||||||
|
|
||||||
#include <rtdef.h>
|
#include <rtdef.h>
|
||||||
|
#include <rtdebug.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -48,6 +49,24 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object* object));
|
||||||
void rt_object_trytake_sethook(void (*hook)(struct rt_object* object));
|
void rt_object_trytake_sethook(void (*hook)(struct rt_object* object));
|
||||||
void rt_object_take_sethook(void (*hook)(struct rt_object* object));
|
void rt_object_take_sethook(void (*hook)(struct rt_object* object));
|
||||||
void rt_object_put_sethook(void (*hook)(struct rt_object* object));
|
void rt_object_put_sethook(void (*hook)(struct rt_object* object));
|
||||||
|
#define RT_OBJECT_HOOK_CALL(hookfunc)\
|
||||||
|
do{\
|
||||||
|
register rt_base_t temp;\
|
||||||
|
temp = rt_hw_interrupt_disable();\
|
||||||
|
RT_DEBUG_REENT_IN\
|
||||||
|
if (hookfunc != RT_NULL) hookfunc();\
|
||||||
|
RT_DEBUG_REENT_OUT\
|
||||||
|
rt_hw_interrupt_enable(temp);\
|
||||||
|
}while(0)
|
||||||
|
#define RT_OBJECT_HOOK_CALL2(hookfunc,...)\
|
||||||
|
do{\
|
||||||
|
register rt_base_t temp;\
|
||||||
|
temp = rt_hw_interrupt_disable();\
|
||||||
|
RT_DEBUG_REENT_IN\
|
||||||
|
if (hookfunc != RT_NULL) hookfunc(__VA_ARGS__);\
|
||||||
|
RT_DEBUG_REENT_OUT\
|
||||||
|
rt_hw_interrupt_enable(temp);\
|
||||||
|
}while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* File : debug.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2011-06 11 mbbill first version
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rtdef.h>
|
||||||
|
#include <rtdebug.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup Kernel
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*@{*/
|
||||||
|
#ifdef RT_DEBUG
|
||||||
|
rt_uint8_t rt_debug_reent_cnt = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*@}*/
|
|
@ -60,6 +60,9 @@ void rt_thread_idle_sethook(void (*hook)())
|
||||||
*/
|
*/
|
||||||
void rt_thread_idle_excute(void)
|
void rt_thread_idle_excute(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* check the defunct thread list */
|
/* check the defunct thread list */
|
||||||
if (!rt_list_isempty(&rt_thread_defunct))
|
if (!rt_list_isempty(&rt_thread_defunct))
|
||||||
{
|
{
|
||||||
|
@ -147,8 +150,7 @@ static void rt_thread_idle_entry(void* parameter)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
/* if there is an idle thread hook */
|
RT_OBJECT_HOOK_CALL(rt_thread_idle_hook);
|
||||||
if (rt_thread_idle_hook != RT_NULL) rt_thread_idle_hook();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rt_thread_idle_excute();
|
rt_thread_idle_excute();
|
||||||
|
|
148
src/ipc.c
148
src/ipc.c
|
@ -135,9 +135,7 @@ rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list)
|
||||||
/* get thread entry */
|
/* get thread entry */
|
||||||
thread = rt_list_entry(list->next, struct rt_thread, tlist);
|
thread = rt_list_entry(list->next, struct rt_thread, tlist);
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,("resume thread:%s\n", thread->name));
|
||||||
rt_kprintf("resume thread:%s\n", thread->name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* resume it */
|
/* resume it */
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
|
@ -253,6 +251,8 @@ rt_sem_t rt_sem_create (const char* name, rt_uint32_t value, rt_uint8_t flag)
|
||||||
{
|
{
|
||||||
rt_sem_t sem;
|
rt_sem_t sem;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate object */
|
/* allocate object */
|
||||||
sem = (rt_sem_t) rt_object_allocate(RT_Object_Class_Semaphore, name);
|
sem = (rt_sem_t) rt_object_allocate(RT_Object_Class_Semaphore, name);
|
||||||
if (sem == RT_NULL) return sem;
|
if (sem == RT_NULL) return sem;
|
||||||
|
@ -280,6 +280,8 @@ rt_sem_t rt_sem_create (const char* name, rt_uint32_t value, rt_uint8_t flag)
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_sem_delete (rt_sem_t sem)
|
rt_err_t rt_sem_delete (rt_sem_t sem)
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
RT_ASSERT(sem != RT_NULL);
|
RT_ASSERT(sem != RT_NULL);
|
||||||
|
|
||||||
/* wakeup all suspend threads */
|
/* wakeup all suspend threads */
|
||||||
|
@ -309,16 +311,16 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
|
||||||
RT_ASSERT(sem != RT_NULL);
|
RT_ASSERT(sem != RT_NULL);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_trytake_hook != RT_NULL) rt_object_trytake_hook(&(sem->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(sem->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
temp = rt_hw_interrupt_disable();
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBU
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("thread %s take sem:%s, which value is: %d\n", rt_thread_self()->name,
|
("thread %s take sem:%s, which value is: %d\n", rt_thread_self()->name,
|
||||||
((struct rt_object*)sem)->name, sem->value);
|
((struct rt_object*)sem)->name, sem->value));
|
||||||
#endif
|
|
||||||
if (sem->value > 0)
|
if (sem->value > 0)
|
||||||
{
|
{
|
||||||
/* semaphore is available */
|
/* semaphore is available */
|
||||||
|
@ -337,6 +339,9 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* time = 0 is ok */
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* semaphore is unavailable, push to suspend list */
|
/* semaphore is unavailable, push to suspend list */
|
||||||
/* get current thread */
|
/* get current thread */
|
||||||
thread = rt_thread_self();
|
thread = rt_thread_self();
|
||||||
|
@ -344,9 +349,8 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
|
||||||
/* reset thread error number */
|
/* reset thread error number */
|
||||||
thread->error = RT_EOK;
|
thread->error = RT_EOK;
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("sem take: suspend thread - %s\n", thread->name);
|
("sem take: suspend thread - %s\n", thread->name));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* suspend thread */
|
/* suspend thread */
|
||||||
rt_ipc_list_suspend(&(sem->parent.suspend_thread),
|
rt_ipc_list_suspend(&(sem->parent.suspend_thread),
|
||||||
|
@ -355,9 +359,8 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
|
||||||
/* has waiting time, start thread timer */
|
/* has waiting time, start thread timer */
|
||||||
if (time > 0)
|
if (time > 0)
|
||||||
{
|
{
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,("set thread:%s to timer list\n", thread->name));
|
||||||
rt_kprintf("set thread:%s to timer list\n", thread->name);
|
|
||||||
#endif
|
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time);
|
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
|
@ -377,7 +380,7 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(sem->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(sem->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
@ -409,7 +412,7 @@ rt_err_t rt_sem_release(rt_sem_t sem)
|
||||||
register rt_bool_t need_schedule;
|
register rt_bool_t need_schedule;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(sem->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(sem->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
need_schedule = RT_FALSE;
|
need_schedule = RT_FALSE;
|
||||||
|
@ -417,10 +420,10 @@ rt_err_t rt_sem_release(rt_sem_t sem)
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
temp = rt_hw_interrupt_disable();
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("thread %s releases sem:%s, which value is: %d\n", rt_thread_self()->name,
|
("thread %s releases sem:%s, which value is: %d\n", rt_thread_self()->name,
|
||||||
((struct rt_object*)sem)->name, sem->value);
|
((struct rt_object*)sem)->name, sem->value));
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( !rt_list_isempty(&sem->parent.suspend_thread) )
|
if ( !rt_list_isempty(&sem->parent.suspend_thread) )
|
||||||
{
|
{
|
||||||
|
@ -549,6 +552,8 @@ rt_mutex_t rt_mutex_create (const char* name, rt_uint8_t flag)
|
||||||
{
|
{
|
||||||
struct rt_mutex *mutex;
|
struct rt_mutex *mutex;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate object */
|
/* allocate object */
|
||||||
mutex = (rt_mutex_t) rt_object_allocate(RT_Object_Class_Mutex, name);
|
mutex = (rt_mutex_t) rt_object_allocate(RT_Object_Class_Mutex, name);
|
||||||
if (mutex == RT_NULL) return mutex;
|
if (mutex == RT_NULL) return mutex;
|
||||||
|
@ -578,6 +583,8 @@ rt_mutex_t rt_mutex_create (const char* name, rt_uint8_t flag)
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_mutex_delete (rt_mutex_t mutex)
|
rt_err_t rt_mutex_delete (rt_mutex_t mutex)
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
RT_ASSERT(mutex != RT_NULL);
|
RT_ASSERT(mutex != RT_NULL);
|
||||||
|
|
||||||
/* wakeup all suspend threads */
|
/* wakeup all suspend threads */
|
||||||
|
@ -604,6 +611,9 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
|
||||||
register rt_base_t temp;
|
register rt_base_t temp;
|
||||||
struct rt_thread* thread;
|
struct rt_thread* thread;
|
||||||
|
|
||||||
|
/* this function must not be used in interrupt even if time = 0 */
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
RT_ASSERT(mutex != RT_NULL);
|
RT_ASSERT(mutex != RT_NULL);
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -613,13 +623,12 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
|
||||||
thread = rt_thread_self();
|
thread = rt_thread_self();
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_trytake_hook != RT_NULL) rt_object_trytake_hook(&(mutex->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(mutex->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mutex_take: current thread %s, mutex value: %d, hold: %d\n",
|
("mutex_take: current thread %s, mutex value: %d, hold: %d\n",
|
||||||
thread->name, mutex->value, mutex->hold);
|
thread->name, mutex->value, mutex->hold));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* reset thread error */
|
/* reset thread error */
|
||||||
thread->error = RT_EOK;
|
thread->error = RT_EOK;
|
||||||
|
@ -660,9 +669,9 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* mutex is unavailable, push to suspend list */
|
/* mutex is unavailable, push to suspend list */
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mutex_take: suspend thread: %s\n", thread->name);
|
("mutex_take: suspend thread: %s\n", thread->name));
|
||||||
#endif
|
|
||||||
/* change the owner thread priority of mutex */
|
/* change the owner thread priority of mutex */
|
||||||
if (thread->current_priority < mutex->owner->current_priority)
|
if (thread->current_priority < mutex->owner->current_priority)
|
||||||
{
|
{
|
||||||
|
@ -678,9 +687,9 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
|
||||||
/* has waiting time, start thread timer */
|
/* has waiting time, start thread timer */
|
||||||
if (time > 0)
|
if (time > 0)
|
||||||
{
|
{
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mutex_take: start the timer of thread:%s\n", thread->name);
|
("mutex_take: start the timer of thread:%s\n", thread->name));
|
||||||
#endif
|
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time);
|
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
|
@ -711,7 +720,7 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(mutex->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mutex->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
@ -739,13 +748,12 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
temp = rt_hw_interrupt_disable();
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mutex_release:current thread %s, mutex value: %d, hold: %d\n",
|
("mutex_release:current thread %s, mutex value: %d, hold: %d\n",
|
||||||
thread->name, mutex->value, mutex->hold);
|
thread->name, mutex->value, mutex->hold));
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(mutex->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mutex->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* mutex only can be released by owner */
|
/* mutex only can be released by owner */
|
||||||
|
@ -777,9 +785,9 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
|
||||||
/* get suspended thread */
|
/* get suspended thread */
|
||||||
thread = rt_list_entry(mutex->parent.suspend_thread.next, struct rt_thread, tlist);
|
thread = rt_list_entry(mutex->parent.suspend_thread.next, struct rt_thread, tlist);
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mutex_release: resume thread: %s\n", thread->name);
|
("mutex_release: resume thread: %s\n", thread->name));
|
||||||
#endif
|
|
||||||
/* set new owner and priority */
|
/* set new owner and priority */
|
||||||
mutex->owner = thread;
|
mutex->owner = thread;
|
||||||
mutex->original_priority = thread->current_priority;
|
mutex->original_priority = thread->current_priority;
|
||||||
|
@ -891,6 +899,8 @@ rt_event_t rt_event_create (const char* name, rt_uint8_t flag)
|
||||||
{
|
{
|
||||||
rt_event_t event;
|
rt_event_t event;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate object */
|
/* allocate object */
|
||||||
event = (rt_event_t) rt_object_allocate(RT_Object_Class_Event, name);
|
event = (rt_event_t) rt_object_allocate(RT_Object_Class_Event, name);
|
||||||
if (event == RT_NULL) return event;
|
if (event == RT_NULL) return event;
|
||||||
|
@ -919,6 +929,8 @@ rt_err_t rt_event_delete (rt_event_t event)
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(event != RT_NULL);
|
RT_ASSERT(event != RT_NULL);
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* resume all suspended thread */
|
/* resume all suspended thread */
|
||||||
rt_ipc_list_resume_all(&(event->parent.suspend_thread));
|
rt_ipc_list_resume_all(&(event->parent.suspend_thread));
|
||||||
|
|
||||||
|
@ -952,7 +964,7 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
|
||||||
|
|
||||||
need_schedule = RT_FALSE;
|
need_schedule = RT_FALSE;
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(event->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(event->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -1039,6 +1051,8 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
|
||||||
register rt_ubase_t level;
|
register rt_ubase_t level;
|
||||||
register rt_base_t status;
|
register rt_base_t status;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(event != RT_NULL);
|
RT_ASSERT(event != RT_NULL);
|
||||||
if (set == 0) return -RT_ERROR;
|
if (set == 0) return -RT_ERROR;
|
||||||
|
@ -1051,7 +1065,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
|
||||||
thread->error = RT_EOK;
|
thread->error = RT_EOK;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_trytake_hook != RT_NULL) rt_object_trytake_hook(&(event->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(event->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -1121,7 +1135,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(event->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(event->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return thread->error;
|
return thread->error;
|
||||||
|
@ -1240,6 +1254,8 @@ rt_mailbox_t rt_mb_create (const char* name, rt_size_t size, rt_uint8_t flag)
|
||||||
{
|
{
|
||||||
rt_mailbox_t mb;
|
rt_mailbox_t mb;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate object */
|
/* allocate object */
|
||||||
mb = (rt_mailbox_t) rt_object_allocate(RT_Object_Class_MailBox, name);
|
mb = (rt_mailbox_t) rt_object_allocate(RT_Object_Class_MailBox, name);
|
||||||
if (mb == RT_NULL) return mb;
|
if (mb == RT_NULL) return mb;
|
||||||
|
@ -1279,6 +1295,8 @@ rt_mailbox_t rt_mb_create (const char* name, rt_size_t size, rt_uint8_t flag)
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_mb_delete (rt_mailbox_t mb)
|
rt_err_t rt_mb_delete (rt_mailbox_t mb)
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(mb != RT_NULL);
|
RT_ASSERT(mb != RT_NULL);
|
||||||
|
|
||||||
|
@ -1325,7 +1343,7 @@ rt_err_t rt_mb_send_wait (rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout
|
||||||
RT_ASSERT(mb != RT_NULL);
|
RT_ASSERT(mb != RT_NULL);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(mb->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mb->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -1350,6 +1368,8 @@ rt_err_t rt_mb_send_wait (rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout
|
||||||
return -RT_EFULL;
|
return -RT_EFULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* suspend current thread */
|
/* suspend current thread */
|
||||||
rt_ipc_list_suspend(&(mb->suspend_sender_thread),
|
rt_ipc_list_suspend(&(mb->suspend_sender_thread),
|
||||||
thread, mb->parent.parent.flag);
|
thread, mb->parent.parent.flag);
|
||||||
|
@ -1360,9 +1380,9 @@ rt_err_t rt_mb_send_wait (rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout
|
||||||
/* get the start tick of timer */
|
/* get the start tick of timer */
|
||||||
tick_delta = rt_tick_get();
|
tick_delta = rt_tick_get();
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mb_send_wait: start timer of thread:%s\n", thread->name);
|
("mb_send_wait: start timer of thread:%s\n", thread->name));
|
||||||
#endif
|
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
|
@ -1456,7 +1476,7 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
|
||||||
|
|
||||||
tick_delta = 0;
|
tick_delta = 0;
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_trytake_hook != RT_NULL) rt_object_trytake_hook(&(mb->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(mb->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -1481,6 +1501,8 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
|
||||||
return -RT_ETIMEOUT;
|
return -RT_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* suspend current thread */
|
/* suspend current thread */
|
||||||
rt_ipc_list_suspend(&(mb->parent.suspend_thread),
|
rt_ipc_list_suspend(&(mb->parent.suspend_thread),
|
||||||
thread, mb->parent.parent.flag);
|
thread, mb->parent.parent.flag);
|
||||||
|
@ -1491,9 +1513,9 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
|
||||||
/* get the start tick of timer */
|
/* get the start tick of timer */
|
||||||
tick_delta = rt_tick_get();
|
tick_delta = rt_tick_get();
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("mb_recv: start timer of thread:%s\n", thread->name);
|
("mb_recv: start timer of thread:%s\n", thread->name));
|
||||||
#endif
|
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
|
@ -1542,7 +1564,7 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(mb->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mb->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
rt_schedule();
|
rt_schedule();
|
||||||
|
|
||||||
|
@ -1553,7 +1575,7 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(mb->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mb->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
@ -1702,6 +1724,8 @@ rt_mq_t rt_mq_create (const char* name, rt_size_t msg_size, rt_size_t max_msgs,
|
||||||
struct rt_mq_message* head;
|
struct rt_mq_message* head;
|
||||||
register rt_base_t temp;
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate object */
|
/* allocate object */
|
||||||
mq = (rt_mq_t) rt_object_allocate(RT_Object_Class_MessageQueue, name);
|
mq = (rt_mq_t) rt_object_allocate(RT_Object_Class_MessageQueue, name);
|
||||||
if (mq == RT_NULL) return mq;
|
if (mq == RT_NULL) return mq;
|
||||||
|
@ -1755,6 +1779,8 @@ rt_mq_t rt_mq_create (const char* name, rt_size_t msg_size, rt_size_t max_msgs,
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_mq_delete (rt_mq_t mq)
|
rt_err_t rt_mq_delete (rt_mq_t mq)
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(mq != RT_NULL);
|
RT_ASSERT(mq != RT_NULL);
|
||||||
|
|
||||||
|
@ -1797,7 +1823,7 @@ rt_err_t rt_mq_send (rt_mq_t mq, void* buffer, rt_size_t size)
|
||||||
if (size > mq->msg_size) return -RT_ERROR;
|
if (size > mq->msg_size) return -RT_ERROR;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(mq->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mq->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -1880,7 +1906,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void* buffer, rt_size_t size)
|
||||||
if (size > mq->msg_size) return -RT_ERROR;
|
if (size > mq->msg_size) return -RT_ERROR;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(mq->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mq->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -1955,7 +1981,7 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
|
||||||
rt_uint32_t tick_delta;
|
rt_uint32_t tick_delta;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_trytake_hook != RT_NULL) rt_object_trytake_hook(&(mq->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(mq->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tick_delta = 0;
|
tick_delta = 0;
|
||||||
|
@ -1981,6 +2007,8 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
|
||||||
return -RT_ETIMEOUT;
|
return -RT_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* suspend current thread */
|
/* suspend current thread */
|
||||||
rt_ipc_list_suspend(&(mq->parent.suspend_thread),
|
rt_ipc_list_suspend(&(mq->parent.suspend_thread),
|
||||||
thread, mq->parent.parent.flag);
|
thread, mq->parent.parent.flag);
|
||||||
|
@ -1991,9 +2019,9 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
|
||||||
/* get the start tick of timer */
|
/* get the start tick of timer */
|
||||||
tick_delta = rt_tick_get();
|
tick_delta = rt_tick_get();
|
||||||
|
|
||||||
#ifdef RT_IPC_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IPC,
|
||||||
rt_kprintf("set thread:%s to timer list\n", thread->name);
|
("set thread:%s to timer list\n", thread->name));
|
||||||
#endif
|
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
|
@ -2051,7 +2079,7 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(mq->parent.parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mq->parent.parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
|
12
src/irq.c
12
src/irq.c
|
@ -37,9 +37,9 @@ void rt_interrupt_enter()
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
|
|
||||||
#ifdef IRQ_DEBUG
|
RT_DEBUG_REENT_IN
|
||||||
rt_kprintf("irq comming..., irq nest:%d\n", rt_interrupt_nest);
|
|
||||||
#endif
|
RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq comming..., irq nest:%d\n", rt_interrupt_nest));
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
rt_interrupt_nest ++;
|
rt_interrupt_nest ++;
|
||||||
|
@ -57,13 +57,13 @@ void rt_interrupt_leave()
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
|
|
||||||
#ifdef IRQ_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq leave, irq nest:%d\n", rt_interrupt_nest));
|
||||||
rt_kprintf("irq leave, irq nest:%d\n", rt_interrupt_nest);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
rt_interrupt_nest --;
|
rt_interrupt_nest --;
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
|
RT_DEBUG_REENT_OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
|
@ -44,6 +44,8 @@ rt_err_t rt_get_errno(void)
|
||||||
{
|
{
|
||||||
rt_thread_t tid;
|
rt_thread_t tid;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
tid = rt_thread_self();
|
tid = rt_thread_self();
|
||||||
if (tid == RT_NULL) return errno;
|
if (tid == RT_NULL) return errno;
|
||||||
|
|
||||||
|
@ -59,6 +61,8 @@ void rt_set_errno(rt_err_t error)
|
||||||
{
|
{
|
||||||
rt_thread_t tid;
|
rt_thread_t tid;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
tid = rt_thread_self();
|
tid = rt_thread_self();
|
||||||
if (tid == RT_NULL) { errno = error; return; }
|
if (tid == RT_NULL) { errno = error; return; }
|
||||||
|
|
||||||
|
|
68
src/mem.c
68
src/mem.c
|
@ -72,7 +72,15 @@ static void (*rt_free_hook)(void *ptr);
|
||||||
*/
|
*/
|
||||||
void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
|
void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_malloc_hook = hook;
|
rt_malloc_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +91,15 @@ void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
|
||||||
*/
|
*/
|
||||||
void rt_free_sethook(void (*hook)(void *ptr))
|
void rt_free_sethook(void (*hook)(void *ptr))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_free_hook = hook;
|
rt_free_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
@ -124,6 +140,8 @@ static void plug_holes(struct heap_mem *mem)
|
||||||
struct heap_mem *nmem;
|
struct heap_mem *nmem;
|
||||||
struct heap_mem *pmem;
|
struct heap_mem *pmem;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
RT_ASSERT((rt_uint8_t *)mem >= heap_ptr);
|
RT_ASSERT((rt_uint8_t *)mem >= heap_ptr);
|
||||||
RT_ASSERT((rt_uint8_t *)mem < (rt_uint8_t *)heap_end);
|
RT_ASSERT((rt_uint8_t *)mem < (rt_uint8_t *)heap_end);
|
||||||
RT_ASSERT(mem->used == 0);
|
RT_ASSERT(mem->used == 0);
|
||||||
|
@ -170,6 +188,8 @@ void rt_system_heap_init(void* begin_addr, void* end_addr)
|
||||||
rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
|
rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
|
||||||
rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
|
rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* alignment addr */
|
/* alignment addr */
|
||||||
if((end_align > (2 * SIZEOF_STRUCT_MEM) ) &&
|
if((end_align > (2 * SIZEOF_STRUCT_MEM) ) &&
|
||||||
((end_align - 2 * SIZEOF_STRUCT_MEM) >= begin_align )) {
|
((end_align - 2 * SIZEOF_STRUCT_MEM) >= begin_align )) {
|
||||||
|
@ -184,9 +204,8 @@ void rt_system_heap_init(void* begin_addr, void* end_addr)
|
||||||
/* point to begin address of heap */
|
/* point to begin address of heap */
|
||||||
heap_ptr = (rt_uint8_t *)begin_align;
|
heap_ptr = (rt_uint8_t *)begin_align;
|
||||||
|
|
||||||
#ifdef RT_MEM_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
||||||
rt_kprintf("mem init, heap begin address 0x%x, size %d\n", (rt_uint32_t)heap_ptr, mem_size_aligned);
|
("mem init, heap begin address 0x%x, size %d\n", (rt_uint32_t)heap_ptr, mem_size_aligned));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* initialize the start of the heap */
|
/* initialize the start of the heap */
|
||||||
mem = (struct heap_mem *)heap_ptr;
|
mem = (struct heap_mem *)heap_ptr;
|
||||||
|
@ -226,9 +245,11 @@ void *rt_malloc(rt_size_t size)
|
||||||
rt_size_t ptr, ptr2;
|
rt_size_t ptr, ptr2;
|
||||||
struct heap_mem *mem, *mem2;
|
struct heap_mem *mem, *mem2;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
if (size == 0) return RT_NULL;
|
if (size == 0) return RT_NULL;
|
||||||
|
|
||||||
#ifdef RT_MEM_DEBUG
|
#if RT_DEBUG_MEM
|
||||||
if (size != RT_ALIGN(size, RT_ALIGN_SIZE))
|
if (size != RT_ALIGN(size, RT_ALIGN_SIZE))
|
||||||
rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE));
|
rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE));
|
||||||
else
|
else
|
||||||
|
@ -240,9 +261,8 @@ void *rt_malloc(rt_size_t size)
|
||||||
|
|
||||||
if (size > mem_size_aligned)
|
if (size > mem_size_aligned)
|
||||||
{
|
{
|
||||||
#ifdef RT_MEM_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_MEM,("no memory\n"));
|
||||||
rt_kprintf("no memory\n");
|
|
||||||
#endif
|
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,15 +347,12 @@ void *rt_malloc(rt_size_t size)
|
||||||
RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
||||||
RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE-1)) == 0);
|
RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE-1)) == 0);
|
||||||
|
|
||||||
#ifdef RT_MEM_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_MEM,("allocate memory at 0x%x, size: %d\n",
|
||||||
rt_kprintf("allocate memory at 0x%x, size: %d\n",
|
|
||||||
(rt_uint32_t)((rt_uint8_t*)mem + SIZEOF_STRUCT_MEM),
|
(rt_uint32_t)((rt_uint8_t*)mem + SIZEOF_STRUCT_MEM),
|
||||||
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr)));
|
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr))));
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_malloc_hook != RT_NULL)
|
RT_OBJECT_HOOK_CALL2(rt_malloc_hook,(rt_uint8_t *)mem + SIZEOF_STRUCT_MEM,size);
|
||||||
rt_malloc_hook((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM, size);
|
|
||||||
#endif
|
#endif
|
||||||
/* return the memory data except mem struct */
|
/* return the memory data except mem struct */
|
||||||
return (rt_uint8_t *)mem + SIZEOF_STRUCT_MEM;
|
return (rt_uint8_t *)mem + SIZEOF_STRUCT_MEM;
|
||||||
|
@ -361,13 +378,14 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
|
||||||
struct heap_mem *mem, *mem2;
|
struct heap_mem *mem, *mem2;
|
||||||
void* nmem;
|
void* nmem;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* alignment size */
|
/* alignment size */
|
||||||
newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE);
|
newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE);
|
||||||
if (newsize > mem_size_aligned)
|
if (newsize > mem_size_aligned)
|
||||||
{
|
{
|
||||||
#ifdef RT_MEM_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_MEM,("realloc: out of memory\n"));
|
||||||
rt_kprintf("realloc: out of memory\n");
|
|
||||||
#endif
|
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,6 +467,8 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate 'count' objects of size 'size' */
|
/* allocate 'count' objects of size 'size' */
|
||||||
p = rt_malloc(count * size);
|
p = rt_malloc(count * size);
|
||||||
|
|
||||||
|
@ -468,31 +488,31 @@ void rt_free(void *rmem)
|
||||||
{
|
{
|
||||||
struct heap_mem *mem;
|
struct heap_mem *mem;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
if (rmem == RT_NULL) return;
|
if (rmem == RT_NULL) return;
|
||||||
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
|
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
|
||||||
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
|
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
|
||||||
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
|
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_free_hook != RT_NULL) rt_free_hook(rmem);
|
RT_OBJECT_HOOK_CALL2(rt_free_hook,rmem);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr || (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
|
if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr || (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
|
||||||
{
|
{
|
||||||
#ifdef RT_MEM_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_MEM,("illegal memory\n"));
|
||||||
rt_kprintf("illegal memory\n");
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the corresponding struct heap_mem ... */
|
/* Get the corresponding struct heap_mem ... */
|
||||||
mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);
|
mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);
|
||||||
|
|
||||||
#ifdef RT_MEM_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_MEM,("release memory 0x%x, size: %d\n",
|
||||||
rt_kprintf("release memory 0x%x, size: %d\n",
|
|
||||||
(rt_uint32_t)rmem,
|
(rt_uint32_t)rmem,
|
||||||
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr)));
|
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr))));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* protect the heap from concurrent access */
|
/* protect the heap from concurrent access */
|
||||||
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
||||||
|
|
|
@ -182,6 +182,8 @@ rt_mp_t rt_mp_create(const char* name, rt_size_t block_count, rt_size_t block_si
|
||||||
struct rt_mempool* mp;
|
struct rt_mempool* mp;
|
||||||
register rt_base_t offset;
|
register rt_base_t offset;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* allocate object */
|
/* allocate object */
|
||||||
mp = (struct rt_mempool*)rt_object_allocate(RT_Object_Class_MemPool, name);
|
mp = (struct rt_mempool*)rt_object_allocate(RT_Object_Class_MemPool, name);
|
||||||
if (mp == RT_NULL) return RT_NULL; /* allocate object failed */
|
if (mp == RT_NULL) return RT_NULL; /* allocate object failed */
|
||||||
|
@ -235,6 +237,8 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
|
||||||
struct rt_thread* thread;
|
struct rt_thread* thread;
|
||||||
register rt_ubase_t temp;
|
register rt_ubase_t temp;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(mp != RT_NULL);
|
RT_ASSERT(mp != RT_NULL);
|
||||||
|
|
||||||
|
@ -321,6 +325,8 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* get current thread */
|
/* get current thread */
|
||||||
thread = rt_thread_self();
|
thread = rt_thread_self();
|
||||||
|
|
||||||
|
@ -363,7 +369,7 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_mp_alloc_hook != RT_NULL) rt_mp_alloc_hook(mp, (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*)));
|
RT_OBJECT_HOOK_CALL2(rt_mp_alloc_hook,mp, (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*));
|
return (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*));
|
||||||
|
@ -387,7 +393,7 @@ void rt_mp_free (void *block)
|
||||||
mp = (struct rt_mempool*) *block_ptr;
|
mp = (struct rt_mempool*) *block_ptr;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_mp_free_hook != RT_NULL) rt_mp_free_hook(mp, block);
|
RT_OBJECT_HOOK_CALL2(rt_mp_free_hook,mp, block);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
|
63
src/module.c
63
src/module.c
|
@ -14,13 +14,13 @@
|
||||||
* 2010-10-23 yi.qiu implement module memory allocator
|
* 2010-10-23 yi.qiu implement module memory allocator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <rthw.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtm.h>
|
#include <rtm.h>
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "kservice.h"
|
#include "kservice.h"
|
||||||
|
|
||||||
/* #define RT_MODULE_DEBUG */
|
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
|
@ -137,9 +137,10 @@ static int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf3
|
||||||
|
|
||||||
case R_ARM_ABS32:
|
case R_ARM_ABS32:
|
||||||
*where += (Elf32_Addr)sym_val;
|
*where += (Elf32_Addr)sym_val;
|
||||||
#ifdef RT_MODULE_DEBUG
|
|
||||||
rt_kprintf("R_ARM_ABS32: %x -> %x\n", where, *where);
|
RT_DEBUG_LOG(RT_DEBUG_MODULE,
|
||||||
#endif
|
("R_ARM_ABS32: %x -> %x\n", where, *where));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_ARM_PC24:
|
case R_ARM_PC24:
|
||||||
|
@ -152,9 +153,9 @@ static int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf3
|
||||||
tmp = sym_val - (Elf32_Addr)where + (addend << 2);
|
tmp = sym_val - (Elf32_Addr)where + (addend << 2);
|
||||||
tmp >>= 2;
|
tmp >>= 2;
|
||||||
*where = (*where & 0xff000000) | (tmp & 0x00ffffff);
|
*where = (*where & 0xff000000) | (tmp & 0x00ffffff);
|
||||||
#ifdef RT_MODULE_DEBUG
|
|
||||||
rt_kprintf("R_ARM_PC24: %x -> %x\n", where, *where);
|
RT_DEBUG_LOG(RT_DEBUG_MODULE,("R_ARM_PC24: %x -> %x\n", where, *where));
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_ARM_V4BX:
|
case R_ARM_V4BX:
|
||||||
|
@ -164,15 +165,17 @@ static int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf3
|
||||||
case R_ARM_GLOB_DAT:
|
case R_ARM_GLOB_DAT:
|
||||||
case R_ARM_JUMP_SLOT:
|
case R_ARM_JUMP_SLOT:
|
||||||
*where = (Elf32_Addr)sym_val;
|
*where = (Elf32_Addr)sym_val;
|
||||||
#ifdef RT_MODULE_DEBUG
|
|
||||||
rt_kprintf("R_ARM_JUMP_SLOT: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val);
|
RT_DEBUG_LOG(RT_DEBUG_MODULE,
|
||||||
#endif
|
("R_ARM_JUMP_SLOT: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case R_ARM_RELATIVE:
|
case R_ARM_RELATIVE:
|
||||||
*where += (Elf32_Addr)sym_val;
|
*where += (Elf32_Addr)sym_val;
|
||||||
#ifdef RT_MODULE_DEBUG
|
|
||||||
rt_kprintf("R_ARM_RELATIVE: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val);
|
RT_DEBUG_LOG(RT_DEBUG_MODULE,
|
||||||
#endif
|
("R_ARM_RELATIVE: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -261,6 +264,8 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
|
||||||
rt_bool_t linked = RT_FALSE;
|
rt_bool_t linked = RT_FALSE;
|
||||||
rt_uint32_t index, module_size = 0;
|
rt_uint32_t index, module_size = 0;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
rt_kprintf("rt_module_load: %s ,", name);
|
rt_kprintf("rt_module_load: %s ,", name);
|
||||||
|
|
||||||
/* check ELF header */
|
/* check ELF header */
|
||||||
|
@ -348,17 +353,19 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
|
||||||
for (i = 0; i < nr_reloc; i ++)
|
for (i = 0; i < nr_reloc; i ++)
|
||||||
{
|
{
|
||||||
Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
|
Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
|
||||||
#ifdef RT_MODULE_DEBUG
|
|
||||||
rt_kprintf("relocate symbol %s shndx %d\n", strtab + sym->st_name, sym->st_shndx);
|
RT_DEBUG_LOG(RT_DEBUG_MODULE,
|
||||||
#endif
|
("relocate symbol %s shndx %d\n", strtab + sym->st_name, sym->st_shndx));
|
||||||
|
|
||||||
if((sym->st_shndx != SHT_NULL) || (ELF_ST_BIND(sym->st_info) == STB_LOCAL))
|
if((sym->st_shndx != SHT_NULL) || (ELF_ST_BIND(sym->st_info) == STB_LOCAL))
|
||||||
rt_module_arm_relocate(module, rel, (Elf32_Addr)(module->module_space + sym->st_value));
|
rt_module_arm_relocate(module, rel, (Elf32_Addr)(module->module_space + sym->st_value));
|
||||||
else if(!linked)
|
else if(!linked)
|
||||||
{
|
{
|
||||||
Elf32_Addr addr;
|
Elf32_Addr addr;
|
||||||
#ifdef RT_MODULE_DEBUG
|
|
||||||
rt_kprintf("unresolved relocate symbol: %s\n", strtab + sym->st_name);
|
RT_DEBUG_LOG(RT_DEBUG_MODULE,
|
||||||
#endif
|
("unresolved relocate symbol: %s\n", strtab + sym->st_name));
|
||||||
|
|
||||||
/* need to resolve symbol in kernel symbol table */
|
/* need to resolve symbol in kernel symbol table */
|
||||||
addr = rt_module_symbol_find((const char*)(strtab + sym->st_name));
|
addr = rt_module_symbol_find((const char*)(strtab + sym->st_name));
|
||||||
if (addr == 0)
|
if (addr == 0)
|
||||||
|
@ -477,6 +484,8 @@ rt_module_t rt_module_open(const char* filename)
|
||||||
struct stat s;
|
struct stat s;
|
||||||
char *buffer, *offset_ptr;;
|
char *buffer, *offset_ptr;;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* check parameters */
|
/* check parameters */
|
||||||
RT_ASSERT(filename != RT_NULL);
|
RT_ASSERT(filename != RT_NULL);
|
||||||
|
|
||||||
|
@ -546,6 +555,8 @@ rt_err_t rt_module_unload(rt_module_t module)
|
||||||
struct rt_object* object;
|
struct rt_object* object;
|
||||||
struct rt_list_node *list;
|
struct rt_list_node *list;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
rt_kprintf("rt_module_unload: %s\n", module->parent.name);
|
rt_kprintf("rt_module_unload: %s\n", module->parent.name);
|
||||||
|
|
||||||
/* check parameter */
|
/* check parameter */
|
||||||
|
@ -763,6 +774,8 @@ rt_module_t rt_module_find(const char* name)
|
||||||
|
|
||||||
extern struct rt_object_information rt_object_container[];
|
extern struct rt_object_information rt_object_container[];
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* enter critical */
|
/* enter critical */
|
||||||
rt_enter_critical();
|
rt_enter_critical();
|
||||||
|
|
||||||
|
@ -794,6 +807,8 @@ static struct rt_mem_head *morepage(rt_size_t nu)
|
||||||
struct rt_mem_head *up;
|
struct rt_mem_head *up;
|
||||||
struct rt_module_page *node;
|
struct rt_module_page *node;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
RT_ASSERT (nu != 0);
|
RT_ASSERT (nu != 0);
|
||||||
|
|
||||||
/* allocate pages from system heap */
|
/* allocate pages from system heap */
|
||||||
|
@ -824,7 +839,9 @@ void *rt_module_malloc(rt_size_t size)
|
||||||
struct rt_mem_head *b, *n;
|
struct rt_mem_head *b, *n;
|
||||||
struct rt_mem_head **prev;
|
struct rt_mem_head **prev;
|
||||||
rt_size_t nunits;
|
rt_size_t nunits;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
nunits = (size + sizeof(struct rt_mem_head) -1)/sizeof(struct rt_mem_head) + 1;
|
nunits = (size + sizeof(struct rt_mem_head) -1)/sizeof(struct rt_mem_head) + 1;
|
||||||
|
|
||||||
RT_ASSERT(size != 0);
|
RT_ASSERT(size != 0);
|
||||||
|
@ -892,7 +909,9 @@ void rt_module_free(rt_module_t module, void *addr)
|
||||||
{
|
{
|
||||||
struct rt_mem_head *b, *n;
|
struct rt_mem_head *b, *n;
|
||||||
struct rt_mem_head **prev;
|
struct rt_mem_head **prev;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
RT_ASSERT(addr);
|
RT_ASSERT(addr);
|
||||||
RT_ASSERT((((rt_uint32_t)addr) & (sizeof(struct rt_mem_head) -1)) == 0);
|
RT_ASSERT((((rt_uint32_t)addr) & (sizeof(struct rt_mem_head) -1)) == 0);
|
||||||
|
|
||||||
|
@ -942,6 +961,8 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
|
||||||
struct rt_mem_head *b, *p, *prev, *tmpp;
|
struct rt_mem_head *b, *p, *prev, *tmpp;
|
||||||
rt_size_t nunits;
|
rt_size_t nunits;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
if (!ptr) return rt_module_malloc(size);
|
if (!ptr) return rt_module_malloc(size);
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
|
|
53
src/object.c
53
src/object.c
|
@ -84,7 +84,15 @@ void (*rt_object_put_hook)(struct rt_object* object);
|
||||||
*/
|
*/
|
||||||
void rt_object_attach_sethook(void (*hook)(struct rt_object* object))
|
void rt_object_attach_sethook(void (*hook)(struct rt_object* object))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_object_attach_hook = hook;
|
rt_object_attach_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,7 +103,15 @@ void rt_object_attach_sethook(void (*hook)(struct rt_object* object))
|
||||||
*/
|
*/
|
||||||
void rt_object_detach_sethook(void (*hook)(struct rt_object* object))
|
void rt_object_detach_sethook(void (*hook)(struct rt_object* object))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_object_detach_hook = hook;
|
rt_object_detach_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,7 +129,15 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object* object))
|
||||||
*/
|
*/
|
||||||
void rt_object_trytake_sethook(void (*hook)(struct rt_object* object))
|
void rt_object_trytake_sethook(void (*hook)(struct rt_object* object))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_object_trytake_hook = hook;
|
rt_object_trytake_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,7 +156,15 @@ void rt_object_trytake_sethook(void (*hook)(struct rt_object* object))
|
||||||
*/
|
*/
|
||||||
void rt_object_take_sethook(void (*hook)(struct rt_object* object))
|
void rt_object_take_sethook(void (*hook)(struct rt_object* object))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_object_take_hook = hook;
|
rt_object_take_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,7 +175,15 @@ void rt_object_take_sethook(void (*hook)(struct rt_object* object))
|
||||||
*/
|
*/
|
||||||
void rt_object_put_sethook(void (*hook)(struct rt_object* object))
|
void rt_object_put_sethook(void (*hook)(struct rt_object* object))
|
||||||
{
|
{
|
||||||
|
register rt_base_t temp;
|
||||||
|
|
||||||
|
/* disable interrupt */
|
||||||
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_object_put_hook = hook;
|
rt_object_put_hook = hook;
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
@ -199,10 +239,7 @@ void rt_object_init(struct rt_object* object, enum rt_object_class_type type, co
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_attach_hook != RT_NULL)
|
RT_OBJECT_HOOK_CALL2(rt_object_attach_hook,object);
|
||||||
{
|
|
||||||
rt_object_attach_hook(object);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lock interrupt */
|
/* lock interrupt */
|
||||||
|
@ -229,7 +266,7 @@ void rt_object_detach(rt_object_t object)
|
||||||
RT_ASSERT(object != RT_NULL);
|
RT_ASSERT(object != RT_NULL);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_detach_hook != RT_NULL) rt_object_detach_hook(object);
|
RT_OBJECT_HOOK_CALL2(rt_object_detach_hook,object);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lock interrupt */
|
/* lock interrupt */
|
||||||
|
@ -257,6 +294,8 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
|
||||||
register rt_base_t temp;
|
register rt_base_t temp;
|
||||||
struct rt_object_information* information;
|
struct rt_object_information* information;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
/* get module object information, module object should be managed by kernel object container */
|
/* get module object information, module object should be managed by kernel object container */
|
||||||
information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ?
|
information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ?
|
||||||
|
@ -296,7 +335,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_attach_hook != RT_NULL) rt_object_attach_hook(object);
|
RT_OBJECT_HOOK_CALL2(rt_object_attach_hook,object);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lock interrupt */
|
/* lock interrupt */
|
||||||
|
@ -326,7 +365,7 @@ void rt_object_delete(rt_object_t object)
|
||||||
RT_ASSERT(!(object->type & RT_Object_Class_Static));
|
RT_ASSERT(!(object->type & RT_Object_Class_Static));
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_detach_hook != RT_NULL) rt_object_detach_hook(object);
|
RT_OBJECT_HOOK_CALL2(rt_object_detach_hook,object);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lock interrupt */
|
/* lock interrupt */
|
||||||
|
|
|
@ -31,8 +31,6 @@
|
||||||
|
|
||||||
#include "kservice.h"
|
#include "kservice.h"
|
||||||
|
|
||||||
/* #define RT_SCHEDULER_DEBUG */
|
|
||||||
|
|
||||||
static rt_int16_t rt_scheduler_lock_nest;
|
static rt_int16_t rt_scheduler_lock_nest;
|
||||||
extern volatile rt_uint8_t rt_interrupt_nest;
|
extern volatile rt_uint8_t rt_interrupt_nest;
|
||||||
|
|
||||||
|
@ -134,9 +132,8 @@ void rt_system_scheduler_init(void)
|
||||||
|
|
||||||
rt_scheduler_lock_nest = 0;
|
rt_scheduler_lock_nest = 0;
|
||||||
|
|
||||||
#ifdef RT_SCHEDULER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
||||||
rt_kprintf("start scheduler: max priority 0x%02x\n", RT_THREAD_PRIORITY_MAX);
|
("start scheduler: max priority 0x%02x\n", RT_THREAD_PRIORITY_MAX));
|
||||||
#endif
|
|
||||||
|
|
||||||
for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
|
for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
|
||||||
{
|
{
|
||||||
|
@ -277,14 +274,14 @@ void rt_schedule()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_scheduler_hook != RT_NULL) rt_scheduler_hook(from_thread, to_thread);
|
RT_OBJECT_HOOK_CALL2(rt_scheduler_hook,from_thread, to_thread);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* switch to new thread */
|
/* switch to new thread */
|
||||||
#ifdef RT_SCHEDULER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
||||||
rt_kprintf("[%d]switch to priority#%d thread:%s\n", rt_interrupt_nest,
|
("[%d]switch to priority#%d thread:%s\n", rt_interrupt_nest,
|
||||||
highest_ready_priority, to_thread->name);
|
highest_ready_priority, to_thread->name));
|
||||||
#endif
|
|
||||||
#ifdef RT_USING_OVERFLOW_CHECK
|
#ifdef RT_USING_OVERFLOW_CHECK
|
||||||
_rt_scheduler_stack_check(to_thread);
|
_rt_scheduler_stack_check(to_thread);
|
||||||
#endif
|
#endif
|
||||||
|
@ -295,9 +292,8 @@ void rt_schedule()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef RT_SCHEDULER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,("switch in interrupt\n"));
|
||||||
rt_kprintf("switch in interrupt\n");
|
|
||||||
#endif
|
|
||||||
rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp,
|
rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp,
|
||||||
(rt_uint32_t)&to_thread->sp);
|
(rt_uint32_t)&to_thread->sp);
|
||||||
}
|
}
|
||||||
|
@ -332,12 +328,13 @@ void rt_schedule_insert_thread(struct rt_thread* thread)
|
||||||
&(thread->tlist));
|
&(thread->tlist));
|
||||||
|
|
||||||
/* set priority mask */
|
/* set priority mask */
|
||||||
#ifdef RT_SCHEDULER_DEBUG
|
#if RT_DEBUG_SCHEDULER
|
||||||
#if RT_THREAD_PRIORITY_MAX <= 32
|
#if RT_THREAD_PRIORITY_MAX <= 32
|
||||||
rt_kprintf("insert thread[%s], the priority: %d\n", thread->name, thread->current_priority);
|
rt_kprintf("insert thread[%s], the priority: %d\n", thread->name, thread->current_priority);
|
||||||
#else
|
#else
|
||||||
rt_kprintf("insert thread[%s], the priority: %d 0x%x %d\n", thread->name, thread->number, thread->number_mask, thread->high_mask);
|
rt_kprintf("insert thread[%s], the priority: %d 0x%x %d\n", thread->name, thread->number, thread->number_mask, thread->high_mask);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if RT_THREAD_PRIORITY_MAX > 32
|
#if RT_THREAD_PRIORITY_MAX > 32
|
||||||
|
@ -365,13 +362,14 @@ void rt_schedule_remove_thread(struct rt_thread* thread)
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
temp = rt_hw_interrupt_disable();
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
#ifdef RT_SCHEDULER_DEBUG
|
#if RT_DEBUG_SCHEDULER
|
||||||
#if RT_THREAD_PRIORITY_MAX <= 32
|
#if RT_THREAD_PRIORITY_MAX <= 32
|
||||||
rt_kprintf("remove thread[%s], the priority: %d\n", thread->name, thread->current_priority);
|
rt_kprintf("remove thread[%s], the priority: %d\n", thread->name, thread->current_priority);
|
||||||
#else
|
#else
|
||||||
rt_kprintf("remove thread[%s], the priority: %d 0x%x %d\n", thread->name, thread->number,
|
rt_kprintf("remove thread[%s], the priority: %d 0x%x %d\n", thread->name, thread->number,
|
||||||
thread->number_mask, thread->high_mask);
|
thread->number_mask, thread->high_mask);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* remove thread from ready list */
|
/* remove thread from ready list */
|
||||||
|
|
57
src/slab.c
57
src/slab.c
|
@ -56,7 +56,6 @@
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "kservice.h"
|
#include "kservice.h"
|
||||||
|
|
||||||
/* #define RT_SLAB_DEBUG */
|
|
||||||
#define RT_MEM_STATS
|
#define RT_MEM_STATS
|
||||||
|
|
||||||
#if defined (RT_USING_HEAP) && defined (RT_USING_SLAB)
|
#if defined (RT_USING_HEAP) && defined (RT_USING_SLAB)
|
||||||
|
@ -338,6 +337,8 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
|
||||||
{
|
{
|
||||||
rt_uint32_t limsize, npages;
|
rt_uint32_t limsize, npages;
|
||||||
|
|
||||||
|
RT_DEBUG_NOT_REENT
|
||||||
|
|
||||||
/* align begin and end addr to page */
|
/* align begin and end addr to page */
|
||||||
heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
|
heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
|
||||||
heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
|
heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
|
||||||
|
@ -354,10 +355,8 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
|
||||||
/* initialize heap semaphore */
|
/* initialize heap semaphore */
|
||||||
rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
|
rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
rt_kprintf("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n", heap_start, heap_end,
|
("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n", heap_start, heap_end, limsize, npages));
|
||||||
limsize, npages);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* init pages */
|
/* init pages */
|
||||||
rt_page_init((void*)heap_start, npages);
|
rt_page_init((void*)heap_start, npages);
|
||||||
|
@ -372,18 +371,17 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
|
||||||
|
|
||||||
zone_page_cnt = zone_size / RT_MM_PAGE_SIZE;
|
zone_page_cnt = zone_size / RT_MM_PAGE_SIZE;
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
rt_kprintf("zone size 0x%x, zone page count 0x%x\n", zone_size, zone_page_cnt);
|
("zone size 0x%x, zone page count 0x%x\n", zone_size, zone_page_cnt));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* allocate memusage array */
|
/* allocate memusage array */
|
||||||
limsize = npages * sizeof(struct memusage);
|
limsize = npages * sizeof(struct memusage);
|
||||||
limsize = RT_ALIGN(limsize, RT_MM_PAGE_SIZE);
|
limsize = RT_ALIGN(limsize, RT_MM_PAGE_SIZE);
|
||||||
memusage = rt_page_alloc(limsize/RT_MM_PAGE_SIZE);
|
memusage = rt_page_alloc(limsize/RT_MM_PAGE_SIZE);
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
rt_kprintf("memusage 0x%x, size 0x%x\n", (rt_uint32_t)memusage, limsize);
|
("memusage 0x%x, size 0x%x\n", (rt_uint32_t)memusage, limsize));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -533,12 +531,11 @@ void *rt_malloc(rt_size_t size)
|
||||||
kup->type = PAGE_TYPE_LARGE;
|
kup->type = PAGE_TYPE_LARGE;
|
||||||
kup->size = size >> RT_MM_PAGE_BITS;
|
kup->size = size >> RT_MM_PAGE_BITS;
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,("malloc a large memory 0x%x, page cnt %d, kup %d\n",
|
||||||
rt_kprintf("malloc a large memory 0x%x, page cnt %d, kup %d\n",
|
|
||||||
size,
|
size,
|
||||||
size >> RT_MM_PAGE_BITS,
|
size >> RT_MM_PAGE_BITS,
|
||||||
((rt_uint32_t)chunk - heap_start) >> RT_MM_PAGE_BITS);
|
((rt_uint32_t)chunk - heap_start) >> RT_MM_PAGE_BITS));
|
||||||
#endif
|
|
||||||
/* lock heap */
|
/* lock heap */
|
||||||
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
|
@ -563,9 +560,8 @@ void *rt_malloc(rt_size_t size)
|
||||||
zi = zoneindex(&size);
|
zi = zoneindex(&size);
|
||||||
RT_ASSERT(zi < NZONES);
|
RT_ASSERT(zi < NZONES);
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
rt_kprintf("try to malloc 0x%x on zone: %d\n", size, zi);
|
("try to malloc 0x%x on zone: %d\n", size, zi));
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((z = zone_array[zi]) != RT_NULL)
|
if ((z = zone_array[zi]) != RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -635,9 +631,7 @@ void *rt_malloc(rt_size_t size)
|
||||||
/* lock heap */
|
/* lock heap */
|
||||||
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,("alloc a new zone: 0x%x\n", (rt_uint32_t)z));
|
||||||
rt_kprintf("alloc a new zone: 0x%x\n", (rt_uint32_t)z);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* set message usage */
|
/* set message usage */
|
||||||
for (off = 0, kup = btokup(z); off < zone_page_cnt; off ++)
|
for (off = 0, kup = btokup(z); off < zone_page_cnt; off ++)
|
||||||
|
@ -688,7 +682,7 @@ done:
|
||||||
rt_sem_release(&heap_sem);
|
rt_sem_release(&heap_sem);
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_malloc_hook != RT_NULL) rt_malloc_hook((char*)chunk, size);
|
RT_OBJECT_HOOK_CALL2(rt_malloc_hook,(char*)chunk, size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return chunk;
|
return chunk;
|
||||||
|
@ -804,7 +798,7 @@ void rt_free(void *ptr)
|
||||||
if (ptr == RT_NULL) return ;
|
if (ptr == RT_NULL) return ;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_free_hook != RT_NULL) rt_free_hook(ptr);
|
RT_OBJECT_HOOK_CALL2(rt_free_hook,ptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
|
@ -816,13 +810,14 @@ void rt_free(void *ptr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* get memory usage */
|
/* get memory usage */
|
||||||
#ifdef RT_SLAB_DEBUG
|
#if RT_DEBUG_SLAB
|
||||||
{
|
{
|
||||||
rt_uint32_t addr = ((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK);
|
rt_uint32_t addr = ((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK);
|
||||||
rt_kprintf("free a memory 0x%x and align to 0x%x, kup index %d\n",
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
|
("free a memory 0x%x and align to 0x%x, kup index %d\n",
|
||||||
(rt_uint32_t)ptr,
|
(rt_uint32_t)ptr,
|
||||||
(rt_uint32_t)addr,
|
(rt_uint32_t)addr,
|
||||||
((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS);
|
((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -843,9 +838,8 @@ void rt_free(void *ptr)
|
||||||
#endif
|
#endif
|
||||||
rt_sem_release(&heap_sem);
|
rt_sem_release(&heap_sem);
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
rt_kprintf("free large memory block 0x%x, page count %d\n", (rt_uint32_t)ptr, size);
|
("free large memory block 0x%x, page count %d\n", (rt_uint32_t)ptr, size));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* free this page */
|
/* free this page */
|
||||||
rt_page_free(ptr, size);
|
rt_page_free(ptr, size);
|
||||||
|
@ -888,9 +882,8 @@ void rt_free(void *ptr)
|
||||||
{
|
{
|
||||||
slab_zone **pz;
|
slab_zone **pz;
|
||||||
|
|
||||||
#ifdef RT_SLAB_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_SLAB,
|
||||||
rt_kprintf("free zone 0x%x\n", (rt_uint32_t)z, z->z_zoneindex);
|
("free zone 0x%x\n", (rt_uint32_t)z, z->z_zoneindex));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* remove zone from zone array list */
|
/* remove zone from zone array list */
|
||||||
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next) ;
|
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next) ;
|
||||||
|
|
27
src/thread.c
27
src/thread.c
|
@ -26,7 +26,6 @@
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
#include "kservice.h"
|
#include "kservice.h"
|
||||||
|
|
||||||
/*#define THREAD_DEBUG */
|
|
||||||
|
|
||||||
extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
|
extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
|
||||||
extern struct rt_thread* rt_current_thread;
|
extern struct rt_thread* rt_current_thread;
|
||||||
|
@ -206,10 +205,8 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
|
||||||
thread->number_mask = 1L << thread->current_priority; //1L means long int,fixed compile mistake with IAR EW M16C v3.401,fify 20100410
|
thread->number_mask = 1L << thread->current_priority; //1L means long int,fixed compile mistake with IAR EW M16C v3.401,fify 20100410
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef THREAD_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_THREAD,\
|
||||||
rt_kprintf("startup a thread:%s with priority:%d\n", thread->name, thread->init_priority);
|
("startup a thread:%s with priority:%d\n", thread->name, thread->init_priority));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* change thread stat */
|
/* change thread stat */
|
||||||
thread->stat = RT_THREAD_SUSPEND;
|
thread->stat = RT_THREAD_SUSPEND;
|
||||||
/* then resume it */
|
/* then resume it */
|
||||||
|
@ -536,15 +533,13 @@ rt_err_t rt_thread_suspend (rt_thread_t thread)
|
||||||
/* thread check */
|
/* thread check */
|
||||||
RT_ASSERT(thread != RT_NULL);
|
RT_ASSERT(thread != RT_NULL);
|
||||||
|
|
||||||
#ifdef THREAD_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: %s\n", thread->name));
|
||||||
rt_kprintf("thread suspend: %s\n", thread->name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (thread->stat != RT_THREAD_READY)
|
if (thread->stat != RT_THREAD_READY)
|
||||||
{
|
{
|
||||||
#ifdef THREAD_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_THREAD,\
|
||||||
rt_kprintf("thread suspend: thread disorder, %d\n", thread->stat);
|
("thread suspend: thread disorder, %d\n", thread->stat));
|
||||||
#endif
|
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,15 +571,13 @@ rt_err_t rt_thread_resume (rt_thread_t thread)
|
||||||
/* thread check */
|
/* thread check */
|
||||||
RT_ASSERT(thread != RT_NULL);
|
RT_ASSERT(thread != RT_NULL);
|
||||||
|
|
||||||
#ifdef THREAD_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread resume: %s\n", thread->name));
|
||||||
rt_kprintf("thread resume: %s\n", thread->name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (thread->stat != RT_THREAD_SUSPEND)
|
if (thread->stat != RT_THREAD_SUSPEND)
|
||||||
{
|
{
|
||||||
#ifdef THREAD_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_THREAD, \
|
||||||
rt_kprintf("thread resume: thread disorder, %d\n", thread->stat);
|
("thread resume: thread disorder, %d\n", thread->stat));
|
||||||
#endif
|
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
42
src/timer.c
42
src/timer.c
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
#include "kservice.h"
|
#include "kservice.h"
|
||||||
|
|
||||||
/* #define RT_TIMER_DEBUG */
|
|
||||||
|
|
||||||
/* hard timer list */
|
/* hard timer list */
|
||||||
static rt_list_t rt_timer_list;
|
static rt_list_t rt_timer_list;
|
||||||
|
|
||||||
|
@ -213,7 +211,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||||
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) return -RT_ERROR;
|
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) return -RT_ERROR;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(timer->parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(timer->parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -280,7 +278,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
|
||||||
if(!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) return -RT_ERROR;
|
if(!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) return -RT_ERROR;
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_object_put_hook != RT_NULL) rt_object_put_hook(&(timer->parent));
|
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(timer->parent));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
|
@ -350,9 +348,7 @@ void rt_timer_check(void)
|
||||||
rt_tick_t current_tick;
|
rt_tick_t current_tick;
|
||||||
register rt_base_t level;
|
register rt_base_t level;
|
||||||
|
|
||||||
#ifdef RT_TIMER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_TIMER,("timer check enter\n"));
|
||||||
rt_kprintf("timer check enter\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
current_tick = rt_tick_get();
|
current_tick = rt_tick_get();
|
||||||
|
|
||||||
|
@ -369,21 +365,25 @@ void rt_timer_check(void)
|
||||||
if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
|
if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_timer_timeout_hook != RT_NULL) rt_timer_timeout_hook(t);
|
RT_OBJECT_HOOK_CALL2(rt_timer_timeout_hook,t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* remove timer from timer list firstly */
|
/* remove timer from timer list firstly */
|
||||||
rt_list_remove(&(t->list));
|
rt_list_remove(&(t->list));
|
||||||
|
|
||||||
|
/* Timeout function called while interrupt is disabled, reentant function
|
||||||
|
is a must */
|
||||||
|
RT_DEBUG_REENT_IN
|
||||||
|
|
||||||
/* call timeout function */
|
/* call timeout function */
|
||||||
t->timeout_func(t->parameter);
|
t->timeout_func(t->parameter);
|
||||||
|
|
||||||
|
RT_DEBUG_REENT_OUT
|
||||||
|
|
||||||
/* re-get tick */
|
/* re-get tick */
|
||||||
current_tick = rt_tick_get();
|
current_tick = rt_tick_get();
|
||||||
|
|
||||||
#ifdef RT_TIMER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_TIMER,("current tick: %d\n", current_tick));
|
||||||
rt_kprintf("current tick: %d\n", current_tick);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
|
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
|
||||||
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
|
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
|
||||||
|
@ -409,9 +409,8 @@ void rt_timer_check(void)
|
||||||
rt_soft_timer_tick_increase ( );
|
rt_soft_timer_tick_increase ( );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_TIMER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_TIMER,("timer check leave\n"));
|
||||||
rt_kprintf("timer check leave\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_TIMER_SOFT
|
#ifdef RT_USING_TIMER_SOFT
|
||||||
|
@ -443,9 +442,7 @@ void rt_soft_timer_check()
|
||||||
rt_list_t *n;
|
rt_list_t *n;
|
||||||
struct rt_timer *t;
|
struct rt_timer *t;
|
||||||
|
|
||||||
#ifdef RT_TIMER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_TIMER,("software timer check enter\n"));
|
||||||
rt_kprintf("software timer check enter\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
current_tick = rt_tick_get();
|
current_tick = rt_tick_get();
|
||||||
|
|
||||||
|
@ -459,7 +456,7 @@ void rt_soft_timer_check()
|
||||||
if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
|
if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
if (rt_timer_timeout_hook != RT_NULL) rt_timer_timeout_hook(t);
|
RT_OBJECT_HOOK_CALL2(rt_timer_timeout_hook,t);
|
||||||
#endif
|
#endif
|
||||||
/* move node to the next */
|
/* move node to the next */
|
||||||
n = n->next;
|
n = n->next;
|
||||||
|
@ -473,9 +470,7 @@ void rt_soft_timer_check()
|
||||||
/* re-get tick */
|
/* re-get tick */
|
||||||
current_tick = rt_tick_get();
|
current_tick = rt_tick_get();
|
||||||
|
|
||||||
#ifdef RT_TIMER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_TIMER,("current tick: %d\n", current_tick));
|
||||||
rt_kprintf("current tick: %d\n", current_tick);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
|
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
|
||||||
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
|
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
|
||||||
|
@ -493,9 +488,8 @@ void rt_soft_timer_check()
|
||||||
else break; /* not check anymore */
|
else break; /* not check anymore */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_TIMER_DEBUG
|
RT_DEBUG_LOG(RT_DEBUG_TIMER,("software timer check leave\n"));
|
||||||
rt_kprintf("software timer check leave\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* system timer thread entry */
|
/* system timer thread entry */
|
||||||
|
|
Loading…
Reference in New Issue