Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
2aae989f
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2aae989f
编写于
9月 18, 2017
作者:
G
geniusgogo
提交者:
GitHub
9月 18, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into RT_MACRO
上级
6b06cb83
ed46356e
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
227 addition
and
226 deletion
+227
-226
include/rtdef.h
include/rtdef.h
+27
-27
include/rtthread.h
include/rtthread.h
+9
-9
src/components.c
src/components.c
+9
-9
src/idle.c
src/idle.c
+6
-6
src/ipc.c
src/ipc.c
+8
-8
src/kservice.c
src/kservice.c
+42
-41
src/mem.c
src/mem.c
+5
-5
src/memheap.c
src/memheap.c
+8
-8
src/mempool.c
src/mempool.c
+2
-2
src/module.c
src/module.c
+45
-45
src/object.c
src/object.c
+7
-7
src/scheduler.c
src/scheduler.c
+3
-3
src/slab.c
src/slab.c
+17
-17
src/thread.c
src/thread.c
+9
-9
src/timer.c
src/timer.c
+30
-30
未找到文件。
include/rtdef.h
浏览文件 @
2aae989f
...
@@ -97,7 +97,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
...
@@ -97,7 +97,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
#define RT_UNUSED __attribute__((unused))
#define RT_UNUSED __attribute__((unused))
#define RT_USED __attribute__((used))
#define RT_USED __attribute__((used))
#define ALIGN(n) __attribute__((aligned(n)))
#define ALIGN(n) __attribute__((aligned(n)))
#define RT_WEAK __weak
#define RT_WEAK
__weak
#define rt_inline static __inline
#define rt_inline static __inline
/* module compiling */
/* module compiling */
#ifdef RT_USING_MODULE
#ifdef RT_USING_MODULE
...
@@ -121,7 +121,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
...
@@ -121,7 +121,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
#ifdef RT_USING_NEWLIB
#ifdef RT_USING_NEWLIB
#include <stdarg.h>
#include <stdarg.h>
#else
#else
/* the version of GNU GCC must be greater than 4.x */
/* the version of GNU GCC must be greater than 4.x */
typedef
__builtin_va_list
__gnuc_va_list
;
typedef
__builtin_va_list
__gnuc_va_list
;
typedef
__gnuc_va_list
va_list
;
typedef
__gnuc_va_list
va_list
;
#define va_start(v,l) __builtin_va_start(v,l)
#define va_start(v,l) __builtin_va_start(v,l)
...
@@ -142,7 +142,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
...
@@ -142,7 +142,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
#define RT_UNUSED __attribute__((unused))
#define RT_UNUSED __attribute__((unused))
#define RT_USED __attribute__((used))
#define RT_USED __attribute__((used))
#define ALIGN(n) __attribute__((aligned(n)))
#define ALIGN(n) __attribute__((aligned(n)))
#define RT_WEAK __attribute__((weak))
#define RT_WEAK
__attribute__((weak))
#define rt_inline static inline
#define rt_inline static inline
#define RTT_API
#define RTT_API
#elif defined (_MSC_VER)
#elif defined (_MSC_VER)
...
@@ -151,7 +151,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
...
@@ -151,7 +151,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
#define RT_UNUSED
#define RT_UNUSED
#define RT_USED
#define RT_USED
#define ALIGN(n) __declspec(align(n))
#define ALIGN(n) __declspec(align(n))
#define RT_WEAK
#define RT_WEAK
#define rt_inline static __inline
#define rt_inline static __inline
#define RTT_API
#define RTT_API
#elif defined (__TI_COMPILER_VERSION__)
#elif defined (__TI_COMPILER_VERSION__)
...
@@ -177,20 +177,20 @@ typedef int (*init_fn_t)(void);
...
@@ -177,20 +177,20 @@ typedef int (*init_fn_t)(void);
#ifdef _MSC_VER
/* we do not support MS VC++ compiler */
#ifdef _MSC_VER
/* we do not support MS VC++ compiler */
#define INIT_EXPORT(fn, level)
#define INIT_EXPORT(fn, level)
#else
#else
#if RT_DEBUG_INIT
#if RT_DEBUG_INIT
struct
rt_init_desc
struct
rt_init_desc
{
{
const
char
*
fn_name
;
const
char
*
fn_name
;
const
init_fn_t
fn
;
const
init_fn_t
fn
;
};
};
#define INIT_EXPORT(fn, level)
\
#define INIT_EXPORT(fn, level)
\
const char __rti_##fn##_name[] = #fn; \
const char __rti_##fn##_name[] = #fn; \
const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn."level) = \
const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn."level) = \
{ __rti_##fn##_name, fn};
{ __rti_##fn##_name, fn};
#else
#else
#define INIT_EXPORT(fn, level) \
#define INIT_EXPORT(fn, level) \
const init_fn_t __rt_init_##fn SECTION(".rti_fn."level) = fn
const init_fn_t __rt_init_##fn SECTION(".rti_fn."level) = fn
#endif
#endif
#endif
#endif
#else
#else
#define INIT_EXPORT(fn, level)
#define INIT_EXPORT(fn, level)
...
@@ -206,7 +206,7 @@ typedef int (*init_fn_t)(void);
...
@@ -206,7 +206,7 @@ typedef int (*init_fn_t)(void);
/* file system initialization (dfs-elm, dfs-rom, ...) */
/* file system initialization (dfs-elm, dfs-rom, ...) */
#define INIT_FS_EXPORT(fn) INIT_EXPORT(fn, "4")
#define INIT_FS_EXPORT(fn) INIT_EXPORT(fn, "4")
/* environment initialization (mount disk, ...) */
/* environment initialization (mount disk, ...) */
#define INIT_ENV_EXPORT(fn)
INIT_EXPORT(fn, "5")
#define INIT_ENV_EXPORT(fn)
INIT_EXPORT(fn, "5")
/* appliation initialization (rtgui application etc ...) */
/* appliation initialization (rtgui application etc ...) */
#define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
#define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
...
@@ -759,8 +759,8 @@ enum rt_device_class_type
...
@@ -759,8 +759,8 @@ enum rt_device_class_type
RT_Device_Class_Pipe
,
/**< Pipe device */
RT_Device_Class_Pipe
,
/**< Pipe device */
RT_Device_Class_Portal
,
/**< Portal device */
RT_Device_Class_Portal
,
/**< Portal device */
RT_Device_Class_Timer
,
/**< Timer device */
RT_Device_Class_Timer
,
/**< Timer device */
RT_Device_Class_Miscellaneous
,
/**< Miscellaneous device */
RT_Device_Class_Miscellaneous
,
/**< Miscellaneous device */
RT_Device_Class_Unknown
/**< unknown device */
RT_Device_Class_Unknown
/**< unknown device */
};
};
/**
/**
...
@@ -778,9 +778,9 @@ enum rt_device_class_type
...
@@ -778,9 +778,9 @@ enum rt_device_class_type
#define RT_DEVICE_FLAG_SUSPENDED 0x020
/**< device is suspended */
#define RT_DEVICE_FLAG_SUSPENDED 0x020
/**< device is suspended */
#define RT_DEVICE_FLAG_STREAM 0x040
/**< stream mode */
#define RT_DEVICE_FLAG_STREAM 0x040
/**< stream mode */
#define RT_DEVICE_CTRL_CONFIG 0x03
/* configure device */
#define RT_DEVICE_CTRL_CONFIG 0x03
/* configure device */
#define RT_DEVICE_CTRL_SET_INT 0x10
/* enable receive irq */
#define RT_DEVICE_CTRL_SET_INT 0x10
/* enable receive irq */
#define RT_DEVICE_CTRL_CLR_INT 0x11
/* disable receive irq */
#define RT_DEVICE_CTRL_CLR_INT 0x11
/* disable receive irq */
#define RT_DEVICE_CTRL_GET_INT 0x12
#define RT_DEVICE_CTRL_GET_INT 0x12
#define RT_DEVICE_FLAG_INT_RX 0x100
/**< INT mode on Rx */
#define RT_DEVICE_FLAG_INT_RX 0x100
/**< INT mode on Rx */
...
@@ -969,15 +969,15 @@ struct rt_module
...
@@ -969,15 +969,15 @@ struct rt_module
{
{
struct
rt_object
parent
;
/**< inherit from object */
struct
rt_object
parent
;
/**< inherit from object */
rt_uint32_t
vstart_addr
;
/**< VMA base address for the
rt_uint32_t
vstart_addr
;
/**< VMA base address for the
first LOAD segment. */
first LOAD segment. */
rt_uint8_t
*
module_space
;
/**< module memory space */
rt_uint8_t
*
module_space
;
/**< module memory space */
void
*
module_entry
;
/**< the entry address of module */
void
*
module_entry
;
/**< the entry address of module */
rt_thread_t
module_thread
;
/**< the main thread of module */
rt_thread_t
module_thread
;
/**< the main thread of module */
rt_uint8_t
*
module_cmd_line
;
/**< module command line */
rt_uint8_t
*
module_cmd_line
;
/**< module command line */
rt_uint32_t
module_cmd_size
;
/**< the size of module command line */
rt_uint32_t
module_cmd_size
;
/**< the size of module command line */
#ifdef RT_USING_SLAB
#ifdef RT_USING_SLAB
/* module memory allocator */
/* module memory allocator */
...
...
include/rtthread.h
浏览文件 @
2aae989f
...
@@ -262,8 +262,8 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
...
@@ -262,8 +262,8 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
void
*
start_addr
,
void
*
start_addr
,
rt_uint32_t
size
);
rt_uint32_t
size
);
rt_err_t
rt_memheap_detach
(
struct
rt_memheap
*
heap
);
rt_err_t
rt_memheap_detach
(
struct
rt_memheap
*
heap
);
void
*
rt_memheap_alloc
(
struct
rt_memheap
*
heap
,
rt_uint32_t
size
);
void
*
rt_memheap_alloc
(
struct
rt_memheap
*
heap
,
rt_uint32_t
size
);
void
*
rt_memheap_realloc
(
struct
rt_memheap
*
heap
,
void
*
ptr
,
rt_size_t
newsize
);
void
*
rt_memheap_realloc
(
struct
rt_memheap
*
heap
,
void
*
ptr
,
rt_size_t
newsize
);
void
rt_memheap_free
(
void
*
ptr
);
void
rt_memheap_free
(
void
*
ptr
);
#endif
#endif
...
@@ -429,7 +429,7 @@ rt_module_t rt_module_load(const char *name, void *module_ptr);
...
@@ -429,7 +429,7 @@ rt_module_t rt_module_load(const char *name, void *module_ptr);
rt_err_t
rt_module_unload
(
rt_module_t
module
);
rt_err_t
rt_module_unload
(
rt_module_t
module
);
#ifdef RT_USING_DFS
#ifdef RT_USING_DFS
rt_module_t
rt_module_open
(
const
char
*
filename
);
rt_module_t
rt_module_open
(
const
char
*
filename
);
rt_module_t
rt_module_exec_cmd
(
const
char
*
path
,
const
char
*
cmd_line
,
int
size
);
rt_module_t
rt_module_exec_cmd
(
const
char
*
path
,
const
char
*
cmd_line
,
int
size
);
#endif
#endif
void
*
rt_module_malloc
(
rt_size_t
size
);
void
*
rt_module_malloc
(
rt_size_t
size
);
void
*
rt_module_realloc
(
void
*
ptr
,
rt_size_t
size
);
void
*
rt_module_realloc
(
void
*
ptr
,
rt_size_t
size
);
...
@@ -496,7 +496,7 @@ void rt_kputs(const char *str);
...
@@ -496,7 +496,7 @@ void rt_kputs(const char *str);
#endif
#endif
rt_int32_t
rt_vsprintf
(
char
*
dest
,
const
char
*
format
,
va_list
arg_ptr
);
rt_int32_t
rt_vsprintf
(
char
*
dest
,
const
char
*
format
,
va_list
arg_ptr
);
rt_int32_t
rt_vsnprintf
(
char
*
buf
,
rt_size_t
size
,
const
char
*
fmt
,
va_list
args
);
rt_int32_t
rt_vsnprintf
(
char
*
buf
,
rt_size_t
size
,
const
char
*
fmt
,
va_list
args
);
rt_int32_t
rt_sprintf
(
char
*
buf
,
const
char
*
format
,
...);
rt_int32_t
rt_sprintf
(
char
*
buf
,
const
char
*
format
,
...);
rt_int32_t
rt_snprintf
(
char
*
buf
,
rt_size_t
size
,
const
char
*
format
,
...);
rt_int32_t
rt_snprintf
(
char
*
buf
,
rt_size_t
size
,
const
char
*
format
,
...);
#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
...
@@ -517,8 +517,8 @@ void *rt_memset(void *src, int c, rt_ubase_t n);
...
@@ -517,8 +517,8 @@ void *rt_memset(void *src, int c, rt_ubase_t n);
void
*
rt_memcpy
(
void
*
dest
,
const
void
*
src
,
rt_ubase_t
n
);
void
*
rt_memcpy
(
void
*
dest
,
const
void
*
src
,
rt_ubase_t
n
);
rt_int32_t
rt_strncmp
(
const
char
*
cs
,
const
char
*
ct
,
rt_ubase_t
count
);
rt_int32_t
rt_strncmp
(
const
char
*
cs
,
const
char
*
ct
,
rt_ubase_t
count
);
rt_int32_t
rt_strcmp
(
const
char
*
cs
,
const
char
*
ct
);
rt_int32_t
rt_strcmp
(
const
char
*
cs
,
const
char
*
ct
);
rt_size_t
rt_strlen
(
const
char
*
src
);
rt_size_t
rt_strlen
(
const
char
*
src
);
char
*
rt_strdup
(
const
char
*
s
);
char
*
rt_strdup
(
const
char
*
s
);
char
*
rt_strstr
(
const
char
*
str1
,
const
char
*
str2
);
char
*
rt_strstr
(
const
char
*
str1
,
const
char
*
str2
);
...
@@ -531,10 +531,10 @@ rt_uint32_t rt_strcasecmp(const char *a, const char *b);
...
@@ -531,10 +531,10 @@ rt_uint32_t rt_strcasecmp(const char *a, const char *b);
void
rt_show_version
(
void
);
void
rt_show_version
(
void
);
#ifdef RT_DEBUG
#ifdef RT_DEBUG
extern
void
(
*
rt_assert_hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
);
extern
void
(
*
rt_assert_hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
);
void
rt_assert_set_hook
(
void
(
*
hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
));
void
rt_assert_set_hook
(
void
(
*
hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
));
void
rt_assert_handler
(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
);
void
rt_assert_handler
(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
);
#endif
/* RT_DEBUG */
#endif
/* RT_DEBUG */
/**@}*/
/**@}*/
...
...
src/components.c
浏览文件 @
2aae989f
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
#ifdef RT_USING_COMPONENTS_INIT
#ifdef RT_USING_COMPONENTS_INIT
/*
/*
* Components Initialization will initialize some driver and components as following
* Components Initialization will initialize some driver and components as following
* order:
* order:
* rti_start --> 0
* rti_start --> 0
* BOARD_EXPORT --> 1
* BOARD_EXPORT --> 1
...
@@ -51,17 +51,17 @@
...
@@ -51,17 +51,17 @@
* COMPONENT_EXPORT --> 3
* COMPONENT_EXPORT --> 3
* FS_EXPORT --> 4
* FS_EXPORT --> 4
* ENV_EXPORT --> 5
* ENV_EXPORT --> 5
* APP_EXPORT --> 6
* APP_EXPORT --> 6
*
*
* rti_end --> 6.end
* rti_end --> 6.end
*
*
* These automatically initializaiton, the driver or component initial function must
* These automatically initializaiton, the driver or component initial function must
* be defined with:
* be defined with:
* INIT_BOARD_EXPORT(fn);
* INIT_BOARD_EXPORT(fn);
* INIT_DEVICE_EXPORT(fn);
* INIT_DEVICE_EXPORT(fn);
* ...
* ...
* INIT_APP_EXPORT(fn);
* INIT_APP_EXPORT(fn);
* etc.
* etc.
*/
*/
static
int
rti_start
(
void
)
static
int
rti_start
(
void
)
{
{
...
@@ -155,11 +155,11 @@ int $Sub$$main(void)
...
@@ -155,11 +155,11 @@ int $Sub$$main(void)
#elif defined(__ICCARM__)
#elif defined(__ICCARM__)
extern
int
main
(
void
);
extern
int
main
(
void
);
/* __low_level_init will auto called by IAR cstartup */
/* __low_level_init will auto called by IAR cstartup */
extern
void
__iar_data_init3
(
void
);
extern
void
__iar_data_init3
(
void
);
int
__low_level_init
(
void
)
int
__low_level_init
(
void
)
{
{
// call IAR table copy function.
// call IAR table copy function.
__iar_data_init3
();
__iar_data_init3
();
rt_hw_interrupt_disable
();
rt_hw_interrupt_disable
();
rtthread_startup
();
rtthread_startup
();
return
0
;
return
0
;
...
@@ -221,7 +221,7 @@ void rt_application_init(void)
...
@@ -221,7 +221,7 @@ void rt_application_init(void)
int
rtthread_startup
(
void
)
int
rtthread_startup
(
void
)
{
{
rt_hw_interrupt_disable
();
rt_hw_interrupt_disable
();
/* board level initalization
/* board level initalization
* NOTE: please initialize heap inside board initialization.
* NOTE: please initialize heap inside board initialization.
...
...
src/idle.c
浏览文件 @
2aae989f
...
@@ -55,7 +55,7 @@ static void (*rt_thread_idle_hook)();
...
@@ -55,7 +55,7 @@ static void (*rt_thread_idle_hook)();
/**
/**
* @ingroup Hook
* @ingroup Hook
* This function sets a hook function to idle thread loop. When the system performs
* This function sets a hook function to idle thread loop. When the system performs
* idle loop, this hook function should be invoked.
* idle loop, this hook function should be invoked.
*
*
* @param hook the specified hook function
* @param hook the specified hook function
...
@@ -77,7 +77,7 @@ rt_inline int _has_defunct_thread(void)
...
@@ -77,7 +77,7 @@ rt_inline int _has_defunct_thread(void)
* into a "if".
* into a "if".
*
*
* So add the volatile qualifier here. */
* So add the volatile qualifier here. */
const
volatile
rt_list_t
*
l
=
(
const
volatile
rt_list_t
*
)
&
rt_thread_defunct
;
const
volatile
rt_list_t
*
l
=
(
const
volatile
rt_list_t
*
)
&
rt_thread_defunct
;
return
l
->
next
!=
l
;
return
l
->
next
!=
l
;
}
}
...
@@ -155,8 +155,8 @@ void rt_thread_idle_excute(void)
...
@@ -155,8 +155,8 @@ void rt_thread_idle_excute(void)
rt_module_free
((
rt_module_t
)
thread
->
module_id
,
thread
->
stack_addr
);
rt_module_free
((
rt_module_t
)
thread
->
module_id
,
thread
->
stack_addr
);
else
else
#endif
#endif
/* release thread's stack */
/* release thread's stack */
RT_KERNEL_FREE
(
thread
->
stack_addr
);
RT_KERNEL_FREE
(
thread
->
stack_addr
);
/* delete thread object */
/* delete thread object */
rt_object_delete
((
rt_object_t
)
thread
);
rt_object_delete
((
rt_object_t
)
thread
);
#endif
#endif
...
@@ -185,12 +185,12 @@ static void rt_thread_idle_entry(void *parameter)
...
@@ -185,12 +185,12 @@ static void rt_thread_idle_entry(void *parameter)
{
{
while
(
1
)
while
(
1
)
{
{
#ifdef RT_USING_IDLE_HOOK
#ifdef RT_USING_IDLE_HOOK
if
(
rt_thread_idle_hook
!=
RT_NULL
)
if
(
rt_thread_idle_hook
!=
RT_NULL
)
{
{
rt_thread_idle_hook
();
rt_thread_idle_hook
();
}
}
#endif
#endif
rt_thread_idle_excute
();
rt_thread_idle_excute
();
}
}
...
...
src/ipc.c
浏览文件 @
2aae989f
...
@@ -1382,8 +1382,8 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb)
...
@@ -1382,8 +1382,8 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb)
else
else
#endif
#endif
/* free mailbox pool */
/* free mailbox pool */
RT_KERNEL_FREE
(
mb
->
msg_pool
);
RT_KERNEL_FREE
(
mb
->
msg_pool
);
/* delete mailbox object */
/* delete mailbox object */
rt_object_delete
(
&
(
mb
->
parent
.
parent
));
rt_object_delete
(
&
(
mb
->
parent
.
parent
));
...
@@ -1775,7 +1775,7 @@ rt_err_t rt_mq_init(rt_mq_t mq,
...
@@ -1775,7 +1775,7 @@ rt_err_t rt_mq_init(rt_mq_t mq,
for
(
temp
=
0
;
temp
<
mq
->
max_msgs
;
temp
++
)
for
(
temp
=
0
;
temp
<
mq
->
max_msgs
;
temp
++
)
{
{
head
=
(
struct
rt_mq_message
*
)((
rt_uint8_t
*
)
mq
->
msg_pool
+
head
=
(
struct
rt_mq_message
*
)((
rt_uint8_t
*
)
mq
->
msg_pool
+
temp
*
(
mq
->
msg_size
+
sizeof
(
struct
rt_mq_message
)));
temp
*
(
mq
->
msg_size
+
sizeof
(
struct
rt_mq_message
)));
head
->
next
=
mq
->
msg_queue_free
;
head
->
next
=
mq
->
msg_queue_free
;
mq
->
msg_queue_free
=
head
;
mq
->
msg_queue_free
=
head
;
}
}
...
@@ -1849,7 +1849,7 @@ rt_mq_t rt_mq_create(const char *name,
...
@@ -1849,7 +1849,7 @@ rt_mq_t rt_mq_create(const char *name,
mq
->
max_msgs
=
max_msgs
;
mq
->
max_msgs
=
max_msgs
;
/* allocate message pool */
/* allocate message pool */
mq
->
msg_pool
=
RT_KERNEL_MALLOC
((
mq
->
msg_size
+
sizeof
(
struct
rt_mq_message
))
*
mq
->
max_msgs
);
mq
->
msg_pool
=
RT_KERNEL_MALLOC
((
mq
->
msg_size
+
sizeof
(
struct
rt_mq_message
))
*
mq
->
max_msgs
);
if
(
mq
->
msg_pool
==
RT_NULL
)
if
(
mq
->
msg_pool
==
RT_NULL
)
{
{
rt_mq_delete
(
mq
);
rt_mq_delete
(
mq
);
...
@@ -1866,7 +1866,7 @@ rt_mq_t rt_mq_create(const char *name,
...
@@ -1866,7 +1866,7 @@ rt_mq_t rt_mq_create(const char *name,
for
(
temp
=
0
;
temp
<
mq
->
max_msgs
;
temp
++
)
for
(
temp
=
0
;
temp
<
mq
->
max_msgs
;
temp
++
)
{
{
head
=
(
struct
rt_mq_message
*
)((
rt_uint8_t
*
)
mq
->
msg_pool
+
head
=
(
struct
rt_mq_message
*
)((
rt_uint8_t
*
)
mq
->
msg_pool
+
temp
*
(
mq
->
msg_size
+
sizeof
(
struct
rt_mq_message
)));
temp
*
(
mq
->
msg_size
+
sizeof
(
struct
rt_mq_message
)));
head
->
next
=
mq
->
msg_queue_free
;
head
->
next
=
mq
->
msg_queue_free
;
mq
->
msg_queue_free
=
head
;
mq
->
msg_queue_free
=
head
;
}
}
...
@@ -1902,8 +1902,8 @@ rt_err_t rt_mq_delete(rt_mq_t mq)
...
@@ -1902,8 +1902,8 @@ rt_err_t rt_mq_delete(rt_mq_t mq)
else
else
#endif
#endif
/* free message queue pool */
/* free message queue pool */
RT_KERNEL_FREE
(
mq
->
msg_pool
);
RT_KERNEL_FREE
(
mq
->
msg_pool
);
/* delete message queue object */
/* delete message queue object */
rt_object_delete
(
&
(
mq
->
parent
.
parent
));
rt_object_delete
(
&
(
mq
->
parent
.
parent
));
...
@@ -1942,7 +1942,7 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
...
@@ -1942,7 +1942,7 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
temp
=
rt_hw_interrupt_disable
();
temp
=
rt_hw_interrupt_disable
();
/* get a free list, there must be an empty item */
/* get a free list, there must be an empty item */
msg
=
(
struct
rt_mq_message
*
)
mq
->
msg_queue_free
;
msg
=
(
struct
rt_mq_message
*
)
mq
->
msg_queue_free
;
/* message queue is full */
/* message queue is full */
if
(
msg
==
RT_NULL
)
if
(
msg
==
RT_NULL
)
{
{
...
...
src/kservice.c
浏览文件 @
2aae989f
...
@@ -118,7 +118,7 @@ int *_rt_errno(void)
...
@@ -118,7 +118,7 @@ int *_rt_errno(void)
tid
=
rt_thread_self
();
tid
=
rt_thread_self
();
if
(
tid
!=
RT_NULL
)
if
(
tid
!=
RT_NULL
)
return
(
int
*
)
&
(
tid
->
error
);
return
(
int
*
)
&
(
tid
->
error
);
return
(
int
*
)
&
_errno
;
return
(
int
*
)
&
_errno
;
}
}
...
@@ -464,9 +464,9 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
...
@@ -464,9 +464,9 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
RTM_EXPORT
(
rt_strcmp
);
RTM_EXPORT
(
rt_strcmp
);
/**
/**
* The strnlen() function returns the number of characters in the
* The strnlen() function returns the number of characters in the
* string pointed to by s, excluding the terminating null byte ('\0'),
* string pointed to by s, excluding the terminating null byte ('\0'),
* but at most maxlen. In doing this, strnlen() looks only at the
* but at most maxlen. In doing this, strnlen() looks only at the
* first maxlen characters in the string pointed to by s and never
* first maxlen characters in the string pointed to by s and never
* beyond s+maxlen.
* beyond s+maxlen.
*
*
* @param s the string
* @param s the string
...
@@ -547,13 +547,13 @@ rt_inline rt_int32_t divide(rt_int32_t *n, rt_int32_t base)
...
@@ -547,13 +547,13 @@ rt_inline rt_int32_t divide(rt_int32_t *n, rt_int32_t base)
/* optimized for processor which does not support divide instructions. */
/* optimized for processor which does not support divide instructions. */
if
(
base
==
10
)
if
(
base
==
10
)
{
{
res
=
((
rt_uint32_t
)
*
n
)
%
10U
;
res
=
((
rt_uint32_t
)
*
n
)
%
10U
;
*
n
=
((
rt_uint32_t
)
*
n
)
/
10U
;
*
n
=
((
rt_uint32_t
)
*
n
)
/
10U
;
}
}
else
else
{
{
res
=
((
rt_uint32_t
)
*
n
)
%
16U
;
res
=
((
rt_uint32_t
)
*
n
)
%
16U
;
*
n
=
((
rt_uint32_t
)
*
n
)
/
16U
;
*
n
=
((
rt_uint32_t
)
*
n
)
/
16U
;
}
}
return
res
;
return
res
;
...
@@ -561,7 +561,7 @@ rt_inline rt_int32_t divide(rt_int32_t *n, rt_int32_t base)
...
@@ -561,7 +561,7 @@ rt_inline rt_int32_t divide(rt_int32_t *n, rt_int32_t base)
rt_inline
int
skip_atoi
(
const
char
**
s
)
rt_inline
int
skip_atoi
(
const
char
**
s
)
{
{
register
int
i
=
0
;
register
int
i
=
0
;
while
(
isdigit
(
**
s
))
while
(
isdigit
(
**
s
))
i
=
i
*
10
+
*
((
*
s
)
++
)
-
'0'
;
i
=
i
*
10
+
*
((
*
s
)
++
)
-
'0'
;
...
@@ -640,7 +640,7 @@ static char *print_number(char *buf,
...
@@ -640,7 +640,7 @@ static char *print_number(char *buf,
i
=
0
;
i
=
0
;
if
(
num
==
0
)
if
(
num
==
0
)
tmp
[
i
++
]
=
'0'
;
tmp
[
i
++
]
=
'0'
;
else
else
{
{
while
(
num
!=
0
)
while
(
num
!=
0
)
...
@@ -655,12 +655,12 @@ static char *print_number(char *buf,
...
@@ -655,12 +655,12 @@ static char *print_number(char *buf,
size
-=
i
;
size
-=
i
;
#endif
#endif
if
(
!
(
type
&
(
ZEROPAD
|
LEFT
)))
if
(
!
(
type
&
(
ZEROPAD
|
LEFT
)))
{
{
if
((
sign
)
&&
(
size
>
0
))
if
((
sign
)
&&
(
size
>
0
))
size
--
;
size
--
;
while
(
size
--
>
0
)
while
(
size
--
>
0
)
{
{
if
(
buf
<=
end
)
if
(
buf
<=
end
)
*
buf
=
' '
;
*
buf
=
' '
;
...
@@ -681,7 +681,7 @@ static char *print_number(char *buf,
...
@@ -681,7 +681,7 @@ static char *print_number(char *buf,
#ifdef RT_PRINTF_SPECIAL
#ifdef RT_PRINTF_SPECIAL
if
(
type
&
SPECIAL
)
if
(
type
&
SPECIAL
)
{
{
if
(
base
==
8
)
if
(
base
==
8
)
{
{
if
(
buf
<=
end
)
if
(
buf
<=
end
)
*
buf
=
'0'
;
*
buf
=
'0'
;
...
@@ -694,7 +694,7 @@ static char *print_number(char *buf,
...
@@ -694,7 +694,7 @@ static char *print_number(char *buf,
++
buf
;
++
buf
;
if
(
buf
<=
end
)
if
(
buf
<=
end
)
{
{
*
buf
=
type
&
LARGE
?
'X'
:
'x'
;
*
buf
=
type
&
LARGE
?
'X'
:
'x'
;
}
}
++
buf
;
++
buf
;
}
}
...
@@ -768,7 +768,7 @@ rt_int32_t rt_vsnprintf(char *buf,
...
@@ -768,7 +768,7 @@ rt_int32_t rt_vsnprintf(char *buf,
/* Make sure end is always >= buf */
/* Make sure end is always >= buf */
if
(
end
<
buf
)
if
(
end
<
buf
)
{
{
end
=
((
char
*
)
-
1
);
end
=
((
char
*
)
-
1
);
size
=
end
-
buf
;
size
=
end
-
buf
;
}
}
...
@@ -929,7 +929,7 @@ rt_int32_t rt_vsnprintf(char *buf,
...
@@ -929,7 +929,7 @@ rt_int32_t rt_vsnprintf(char *buf,
++
str
;
++
str
;
continue
;
continue
;
/* integer number formats - set up the flags and "break" */
/* integer number formats - set up the flags and "break" */
case
'o'
:
case
'o'
:
base
=
8
;
base
=
8
;
break
;
break
;
...
@@ -1028,7 +1028,7 @@ RTM_EXPORT(rt_snprintf);
...
@@ -1028,7 +1028,7 @@ RTM_EXPORT(rt_snprintf);
*/
*/
rt_int32_t
rt_vsprintf
(
char
*
buf
,
const
char
*
format
,
va_list
arg_ptr
)
rt_int32_t
rt_vsprintf
(
char
*
buf
,
const
char
*
format
,
va_list
arg_ptr
)
{
{
return
rt_vsnprintf
(
buf
,
(
rt_size_t
)
-
1
,
format
,
arg_ptr
);
return
rt_vsnprintf
(
buf
,
(
rt_size_t
)
-
1
,
format
,
arg_ptr
);
}
}
RTM_EXPORT
(
rt_vsprintf
);
RTM_EXPORT
(
rt_vsprintf
);
...
@@ -1044,7 +1044,7 @@ rt_int32_t rt_sprintf(char *buf, const char *format, ...)
...
@@ -1044,7 +1044,7 @@ rt_int32_t rt_sprintf(char *buf, const char *format, ...)
va_list
arg_ptr
;
va_list
arg_ptr
;
va_start
(
arg_ptr
,
format
);
va_start
(
arg_ptr
,
format
);
n
=
rt_vsprintf
(
buf
,
format
,
arg_ptr
);
n
=
rt_vsprintf
(
buf
,
format
,
arg_ptr
);
va_end
(
arg_ptr
);
va_end
(
arg_ptr
);
return
n
;
return
n
;
...
@@ -1183,7 +1183,7 @@ RTM_EXPORT(rt_kprintf);
...
@@ -1183,7 +1183,7 @@ RTM_EXPORT(rt_kprintf);
*
*
* @return the allocated memory block on successful, otherwise returns RT_NULL
* @return the allocated memory block on successful, otherwise returns RT_NULL
*/
*/
void
*
rt_malloc_align
(
rt_size_t
size
,
rt_size_t
align
)
void
*
rt_malloc_align
(
rt_size_t
size
,
rt_size_t
align
)
{
{
void
*
align_ptr
;
void
*
align_ptr
;
void
*
ptr
;
void
*
ptr
;
...
@@ -1198,7 +1198,7 @@ void* rt_malloc_align(rt_size_t size, rt_size_t align)
...
@@ -1198,7 +1198,7 @@ void* rt_malloc_align(rt_size_t size, rt_size_t align)
ptr
=
rt_malloc
(
align_size
);
ptr
=
rt_malloc
(
align_size
);
if
(
ptr
!=
RT_NULL
)
if
(
ptr
!=
RT_NULL
)
{
{
/* the allocated memory block is aligned */
/* the allocated memory block is aligned */
if
(((
rt_uint32_t
)
ptr
&
(
align
-
1
))
==
0
)
if
(((
rt_uint32_t
)
ptr
&
(
align
-
1
))
==
0
)
{
{
align_ptr
=
(
void
*
)((
rt_uint32_t
)
ptr
+
align
);
align_ptr
=
(
void
*
)((
rt_uint32_t
)
ptr
+
align
);
...
@@ -1228,7 +1228,7 @@ void rt_free_align(void *ptr)
...
@@ -1228,7 +1228,7 @@ void rt_free_align(void *ptr)
{
{
void
*
real_ptr
;
void
*
real_ptr
;
real_ptr
=
(
void
*
)
*
(
rt_uint32_t
*
)((
rt_uint32_t
)
ptr
-
sizeof
(
void
*
));
real_ptr
=
(
void
*
)
*
(
rt_uint32_t
*
)((
rt_uint32_t
)
ptr
-
sizeof
(
void
*
));
rt_free
(
real_ptr
);
rt_free
(
real_ptr
);
}
}
RTM_EXPORT
(
rt_free_align
);
RTM_EXPORT
(
rt_free_align
);
...
@@ -1284,13 +1284,14 @@ rt_ubase_t __rt_ffs(rt_ubase_t value)
...
@@ -1284,13 +1284,14 @@ rt_ubase_t __rt_ffs(rt_ubase_t value)
#ifdef RT_DEBUG
#ifdef RT_DEBUG
/* RT_ASSERT(EX)'s hook */
/* RT_ASSERT(EX)'s hook */
void
(
*
rt_assert_hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
);
void
(
*
rt_assert_hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
);
/**
/**
* This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false.
* This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false.
*
*
* @param hook the hook function
* @param hook the hook function
*/
*/
void
rt_assert_set_hook
(
void
(
*
hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
))
{
void
rt_assert_set_hook
(
void
(
*
hook
)(
const
char
*
ex
,
const
char
*
func
,
rt_size_t
line
))
{
rt_assert_hook
=
hook
;
rt_assert_hook
=
hook
;
}
}
...
@@ -1301,30 +1302,30 @@ void rt_assert_set_hook(void (*hook)(const char* ex, const char* func, rt_size_t
...
@@ -1301,30 +1302,30 @@ void rt_assert_set_hook(void (*hook)(const char* ex, const char* func, rt_size_t
* @param func the function name when assertion.
* @param func the function name when assertion.
* @param line the file line number when assertion.
* @param line the file line number when assertion.
*/
*/
void
rt_assert_handler
(
const
char
*
ex_string
,
const
char
*
func
,
rt_size_t
line
)
void
rt_assert_handler
(
const
char
*
ex_string
,
const
char
*
func
,
rt_size_t
line
)
{
{
volatile
char
dummy
=
0
;
volatile
char
dummy
=
0
;
if
(
rt_assert_hook
==
RT_NULL
)
if
(
rt_assert_hook
==
RT_NULL
)
{
{
#ifdef RT_USING_MODULE
#ifdef RT_USING_MODULE
if
(
rt_module_self
()
!=
RT_NULL
)
if
(
rt_module_self
()
!=
RT_NULL
)
{
{
/* unload assertion module */
/* unload assertion module */
rt_module_unload
(
rt_module_self
());
rt_module_unload
(
rt_module_self
());
/* re-schedule */
/* re-schedule */
rt_schedule
();
rt_schedule
();
}
}
else
else
#endif
#endif
{
{
rt_kprintf
(
"(%s) assertion failed at function:%s, line number:%d
\n
"
,
ex_string
,
func
,
line
);
rt_kprintf
(
"(%s) assertion failed at function:%s, line number:%d
\n
"
,
ex_string
,
func
,
line
);
while
(
dummy
==
0
);
while
(
dummy
==
0
);
}
}
}
}
else
else
{
{
rt_assert_hook
(
ex_string
,
func
,
line
);
rt_assert_hook
(
ex_string
,
func
,
line
);
}
}
}
}
...
@@ -1339,7 +1340,7 @@ void *memmove(void *dest, const void *src, size_t n) __attribute__((weak, alias(
...
@@ -1339,7 +1340,7 @@ void *memmove(void *dest, const void *src, size_t n) __attribute__((weak, alias(
int
memcmp
(
const
void
*
s1
,
const
void
*
s2
,
size_t
n
)
__attribute__
((
weak
,
alias
(
"rt_memcmp"
)));
int
memcmp
(
const
void
*
s1
,
const
void
*
s2
,
size_t
n
)
__attribute__
((
weak
,
alias
(
"rt_memcmp"
)));
size_t
strlen
(
const
char
*
s
)
__attribute__
((
weak
,
alias
(
"rt_strlen"
)));
size_t
strlen
(
const
char
*
s
)
__attribute__
((
weak
,
alias
(
"rt_strlen"
)));
char
*
strstr
(
const
char
*
s1
,
const
char
*
s2
)
__attribute__
((
weak
,
alias
(
"rt_strstr"
)));
char
*
strstr
(
const
char
*
s1
,
const
char
*
s2
)
__attribute__
((
weak
,
alias
(
"rt_strstr"
)));
int
strcasecmp
(
const
char
*
a
,
const
char
*
b
)
__attribute__
((
weak
,
alias
(
"rt_strcasecmp"
)));
int
strcasecmp
(
const
char
*
a
,
const
char
*
b
)
__attribute__
((
weak
,
alias
(
"rt_strcasecmp"
)));
char
*
strncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
)
__attribute__
((
weak
,
alias
(
"rt_strncpy"
)));
char
*
strncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
)
__attribute__
((
weak
,
alias
(
"rt_strncpy"
)));
int
strncmp
(
const
char
*
cs
,
const
char
*
ct
,
size_t
count
)
__attribute__
((
weak
,
alias
(
"rt_strncmp"
)));
int
strncmp
(
const
char
*
cs
,
const
char
*
ct
,
size_t
count
)
__attribute__
((
weak
,
alias
(
"rt_strncmp"
)));
...
...
src/mem.c
浏览文件 @
2aae989f
...
@@ -335,7 +335,7 @@ void *rt_malloc(rt_size_t size)
...
@@ -335,7 +335,7 @@ void *rt_malloc(rt_size_t size)
*/
*/
mem
->
used
=
1
;
mem
->
used
=
1
;
#ifdef RT_MEM_STATS
#ifdef RT_MEM_STATS
used_mem
+=
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
);
used_mem
+=
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
);
if
(
max_mem
<
used_mem
)
if
(
max_mem
<
used_mem
)
max_mem
=
used_mem
;
max_mem
=
used_mem
;
#endif
#endif
...
@@ -355,7 +355,7 @@ void *rt_malloc(rt_size_t size)
...
@@ -355,7 +355,7 @@ void *rt_malloc(rt_size_t size)
rt_sem_release
(
&
heap_sem
);
rt_sem_release
(
&
heap_sem
);
RT_ASSERT
((
rt_uint32_t
)
mem
+
SIZEOF_STRUCT_MEM
+
size
<=
(
rt_uint32_t
)
heap_end
);
RT_ASSERT
((
rt_uint32_t
)
mem
+
SIZEOF_STRUCT_MEM
+
size
<=
(
rt_uint32_t
)
heap_end
);
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
);
RT_DEBUG_LOG
(
RT_DEBUG_MEM
,
RT_DEBUG_LOG
(
RT_DEBUG_MEM
,
(
"allocate memory at 0x%x, size: %d
\n
"
,
(
"allocate memory at 0x%x, size: %d
\n
"
,
...
@@ -443,7 +443,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
...
@@ -443,7 +443,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
ptr2
=
ptr
+
SIZEOF_STRUCT_MEM
+
newsize
;
ptr2
=
ptr
+
SIZEOF_STRUCT_MEM
+
newsize
;
mem2
=
(
struct
heap_mem
*
)
&
heap_ptr
[
ptr2
];
mem2
=
(
struct
heap_mem
*
)
&
heap_ptr
[
ptr2
];
mem2
->
magic
=
HEAP_MAGIC
;
mem2
->
magic
=
HEAP_MAGIC
;
mem2
->
used
=
0
;
mem2
->
used
=
0
;
mem2
->
next
=
mem
->
next
;
mem2
->
next
=
mem
->
next
;
mem2
->
prev
=
ptr
;
mem2
->
prev
=
ptr
;
...
@@ -516,7 +516,7 @@ void rt_free(void *rmem)
...
@@ -516,7 +516,7 @@ void rt_free(void *rmem)
if
(
rmem
==
RT_NULL
)
if
(
rmem
==
RT_NULL
)
return
;
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
);
...
@@ -556,7 +556,7 @@ void rt_free(void *rmem)
...
@@ -556,7 +556,7 @@ void rt_free(void *rmem)
}
}
#ifdef RT_MEM_STATS
#ifdef RT_MEM_STATS
used_mem
-=
(
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
));
used_mem
-=
(
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
));
#endif
#endif
/* finally, see if prev or next are free also */
/* finally, see if prev or next are free also */
...
...
src/memheap.c
浏览文件 @
2aae989f
...
@@ -96,7 +96,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
...
@@ -96,7 +96,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
item
->
prev_free
=
item
;
item
->
prev_free
=
item
;
item
->
next
=
(
struct
rt_memheap_item
*
)
item
->
next
=
(
struct
rt_memheap_item
*
)
((
rt_uint8_t
*
)
item
+
memheap
->
available_size
+
RT_MEMHEAP_SIZE
);
((
rt_uint8_t
*
)
item
+
memheap
->
available_size
+
RT_MEMHEAP_SIZE
);
item
->
prev
=
item
->
next
;
item
->
prev
=
item
->
next
;
/* block list header */
/* block list header */
...
@@ -315,10 +315,10 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
...
@@ -315,10 +315,10 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
header_ptr
=
(
struct
rt_memheap_item
*
)
header_ptr
=
(
struct
rt_memheap_item
*
)
((
rt_uint8_t
*
)
ptr
-
RT_MEMHEAP_SIZE
);
((
rt_uint8_t
*
)
ptr
-
RT_MEMHEAP_SIZE
);
oldsize
=
MEMITEM_SIZE
(
header_ptr
);
oldsize
=
MEMITEM_SIZE
(
header_ptr
);
/* re-allocate memory */
/* re-allocate memory */
if
(
newsize
>
oldsize
)
if
(
newsize
>
oldsize
)
{
{
void
*
new_ptr
;
void
*
new_ptr
;
struct
rt_memheap_item
*
next_ptr
;
struct
rt_memheap_item
*
next_ptr
;
/* lock memheap */
/* lock memheap */
...
@@ -371,7 +371,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
...
@@ -371,7 +371,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
next_ptr
->
prev
->
next
=
next_ptr
->
next
;
next_ptr
->
prev
->
next
=
next_ptr
->
next
;
/* build a new one on the right place */
/* build a new one on the right place */
next_ptr
=
(
struct
rt_memheap_item
*
)((
char
*
)
ptr
+
newsize
);
next_ptr
=
(
struct
rt_memheap_item
*
)((
char
*
)
ptr
+
newsize
);
RT_DEBUG_LOG
(
RT_DEBUG_MEMHEAP
,
RT_DEBUG_LOG
(
RT_DEBUG_MEMHEAP
,
(
"new free block: block[0x%08x] nextm[0x%08x] prevm[0x%08x]"
,
(
"new free block: block[0x%08x] nextm[0x%08x] prevm[0x%08x]"
,
...
@@ -410,7 +410,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
...
@@ -410,7 +410,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
rt_sem_release
(
&
(
heap
->
lock
));
rt_sem_release
(
&
(
heap
->
lock
));
/* re-allocate a memory block */
/* re-allocate a memory block */
new_ptr
=
(
void
*
)
rt_memheap_alloc
(
heap
,
newsize
);
new_ptr
=
(
void
*
)
rt_memheap_alloc
(
heap
,
newsize
);
if
(
new_ptr
!=
RT_NULL
)
if
(
new_ptr
!=
RT_NULL
)
{
{
rt_memcpy
(
new_ptr
,
ptr
,
oldsize
<
newsize
?
oldsize
:
newsize
);
rt_memcpy
(
new_ptr
,
ptr
,
oldsize
<
newsize
?
oldsize
:
newsize
);
...
@@ -503,8 +503,8 @@ void rt_memheap_free(void *ptr)
...
@@ -503,8 +503,8 @@ void rt_memheap_free(void *ptr)
struct
rt_memheap_item
*
header_ptr
,
*
new_ptr
;
struct
rt_memheap_item
*
header_ptr
,
*
new_ptr
;
rt_uint32_t
insert_header
;
rt_uint32_t
insert_header
;
/* NULL check */
/* NULL check */
if
(
ptr
==
RT_NULL
)
return
;
if
(
ptr
==
RT_NULL
)
return
;
/* set initial status as OK */
/* set initial status as OK */
insert_header
=
1
;
insert_header
=
1
;
...
@@ -610,7 +610,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -610,7 +610,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
void
*
rt_malloc
(
rt_size_t
size
)
void
*
rt_malloc
(
rt_size_t
size
)
{
{
void
*
ptr
;
void
*
ptr
;
/* try to allocate in system heap */
/* try to allocate in system heap */
ptr
=
rt_memheap_alloc
(
&
_heap
,
size
);
ptr
=
rt_memheap_alloc
(
&
_heap
,
size
);
...
...
src/mempool.c
浏览文件 @
2aae989f
...
@@ -299,8 +299,8 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
...
@@ -299,8 +299,8 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
else
else
#endif
#endif
/* release allocated room */
/* release allocated room */
rt_free
(
mp
->
start_address
);
rt_free
(
mp
->
start_address
);
/* detach object */
/* detach object */
rt_object_delete
(
&
(
mp
->
parent
));
rt_object_delete
(
&
(
mp
->
parent
));
...
...
src/module.c
浏览文件 @
2aae989f
...
@@ -138,7 +138,7 @@ void list_symbol(void)
...
@@ -138,7 +138,7 @@ void list_symbol(void)
index
!=
_rt_module_symtab_end
;
index
!=
_rt_module_symtab_end
;
index
++
)
index
++
)
{
{
rt_kprintf
(
"%s
\n
"
,
index
->
name
);
rt_kprintf
(
"%s
\n
"
,
index
->
name
);
}
}
return
;
return
;
...
@@ -259,10 +259,10 @@ static int rt_module_arm_relocate(struct rt_module *module,
...
@@ -259,10 +259,10 @@ static int rt_module_arm_relocate(struct rt_module *module,
j1
=
(
lower
>>
13
)
&
1
;
j1
=
(
lower
>>
13
)
&
1
;
j2
=
(
lower
>>
11
)
&
1
;
j2
=
(
lower
>>
11
)
&
1
;
offset
=
(
sign
<<
24
)
|
offset
=
(
sign
<<
24
)
|
((
~
(
j1
^
sign
)
&
1
)
<<
23
)
|
((
~
(
j1
^
sign
)
&
1
)
<<
23
)
|
((
~
(
j2
^
sign
)
&
1
)
<<
22
)
|
((
~
(
j2
^
sign
)
&
1
)
<<
22
)
|
((
upper
&
0x03ff
)
<<
12
)
|
((
upper
&
0x03ff
)
<<
12
)
|
((
lower
&
0x07ff
)
<<
1
);
((
lower
&
0x07ff
)
<<
1
);
if
(
offset
&
0x01000000
)
if
(
offset
&
0x01000000
)
offset
-=
0x02000000
;
offset
-=
0x02000000
;
offset
+=
sym_val
-
(
Elf32_Addr
)
where
;
offset
+=
sym_val
-
(
Elf32_Addr
)
where
;
...
@@ -517,7 +517,7 @@ static struct rt_module *_load_shared_object(const char *name,
...
@@ -517,7 +517,7 @@ static struct rt_module *_load_shared_object(const char *name,
/* set module entry */
/* set module entry */
module
->
module_entry
=
module
->
module_space
module
->
module_entry
=
module
->
module_space
+
elf_module
->
e_entry
-
vstart_addr
;
+
elf_module
->
e_entry
-
vstart_addr
;
/* handle relocation section */
/* handle relocation section */
for
(
index
=
0
;
index
<
elf_module
->
e_shnum
;
index
++
)
for
(
index
=
0
;
index
<
elf_module
->
e_shnum
;
index
++
)
...
@@ -538,7 +538,7 @@ static struct rt_module *_load_shared_object(const char *name,
...
@@ -538,7 +538,7 @@ static struct rt_module *_load_shared_object(const char *name,
symtab
=
(
Elf32_Sym
*
)((
rt_uint8_t
*
)
module_ptr
+
symtab
=
(
Elf32_Sym
*
)((
rt_uint8_t
*
)
module_ptr
+
shdr
[
shdr
[
index
].
sh_link
].
sh_offset
);
shdr
[
shdr
[
index
].
sh_link
].
sh_offset
);
strtab
=
(
rt_uint8_t
*
)
module_ptr
+
strtab
=
(
rt_uint8_t
*
)
module_ptr
+
shdr
[
shdr
[
shdr
[
index
].
sh_link
].
sh_link
].
sh_offset
;
shdr
[
shdr
[
shdr
[
index
].
sh_link
].
sh_link
].
sh_offset
;
nr_reloc
=
(
rt_uint32_t
)(
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Rel
));
nr_reloc
=
(
rt_uint32_t
)(
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Rel
));
/* relocate every items */
/* relocate every items */
...
@@ -555,7 +555,7 @@ static struct rt_module *_load_shared_object(const char *name,
...
@@ -555,7 +555,7 @@ static struct rt_module *_load_shared_object(const char *name,
#ifdef MODULE_USING_386
#ifdef MODULE_USING_386
||
(
(
ELF_ST_BIND
(
sym
->
st_info
)
==
STB_GLOBAL
)
&&
(
ELF_ST_TYPE
(
sym
->
st_info
)
==
STT_OBJECT
)
)
||
(
(
ELF_ST_BIND
(
sym
->
st_info
)
==
STB_GLOBAL
)
&&
(
ELF_ST_TYPE
(
sym
->
st_info
)
==
STT_OBJECT
)
)
#endif
#endif
)
)
{
{
rt_module_arm_relocate
(
module
,
rel
,
rt_module_arm_relocate
(
module
,
rel
,
(
Elf32_Addr
)(
module
->
module_space
(
Elf32_Addr
)(
module
->
module_space
...
@@ -597,7 +597,7 @@ static struct rt_module *_load_shared_object(const char *name,
...
@@ -597,7 +597,7 @@ static struct rt_module *_load_shared_object(const char *name,
/* find .dynsym section */
/* find .dynsym section */
rt_uint8_t
*
shstrab
;
rt_uint8_t
*
shstrab
;
shstrab
=
(
rt_uint8_t
*
)
module_ptr
+
shstrab
=
(
rt_uint8_t
*
)
module_ptr
+
shdr
[
elf_module
->
e_shstrndx
].
sh_offset
;
shdr
[
elf_module
->
e_shstrndx
].
sh_offset
;
if
(
rt_strcmp
((
const
char
*
)(
shstrab
+
shdr
[
index
].
sh_name
),
ELF_DYNSYM
)
==
0
)
if
(
rt_strcmp
((
const
char
*
)(
shstrab
+
shdr
[
index
].
sh_name
),
ELF_DYNSYM
)
==
0
)
break
;
break
;
}
}
...
@@ -609,10 +609,10 @@ static struct rt_module *_load_shared_object(const char *name,
...
@@ -609,10 +609,10 @@ static struct rt_module *_load_shared_object(const char *name,
Elf32_Sym
*
symtab
=
RT_NULL
;
Elf32_Sym
*
symtab
=
RT_NULL
;
rt_uint8_t
*
strtab
=
RT_NULL
;
rt_uint8_t
*
strtab
=
RT_NULL
;
symtab
=
(
Elf32_Sym
*
)((
rt_uint8_t
*
)
module_ptr
+
shdr
[
index
].
sh_offset
);
symtab
=
(
Elf32_Sym
*
)((
rt_uint8_t
*
)
module_ptr
+
shdr
[
index
].
sh_offset
);
strtab
=
(
rt_uint8_t
*
)
module_ptr
+
shdr
[
shdr
[
index
].
sh_link
].
sh_offset
;
strtab
=
(
rt_uint8_t
*
)
module_ptr
+
shdr
[
shdr
[
index
].
sh_link
].
sh_offset
;
for
(
i
=
0
;
i
<
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Sym
);
i
++
)
for
(
i
=
0
;
i
<
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Sym
);
i
++
)
{
{
if
((
ELF_ST_BIND
(
symtab
[
i
].
st_info
)
==
STB_GLOBAL
)
&&
if
((
ELF_ST_BIND
(
symtab
[
i
].
st_info
)
==
STB_GLOBAL
)
&&
(
ELF_ST_TYPE
(
symtab
[
i
].
st_info
)
==
STT_FUNC
))
(
ELF_ST_TYPE
(
symtab
[
i
].
st_info
)
==
STT_FUNC
))
...
@@ -620,9 +620,9 @@ static struct rt_module *_load_shared_object(const char *name,
...
@@ -620,9 +620,9 @@ static struct rt_module *_load_shared_object(const char *name,
}
}
module
->
symtab
=
(
struct
rt_module_symtab
*
)
rt_malloc
module
->
symtab
=
(
struct
rt_module_symtab
*
)
rt_malloc
(
count
*
sizeof
(
struct
rt_module_symtab
));
(
count
*
sizeof
(
struct
rt_module_symtab
));
module
->
nsym
=
count
;
module
->
nsym
=
count
;
for
(
i
=
0
,
count
=
0
;
i
<
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Sym
);
i
++
)
for
(
i
=
0
,
count
=
0
;
i
<
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Sym
);
i
++
)
{
{
rt_size_t
length
;
rt_size_t
length
;
...
@@ -686,7 +686,7 @@ static struct rt_module* _load_relocated_object(const char *name,
...
@@ -686,7 +686,7 @@ static struct rt_module* _load_relocated_object(const char *name,
/* allocate module */
/* allocate module */
module
=
(
struct
rt_module
*
)
module
=
(
struct
rt_module
*
)
rt_object_allocate
(
RT_Object_Class_Module
,
(
const
char
*
)
name
);
rt_object_allocate
(
RT_Object_Class_Module
,
(
const
char
*
)
name
);
if
(
module
==
RT_NULL
)
if
(
module
==
RT_NULL
)
return
RT_NULL
;
return
RT_NULL
;
...
@@ -777,9 +777,9 @@ static struct rt_module* _load_relocated_object(const char *name,
...
@@ -777,9 +777,9 @@ static struct rt_module* _load_relocated_object(const char *name,
symtab
=
(
Elf32_Sym
*
)((
rt_uint8_t
*
)
module_ptr
+
symtab
=
(
Elf32_Sym
*
)((
rt_uint8_t
*
)
module_ptr
+
shdr
[
shdr
[
index
].
sh_link
].
sh_offset
);
shdr
[
shdr
[
index
].
sh_link
].
sh_offset
);
strtab
=
(
rt_uint8_t
*
)
module_ptr
+
strtab
=
(
rt_uint8_t
*
)
module_ptr
+
shdr
[
shdr
[
shdr
[
index
].
sh_link
].
sh_link
].
sh_offset
;
shdr
[
shdr
[
shdr
[
index
].
sh_link
].
sh_link
].
sh_offset
;
shstrab
=
(
rt_uint8_t
*
)
module_ptr
+
shstrab
=
(
rt_uint8_t
*
)
module_ptr
+
shdr
[
elf_module
->
e_shstrndx
].
sh_offset
;
shdr
[
elf_module
->
e_shstrndx
].
sh_offset
;
nr_reloc
=
(
rt_uint32_t
)(
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Rel
));
nr_reloc
=
(
rt_uint32_t
)(
shdr
[
index
].
sh_size
/
sizeof
(
Elf32_Rel
));
/* relocate every items */
/* relocate every items */
...
@@ -803,7 +803,7 @@ static struct rt_module* _load_relocated_object(const char *name,
...
@@ -803,7 +803,7 @@ static struct rt_module* _load_relocated_object(const char *name,
rt_module_arm_relocate
(
module
,
rel
,
rt_module_arm_relocate
(
module
,
rel
,
(
Elf32_Addr
)(
rodata_addr
+
sym
->
st_value
));
(
Elf32_Addr
)(
rodata_addr
+
sym
->
st_value
));
}
}
else
if
(
rt_strncmp
((
const
char
*
)
else
if
(
rt_strncmp
((
const
char
*
)
(
shstrab
+
shdr
[
sym
->
st_shndx
].
sh_name
),
ELF_BSS
,
5
)
==
0
)
(
shstrab
+
shdr
[
sym
->
st_shndx
].
sh_name
),
ELF_BSS
,
5
)
==
0
)
{
{
/* relocate bss section */
/* relocate bss section */
...
@@ -854,7 +854,7 @@ static struct rt_module* _load_relocated_object(const char *name,
...
@@ -854,7 +854,7 @@ static struct rt_module* _load_relocated_object(const char *name,
else
else
{
{
rt_module_arm_relocate
(
module
,
rel
,
rt_module_arm_relocate
(
module
,
rel
,
(
Elf32_Addr
)((
rt_uint8_t
*
)
(
Elf32_Addr
)((
rt_uint8_t
*
)
module
->
module_space
module
->
module_space
-
module_addr
-
module_addr
+
sym
->
st_value
));
+
sym
->
st_value
));
...
@@ -868,7 +868,7 @@ static struct rt_module* _load_relocated_object(const char *name,
...
@@ -868,7 +868,7 @@ static struct rt_module* _load_relocated_object(const char *name,
}
}
#define RT_MODULE_ARG_MAX 8
#define RT_MODULE_ARG_MAX 8
static
int
_rt_module_split_arg
(
char
*
cmd
,
rt_size_t
length
,
char
*
argv
[])
static
int
_rt_module_split_arg
(
char
*
cmd
,
rt_size_t
length
,
char
*
argv
[])
{
{
int
argc
=
0
;
int
argc
=
0
;
char
*
ptr
=
cmd
;
char
*
ptr
=
cmd
;
...
@@ -876,10 +876,10 @@ static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
...
@@ -876,10 +876,10 @@ static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
while
((
ptr
-
cmd
)
<
length
)
while
((
ptr
-
cmd
)
<
length
)
{
{
/* strip bank and tab */
/* strip bank and tab */
while
((
*
ptr
==
' '
||
*
ptr
==
'\t'
)
&&
(
ptr
-
cmd
)
<
length
)
while
((
*
ptr
==
' '
||
*
ptr
==
'\t'
)
&&
(
ptr
-
cmd
)
<
length
)
*
ptr
++
=
'\0'
;
*
ptr
++
=
'\0'
;
/* check whether it's the end of line */
/* check whether it's the end of line */
if
((
ptr
-
cmd
)
>=
length
)
break
;
if
((
ptr
-
cmd
)
>=
length
)
break
;
/* handle string with quote */
/* handle string with quote */
if
(
*
ptr
==
'"'
)
if
(
*
ptr
==
'"'
)
...
@@ -887,7 +887,7 @@ static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
...
@@ -887,7 +887,7 @@ static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
argv
[
argc
++
]
=
++
ptr
;
argv
[
argc
++
]
=
++
ptr
;
/* skip this string */
/* skip this string */
while
(
*
ptr
!=
'"'
&&
(
ptr
-
cmd
)
<
length
)
while
(
*
ptr
!=
'"'
&&
(
ptr
-
cmd
)
<
length
)
if
(
*
ptr
++
==
'\\'
)
ptr
++
;
if
(
*
ptr
++
==
'\\'
)
ptr
++
;
if
((
ptr
-
cmd
)
>=
length
)
break
;
if
((
ptr
-
cmd
)
>=
length
)
break
;
...
@@ -908,11 +908,11 @@ static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
...
@@ -908,11 +908,11 @@ static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
}
}
/* module main thread entry */
/* module main thread entry */
static
void
module_main_entry
(
void
*
parameter
)
static
void
module_main_entry
(
void
*
parameter
)
{
{
int
argc
;
int
argc
;
char
*
argv
[
RT_MODULE_ARG_MAX
];
char
*
argv
[
RT_MODULE_ARG_MAX
];
typedef
int
(
*
main_func_t
)(
int
argc
,
char
**
argv
);
typedef
int
(
*
main_func_t
)(
int
argc
,
char
**
argv
);
rt_module_t
module
=
(
rt_module_t
)
parameter
;
rt_module_t
module
=
(
rt_module_t
)
parameter
;
if
(
module
==
RT_NULL
)
if
(
module
==
RT_NULL
)
...
@@ -934,7 +934,7 @@ static void module_main_entry(void* parameter)
...
@@ -934,7 +934,7 @@ static void module_main_entry(void* parameter)
}
}
rt_memset
(
argv
,
0x00
,
sizeof
(
argv
));
rt_memset
(
argv
,
0x00
,
sizeof
(
argv
));
argc
=
_rt_module_split_arg
((
char
*
)
module
->
module_cmd_line
,
argc
=
_rt_module_split_arg
((
char
*
)
module
->
module_cmd_line
,
module
->
module_cmd_size
,
argv
);
module
->
module_cmd_size
,
argv
);
if
(
argc
==
0
)
if
(
argc
==
0
)
return
;
return
;
...
@@ -948,19 +948,19 @@ static void module_main_entry(void* parameter)
...
@@ -948,19 +948,19 @@ static void module_main_entry(void* parameter)
}
}
/**
/**
* This function will load a module with a main function from memory and create a
* This function will load a module with a main function from memory and create a
* main thread for it
* main thread for it
*
*
* @param name the name of module, which shall be unique
* @param name the name of module, which shall be unique
* @param module_ptr the memory address of module image
* @param module_ptr the memory address of module image
* @argc the count of argument
* @argc the count of argument
* @argd the argument data, which should be a
* @argd the argument data, which should be a
*
*
* @return the module object
* @return the module object
*/
*/
rt_module_t
rt_module_do_main
(
const
char
*
name
,
rt_module_t
rt_module_do_main
(
const
char
*
name
,
void
*
module_ptr
,
void
*
module_ptr
,
const
char
*
cmd_line
,
const
char
*
cmd_line
,
int
line_size
)
int
line_size
)
{
{
rt_module_t
module
;
rt_module_t
module
;
...
@@ -1010,7 +1010,7 @@ rt_module_t rt_module_do_main(const char *name,
...
@@ -1010,7 +1010,7 @@ rt_module_t rt_module_do_main(const char *name,
if
(
line_size
&&
cmd_line
)
if
(
line_size
&&
cmd_line
)
{
{
/* set module argument */
/* set module argument */
module
->
module_cmd_line
=
(
rt_uint8_t
*
)
rt_malloc
(
line_size
+
1
);
module
->
module_cmd_line
=
(
rt_uint8_t
*
)
rt_malloc
(
line_size
+
1
);
if
(
module
->
module_cmd_line
)
if
(
module
->
module_cmd_line
)
{
{
rt_memcpy
(
module
->
module_cmd_line
,
cmd_line
,
line_size
);
rt_memcpy
(
module
->
module_cmd_line
,
cmd_line
,
line_size
);
...
@@ -1088,7 +1088,7 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
...
@@ -1088,7 +1088,7 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
#ifdef RT_USING_DFS
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#include <dfs_posix.h>
static
char
*
_module_name
(
const
char
*
path
)
static
char
*
_module_name
(
const
char
*
path
)
{
{
const
char
*
first
,
*
end
,
*
ptr
;
const
char
*
first
,
*
end
,
*
ptr
;
char
*
name
;
char
*
name
;
...
@@ -1136,7 +1136,7 @@ rt_module_t rt_module_open(const char *path)
...
@@ -1136,7 +1136,7 @@ rt_module_t rt_module_open(const char *path)
/* check parameters */
/* check parameters */
RT_ASSERT
(
path
!=
RT_NULL
);
RT_ASSERT
(
path
!=
RT_NULL
);
if
(
stat
(
path
,
&
s
)
!=
0
)
if
(
stat
(
path
,
&
s
)
!=
0
)
{
{
rt_kprintf
(
"Module: access %s failed
\n
"
,
path
);
rt_kprintf
(
"Module: access %s failed
\n
"
,
path
);
...
@@ -1197,7 +1197,7 @@ rt_module_t rt_module_open(const char *path)
...
@@ -1197,7 +1197,7 @@ rt_module_t rt_module_open(const char *path)
*
*
* @return the module object
* @return the module object
*/
*/
rt_module_t
rt_module_exec_cmd
(
const
char
*
path
,
const
char
*
cmd_line
,
int
size
)
rt_module_t
rt_module_exec_cmd
(
const
char
*
path
,
const
char
*
cmd_line
,
int
size
)
{
{
struct
stat
s
;
struct
stat
s
;
int
fd
,
length
;
int
fd
,
length
;
...
@@ -1212,7 +1212,7 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int size)
...
@@ -1212,7 +1212,7 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int size)
RT_ASSERT
(
path
!=
RT_NULL
);
RT_ASSERT
(
path
!=
RT_NULL
);
/* get file size */
/* get file size */
if
(
stat
(
path
,
&
s
)
!=
0
)
if
(
stat
(
path
,
&
s
)
!=
0
)
{
{
rt_kprintf
(
"Module: access %s failed
\n
"
,
path
);
rt_kprintf
(
"Module: access %s failed
\n
"
,
path
);
goto
__exit
;
goto
__exit
;
...
@@ -1649,7 +1649,7 @@ static void rt_module_free_page(rt_module_t module,
...
@@ -1649,7 +1649,7 @@ static void rt_module_free_page(rt_module_t module,
}
}
else
if
(
page
[
i
].
npage
==
npages
)
else
if
(
page
[
i
].
npage
==
npages
)
{
{
for
(
index
=
i
;
index
<
module
->
page_cnt
-
1
;
index
++
)
for
(
index
=
i
;
index
<
module
->
page_cnt
-
1
;
index
++
)
{
{
page
[
index
].
page_ptr
=
page
[
index
+
1
].
page_ptr
;
page
[
index
].
page_ptr
=
page
[
index
+
1
].
page_ptr
;
page
[
index
].
npage
=
page
[
index
+
1
].
npage
;
page
[
index
].
npage
=
page
[
index
+
1
].
npage
;
...
@@ -1688,8 +1688,8 @@ void *rt_module_malloc(rt_size_t size)
...
@@ -1688,8 +1688,8 @@ void *rt_module_malloc(rt_size_t size)
RT_DEBUG_NOT_IN_INTERRUPT
;
RT_DEBUG_NOT_IN_INTERRUPT
;
nunits
=
(
size
+
sizeof
(
struct
rt_mem_head
)
-
1
)
/
nunits
=
(
size
+
sizeof
(
struct
rt_mem_head
)
-
1
)
/
sizeof
(
struct
rt_mem_head
)
sizeof
(
struct
rt_mem_head
)
+
1
;
+
1
;
RT_ASSERT
(
size
!=
0
);
RT_ASSERT
(
size
!=
0
);
RT_ASSERT
(
nunits
!=
0
);
RT_ASSERT
(
nunits
!=
0
);
...
@@ -1732,7 +1732,7 @@ void *rt_module_malloc(rt_size_t size)
...
@@ -1732,7 +1732,7 @@ void *rt_module_malloc(rt_size_t size)
/* allocate pages from system heap */
/* allocate pages from system heap */
npage
=
(
size
+
sizeof
(
struct
rt_mem_head
)
+
RT_MM_PAGE_SIZE
-
1
)
/
npage
=
(
size
+
sizeof
(
struct
rt_mem_head
)
+
RT_MM_PAGE_SIZE
-
1
)
/
RT_MM_PAGE_SIZE
;
RT_MM_PAGE_SIZE
;
if
((
up
=
(
struct
rt_mem_head
*
)
rt_module_malloc_page
(
npage
))
==
RT_NULL
)
if
((
up
=
(
struct
rt_mem_head
*
)
rt_module_malloc_page
(
npage
))
==
RT_NULL
)
return
RT_NULL
;
return
RT_NULL
;
...
@@ -1765,7 +1765,7 @@ void rt_module_free(rt_module_t module, void *addr)
...
@@ -1765,7 +1765,7 @@ void rt_module_free(rt_module_t module, void *addr)
RT_DEBUG_NOT_IN_INTERRUPT
;
RT_DEBUG_NOT_IN_INTERRUPT
;
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
);
RT_DEBUG_LOG
(
RT_DEBUG_MODULE
,
(
"rt_module_free 0x%x
\n
"
,
addr
));
RT_DEBUG_LOG
(
RT_DEBUG_MODULE
,
(
"rt_module_free 0x%x
\n
"
,
addr
));
...
@@ -1798,8 +1798,8 @@ void rt_module_free(rt_module_t module, void *addr)
...
@@ -1798,8 +1798,8 @@ void rt_module_free(rt_module_t module, void *addr)
if
((
b
->
size
*
sizeof
(
struct
rt_page_info
)
%
RT_MM_PAGE_SIZE
)
!=
0
)
if
((
b
->
size
*
sizeof
(
struct
rt_page_info
)
%
RT_MM_PAGE_SIZE
)
!=
0
)
{
{
rt_size_t
nunits
=
npage
*
rt_size_t
nunits
=
npage
*
RT_MM_PAGE_SIZE
/
RT_MM_PAGE_SIZE
/
sizeof
(
struct
rt_mem_head
);
sizeof
(
struct
rt_mem_head
);
/* split memory */
/* split memory */
r
=
b
+
nunits
;
r
=
b
+
nunits
;
r
->
next
=
b
->
next
;
r
->
next
=
b
->
next
;
...
@@ -1835,8 +1835,8 @@ void rt_module_free(rt_module_t module, void *addr)
...
@@ -1835,8 +1835,8 @@ void rt_module_free(rt_module_t module, void *addr)
if
((
n
->
size
*
sizeof
(
struct
rt_page_info
)
%
RT_MM_PAGE_SIZE
)
!=
0
)
if
((
n
->
size
*
sizeof
(
struct
rt_page_info
)
%
RT_MM_PAGE_SIZE
)
!=
0
)
{
{
rt_size_t
nunits
=
npage
*
rt_size_t
nunits
=
npage
*
RT_MM_PAGE_SIZE
/
RT_MM_PAGE_SIZE
/
sizeof
(
struct
rt_mem_head
);
sizeof
(
struct
rt_mem_head
);
/* split memory */
/* split memory */
r
=
n
+
nunits
;
r
=
n
+
nunits
;
r
->
next
=
n
->
next
;
r
->
next
=
n
->
next
;
...
@@ -1921,8 +1921,8 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
...
@@ -1921,8 +1921,8 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
}
}
nunits
=
(
size
+
sizeof
(
struct
rt_mem_head
)
-
1
)
/
nunits
=
(
size
+
sizeof
(
struct
rt_mem_head
)
-
1
)
/
sizeof
(
struct
rt_mem_head
)
sizeof
(
struct
rt_mem_head
)
+
1
;
+
1
;
b
=
(
struct
rt_mem_head
*
)
ptr
-
1
;
b
=
(
struct
rt_mem_head
*
)
ptr
-
1
;
if
(
nunits
<=
b
->
size
)
if
(
nunits
<=
b
->
size
)
...
@@ -1984,7 +1984,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
...
@@ -1984,7 +1984,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
{
{
if
((
p
=
rt_module_malloc
(
size
))
==
RT_NULL
)
if
((
p
=
rt_module_malloc
(
size
))
==
RT_NULL
)
return
RT_NULL
;
return
RT_NULL
;
rt_memmove
(
p
,
(
b
+
1
),
((
b
->
size
)
*
sizeof
(
struct
rt_mem_head
)));
rt_memmove
(
p
,
(
b
+
1
),
((
b
->
size
)
*
sizeof
(
struct
rt_mem_head
)));
rt_module_free
(
self_module
,
(
void
*
)(
b
+
1
));
rt_module_free
(
self_module
,
(
void
*
)(
b
+
1
));
return
(
void
*
)(
p
);
return
(
void
*
)(
p
);
...
...
src/object.c
浏览文件 @
2aae989f
...
@@ -211,7 +211,7 @@ void rt_object_init(struct rt_object *object,
...
@@ -211,7 +211,7 @@ void rt_object_init(struct rt_object *object,
#ifdef RT_USING_MODULE
#ifdef RT_USING_MODULE
/* get module object information */
/* get module object information */
information
=
(
rt_module_self
()
!=
RT_NULL
)
?
information
=
(
rt_module_self
()
!=
RT_NULL
)
?
&
rt_module_self
()
->
module_object
[
type
]
:
&
rt_object_container
[
type
];
&
rt_module_self
()
->
module_object
[
type
]
:
&
rt_object_container
[
type
];
#else
#else
/* get object information */
/* get object information */
information
=
&
rt_object_container
[
type
];
information
=
&
rt_object_container
[
type
];
...
@@ -362,8 +362,8 @@ void rt_object_delete(rt_object_t object)
...
@@ -362,8 +362,8 @@ void rt_object_delete(rt_object_t object)
else
else
#endif
#endif
/* free the memory of object */
/* free the memory of object */
RT_KERNEL_FREE
(
object
);
RT_KERNEL_FREE
(
object
);
}
}
#endif
#endif
...
@@ -424,7 +424,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
...
@@ -424,7 +424,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
if
(
*
name_ptr
==
'/'
)
if
(
*
name_ptr
==
'/'
)
{
{
struct
rt_module
*
module
=
RT_NULL
;
struct
rt_module
*
module
=
RT_NULL
;
/* get the name length of module */
/* get the name length of module */
module_name_length
=
name_ptr
-
name
;
module_name_length
=
name_ptr
-
name
;
...
@@ -435,15 +435,15 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
...
@@ -435,15 +435,15 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
/* find module */
/* find module */
information
=
&
rt_object_container
[
RT_Object_Class_Module
];
information
=
&
rt_object_container
[
RT_Object_Class_Module
];
for
(
node
=
information
->
object_list
.
next
;
for
(
node
=
information
->
object_list
.
next
;
node
!=
&
(
information
->
object_list
);
node
!=
&
(
information
->
object_list
);
node
=
node
->
next
)
node
=
node
->
next
)
{
{
object
=
rt_list_entry
(
node
,
struct
rt_object
,
list
);
object
=
rt_list_entry
(
node
,
struct
rt_object
,
list
);
if
((
rt_strncmp
(
object
->
name
,
name
,
module_name_length
)
==
0
)
&&
if
((
rt_strncmp
(
object
->
name
,
name
,
module_name_length
)
==
0
)
&&
(
module_name_length
==
RT_NAME_MAX
||
object
->
name
[
module_name_length
]
==
'\0'
))
(
module_name_length
==
RT_NAME_MAX
||
object
->
name
[
module_name_length
]
==
'\0'
))
{
{
/* get module */
/* get module */
module
=
(
struct
rt_module
*
)
object
;
module
=
(
struct
rt_module
*
)
object
;
break
;
break
;
}
}
}
}
...
...
src/scheduler.c
浏览文件 @
2aae989f
...
@@ -90,19 +90,19 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
...
@@ -90,19 +90,19 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
RT_ASSERT
(
thread
!=
RT_NULL
);
RT_ASSERT
(
thread
!=
RT_NULL
);
if
(
*
((
rt_uint8_t
*
)
thread
->
stack_addr
)
!=
'#'
||
if
(
*
((
rt_uint8_t
*
)
thread
->
stack_addr
)
!=
'#'
||
(
rt_uint32_t
)
thread
->
sp
<=
(
rt_uint32_t
)
thread
->
stack_addr
||
(
rt_uint32_t
)
thread
->
sp
<=
(
rt_uint32_t
)
thread
->
stack_addr
||
(
rt_uint32_t
)
thread
->
sp
>
(
rt_uint32_t
)
thread
->
sp
>
(
rt_uint32_t
)
thread
->
stack_addr
+
(
rt_uint32_t
)
thread
->
stack_size
)
(
rt_uint32_t
)
thread
->
stack_addr
+
(
rt_uint32_t
)
thread
->
stack_size
)
{
{
rt_uint32_t
level
;
rt_uint32_t
level
;
rt_kprintf
(
"thread:%s stack overflow
\n
"
,
thread
->
name
);
rt_kprintf
(
"thread:%s stack overflow
\n
"
,
thread
->
name
);
#ifdef RT_USING_FINSH
#ifdef RT_USING_FINSH
{
{
extern
long
list_thread
(
void
);
extern
long
list_thread
(
void
);
list_thread
();
list_thread
();
}
}
#endif
#endif
level
=
rt_hw_interrupt_disable
();
level
=
rt_hw_interrupt_disable
();
while
(
level
);
while
(
level
);
}
}
...
...
src/slab.c
浏览文件 @
2aae989f
...
@@ -222,8 +222,8 @@ static int zone_page_cnt;
...
@@ -222,8 +222,8 @@ static int zone_page_cnt;
#define PAGE_TYPE_LARGE 0x02
#define PAGE_TYPE_LARGE 0x02
struct
memusage
struct
memusage
{
{
rt_uint32_t
type
:
2
;
/* page type */
rt_uint32_t
type
:
2
;
/* page type */
rt_uint32_t
size
:
30
;
/* pages allocated or offset from zone */
rt_uint32_t
size
:
30
;
/* pages allocated or offset from zone */
};
};
static
struct
memusage
*
memusage
=
RT_NULL
;
static
struct
memusage
*
memusage
=
RT_NULL
;
#define btokup(addr) \
#define btokup(addr) \
...
@@ -238,7 +238,7 @@ struct rt_page_head
...
@@ -238,7 +238,7 @@ struct rt_page_head
rt_size_t
page
;
/* number of page */
rt_size_t
page
;
/* number of page */
/* dummy */
/* dummy */
char
dummy
[
RT_MM_PAGE_SIZE
-
(
sizeof
(
struct
rt_page_head
*
)
+
sizeof
(
rt_size_t
))];
char
dummy
[
RT_MM_PAGE_SIZE
-
(
sizeof
(
struct
rt_page_head
*
)
+
sizeof
(
rt_size_t
))];
};
};
static
struct
rt_page_head
*
rt_page_list
;
static
struct
rt_page_head
*
rt_page_list
;
static
struct
rt_semaphore
heap_sem
;
static
struct
rt_semaphore
heap_sem
;
...
@@ -248,7 +248,7 @@ void *rt_page_alloc(rt_size_t npages)
...
@@ -248,7 +248,7 @@ void *rt_page_alloc(rt_size_t npages)
struct
rt_page_head
*
b
,
*
n
;
struct
rt_page_head
*
b
,
*
n
;
struct
rt_page_head
**
prev
;
struct
rt_page_head
**
prev
;
if
(
npages
==
0
)
if
(
npages
==
0
)
return
RT_NULL
;
return
RT_NULL
;
/* lock heap */
/* lock heap */
...
@@ -383,7 +383,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -383,7 +383,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
/* calculate zone size */
/* calculate zone size */
zone_size
=
ZALLOC_MIN_ZONE_SIZE
;
zone_size
=
ZALLOC_MIN_ZONE_SIZE
;
while
(
zone_size
<
ZALLOC_MAX_ZONE_SIZE
&&
(
zone_size
<<
1
)
<
(
limsize
/
1024
))
while
(
zone_size
<
ZALLOC_MAX_ZONE_SIZE
&&
(
zone_size
<<
1
)
<
(
limsize
/
1024
))
zone_size
<<=
1
;
zone_size
<<=
1
;
zone_limit
=
zone_size
/
4
;
zone_limit
=
zone_size
/
4
;
...
@@ -398,7 +398,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -398,7 +398,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
/* 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
);
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"memusage 0x%x, size 0x%x
\n
"
,
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"memusage 0x%x, size 0x%x
\n
"
,
(
rt_uint32_t
)
memusage
,
limsize
));
(
rt_uint32_t
)
memusage
,
limsize
));
...
@@ -411,20 +411,20 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -411,20 +411,20 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
rt_inline
int
zoneindex
(
rt_uint32_t
*
bytes
)
rt_inline
int
zoneindex
(
rt_uint32_t
*
bytes
)
{
{
/* unsigned for shift opt */
/* unsigned for shift opt */
rt_uint32_t
n
=
(
rt_uint32_t
)
*
bytes
;
rt_uint32_t
n
=
(
rt_uint32_t
)
*
bytes
;
if
(
n
<
128
)
if
(
n
<
128
)
{
{
*
bytes
=
n
=
(
n
+
7
)
&
~
7
;
*
bytes
=
n
=
(
n
+
7
)
&
~
7
;
/* 8 byte chunks, 16 zones */
/* 8 byte chunks, 16 zones */
return
(
n
/
8
-
1
);
return
(
n
/
8
-
1
);
}
}
if
(
n
<
256
)
if
(
n
<
256
)
{
{
*
bytes
=
n
=
(
n
+
15
)
&
~
15
;
*
bytes
=
n
=
(
n
+
15
)
&
~
15
;
return
(
n
/
16
+
7
);
return
(
n
/
16
+
7
);
}
}
if
(
n
<
8192
)
if
(
n
<
8192
)
{
{
...
@@ -432,35 +432,35 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
...
@@ -432,35 +432,35 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
{
{
*
bytes
=
n
=
(
n
+
31
)
&
~
31
;
*
bytes
=
n
=
(
n
+
31
)
&
~
31
;
return
(
n
/
32
+
15
);
return
(
n
/
32
+
15
);
}
}
if
(
n
<
1024
)
if
(
n
<
1024
)
{
{
*
bytes
=
n
=
(
n
+
63
)
&
~
63
;
*
bytes
=
n
=
(
n
+
63
)
&
~
63
;
return
(
n
/
64
+
23
);
return
(
n
/
64
+
23
);
}
}
if
(
n
<
2048
)
if
(
n
<
2048
)
{
{
*
bytes
=
n
=
(
n
+
127
)
&
~
127
;
*
bytes
=
n
=
(
n
+
127
)
&
~
127
;
return
(
n
/
128
+
31
);
return
(
n
/
128
+
31
);
}
}
if
(
n
<
4096
)
if
(
n
<
4096
)
{
{
*
bytes
=
n
=
(
n
+
255
)
&
~
255
;
*
bytes
=
n
=
(
n
+
255
)
&
~
255
;
return
(
n
/
256
+
39
);
return
(
n
/
256
+
39
);
}
}
*
bytes
=
n
=
(
n
+
511
)
&
~
511
;
*
bytes
=
n
=
(
n
+
511
)
&
~
511
;
return
(
n
/
512
+
47
);
return
(
n
/
512
+
47
);
}
}
if
(
n
<
16384
)
if
(
n
<
16384
)
{
{
*
bytes
=
n
=
(
n
+
1023
)
&
~
1023
;
*
bytes
=
n
=
(
n
+
1023
)
&
~
1023
;
return
(
n
/
1024
+
55
);
return
(
n
/
1024
+
55
);
}
}
rt_kprintf
(
"Unexpected byte count %d"
,
n
);
rt_kprintf
(
"Unexpected byte count %d"
,
n
);
...
@@ -737,7 +737,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
...
@@ -737,7 +737,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
zoneindex
(
&
size
);
zoneindex
(
&
size
);
if
(
z
->
z_chunksize
==
size
)
if
(
z
->
z_chunksize
==
size
)
return
(
ptr
);
/* same chunk */
return
(
ptr
);
/* same chunk */
/*
/*
* Allocate memory for the new request size. Note that zoneindex has
* Allocate memory for the new request size. Note that zoneindex has
...
@@ -803,7 +803,7 @@ void rt_free(void *ptr)
...
@@ -803,7 +803,7 @@ void rt_free(void *ptr)
RT_OBJECT_HOOK_CALL
(
rt_free_hook
,
(
ptr
));
RT_OBJECT_HOOK_CALL
(
rt_free_hook
,
(
ptr
));
#ifdef RT_USING_MODULE
#ifdef RT_USING_MODULE
if
(
rt_module_self
()
!=
RT_NULL
)
if
(
rt_module_self
()
!=
RT_NULL
)
{
{
rt_module_free
(
rt_module_self
(),
ptr
);
rt_module_free
(
rt_module_self
(),
ptr
);
...
...
src/thread.c
浏览文件 @
2aae989f
...
@@ -55,7 +55,7 @@ static void (*rt_thread_inited_hook) (rt_thread_t thread);
...
@@ -55,7 +55,7 @@ static void (*rt_thread_inited_hook) (rt_thread_t thread);
/**
/**
* @ingroup Hook
* @ingroup Hook
* This function sets a hook function when the system suspend a thread.
* This function sets a hook function when the system suspend a thread.
*
*
* @param hook the specified hook function
* @param hook the specified hook function
*
*
...
@@ -68,7 +68,7 @@ void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
...
@@ -68,7 +68,7 @@ void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
/**
/**
* @ingroup Hook
* @ingroup Hook
* This function sets a hook function when the system resume a thread.
* This function sets a hook function when the system resume a thread.
*
*
* @param hook the specified hook function
* @param hook the specified hook function
*
*
...
@@ -81,13 +81,13 @@ void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
...
@@ -81,13 +81,13 @@ void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
/**
/**
* @ingroup Hook
* @ingroup Hook
* This function sets a hook function when a thread is initialized.
* This function sets a hook function when a thread is initialized.
*
*
* @param hook the specified hook function
* @param hook the specified hook function
*/
*/
void
rt_thread_inited_sethook
(
void
(
*
hook
)(
rt_thread_t
thread
))
void
rt_thread_inited_sethook
(
void
(
*
hook
)(
rt_thread_t
thread
))
{
{
rt_thread_inited_hook
=
hook
;
rt_thread_inited_hook
=
hook
;
}
}
#endif
#endif
...
@@ -151,8 +151,8 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
...
@@ -151,8 +151,8 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
/* init thread stack */
/* init thread stack */
rt_memset
(
thread
->
stack_addr
,
'#'
,
thread
->
stack_size
);
rt_memset
(
thread
->
stack_addr
,
'#'
,
thread
->
stack_size
);
thread
->
sp
=
(
void
*
)
rt_hw_stack_init
(
thread
->
entry
,
thread
->
parameter
,
thread
->
sp
=
(
void
*
)
rt_hw_stack_init
(
thread
->
entry
,
thread
->
parameter
,
(
void
*
)((
char
*
)
thread
->
stack_addr
+
thread
->
stack_size
-
4
),
(
void
*
)((
char
*
)
thread
->
stack_addr
+
thread
->
stack_size
-
4
),
(
void
*
)
rt_thread_exit
);
(
void
*
)
rt_thread_exit
);
/* priority init */
/* priority init */
RT_ASSERT
(
priority
<
RT_THREAD_PRIORITY_MAX
);
RT_ASSERT
(
priority
<
RT_THREAD_PRIORITY_MAX
);
...
@@ -185,7 +185,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
...
@@ -185,7 +185,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
0
,
0
,
RT_TIMER_FLAG_ONE_SHOT
);
RT_TIMER_FLAG_ONE_SHOT
);
RT_OBJECT_HOOK_CALL
(
rt_thread_inited_hook
,(
thread
));
RT_OBJECT_HOOK_CALL
(
rt_thread_inited_hook
,
(
thread
));
return
RT_EOK
;
return
RT_EOK
;
}
}
...
@@ -643,7 +643,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
...
@@ -643,7 +643,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
/* enable interrupt */
/* enable interrupt */
rt_hw_interrupt_enable
(
temp
);
rt_hw_interrupt_enable
(
temp
);
RT_OBJECT_HOOK_CALL
(
rt_thread_suspend_hook
,(
thread
));
RT_OBJECT_HOOK_CALL
(
rt_thread_suspend_hook
,
(
thread
));
return
RT_EOK
;
return
RT_EOK
;
}
}
RTM_EXPORT
(
rt_thread_suspend
);
RTM_EXPORT
(
rt_thread_suspend
);
...
@@ -686,7 +686,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
...
@@ -686,7 +686,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
/* insert to schedule ready list */
/* insert to schedule ready list */
rt_schedule_insert_thread
(
thread
);
rt_schedule_insert_thread
(
thread
);
RT_OBJECT_HOOK_CALL
(
rt_thread_resume_hook
,(
thread
));
RT_OBJECT_HOOK_CALL
(
rt_thread_resume_hook
,
(
thread
));
return
RT_EOK
;
return
RT_EOK
;
}
}
RTM_EXPORT
(
rt_thread_resume
);
RTM_EXPORT
(
rt_thread_resume
);
...
...
src/timer.c
浏览文件 @
2aae989f
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
* 2010-05-12 Bernard fix the timer check bug.
* 2010-05-12 Bernard fix the timer check bug.
* 2010-11-02 Charlie re-implement tick overflow issue
* 2010-11-02 Charlie re-implement tick overflow issue
* 2012-12-15 Bernard fix the next timeout issue in soft timer
* 2012-12-15 Bernard fix the next timeout issue in soft timer
* 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
* 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
* timeout function.
* timeout function.
*/
*/
...
@@ -147,13 +147,13 @@ void rt_timer_dump(rt_list_t timer_heads[])
...
@@ -147,13 +147,13 @@ void rt_timer_dump(rt_list_t timer_heads[])
{
{
rt_list_t
*
list
;
rt_list_t
*
list
;
for
(
list
=
timer_heads
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
;
for
(
list
=
timer_heads
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
;
list
!=
&
timer_heads
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
];
list
!=
&
timer_heads
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
];
list
=
list
->
next
)
list
=
list
->
next
)
{
{
struct
rt_timer
*
timer
=
rt_list_entry
(
list
,
struct
rt_timer
*
timer
=
rt_list_entry
(
list
,
struct
rt_timer
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
rt_kprintf
(
"%d"
,
rt_timer_count_height
(
timer
));
rt_kprintf
(
"%d"
,
rt_timer_count_height
(
timer
));
}
}
rt_kprintf
(
"
\n
"
);
rt_kprintf
(
"
\n
"
);
...
@@ -303,9 +303,9 @@ rt_err_t rt_timer_start(rt_timer_t timer)
...
@@ -303,9 +303,9 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* timer check */
/* timer check */
RT_ASSERT
(
timer
!=
RT_NULL
);
RT_ASSERT
(
timer
!=
RT_NULL
);
/* stop timer firstly */
/* stop timer firstly */
level
=
rt_hw_interrupt_disable
();
level
=
rt_hw_interrupt_disable
();
/* remove timer from list */
/* remove timer from list */
_rt_timer_remove
(
timer
);
_rt_timer_remove
(
timer
);
/* change status of timer */
/* change status of timer */
timer
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
timer
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
@@ -339,7 +339,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
...
@@ -339,7 +339,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
row_head
[
0
]
=
&
timer_list
[
0
];
row_head
[
0
]
=
&
timer_list
[
0
];
for
(
row_lvl
=
0
;
row_lvl
<
RT_TIMER_SKIP_LIST_LEVEL
;
row_lvl
++
)
for
(
row_lvl
=
0
;
row_lvl
<
RT_TIMER_SKIP_LIST_LEVEL
;
row_lvl
++
)
{
{
for
(;
row_head
[
row_lvl
]
!=
timer_list
[
row_lvl
].
prev
;
for
(;
row_head
[
row_lvl
]
!=
timer_list
[
row_lvl
].
prev
;
row_head
[
row_lvl
]
=
row_head
[
row_lvl
]
->
next
)
row_head
[
row_lvl
]
=
row_head
[
row_lvl
]
->
next
)
{
{
struct
rt_timer
*
t
;
struct
rt_timer
*
t
;
...
@@ -363,7 +363,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
...
@@ -363,7 +363,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
}
}
}
}
if
(
row_lvl
!=
RT_TIMER_SKIP_LIST_LEVEL
-
1
)
if
(
row_lvl
!=
RT_TIMER_SKIP_LIST_LEVEL
-
1
)
row_head
[
row_lvl
+
1
]
=
row_head
[
row_lvl
]
+
1
;
row_head
[
row_lvl
+
1
]
=
row_head
[
row_lvl
]
+
1
;
}
}
/* Interestingly, this super simple timer insert counter works very very
/* Interestingly, this super simple timer insert counter works very very
...
@@ -373,8 +373,8 @@ rt_err_t rt_timer_start(rt_timer_t timer)
...
@@ -373,8 +373,8 @@ rt_err_t rt_timer_start(rt_timer_t timer)
random_nr
++
;
random_nr
++
;
tst_nr
=
random_nr
;
tst_nr
=
random_nr
;
rt_list_insert_after
(
row_head
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
],
rt_list_insert_after
(
row_head
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
],
&
(
timer
->
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]));
&
(
timer
->
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]));
for
(
row_lvl
=
2
;
row_lvl
<=
RT_TIMER_SKIP_LIST_LEVEL
;
row_lvl
++
)
for
(
row_lvl
=
2
;
row_lvl
<=
RT_TIMER_SKIP_LIST_LEVEL
;
row_lvl
++
)
{
{
if
(
!
(
tst_nr
&
RT_TIMER_SKIP_LIST_MASK
))
if
(
!
(
tst_nr
&
RT_TIMER_SKIP_LIST_MASK
))
...
@@ -384,7 +384,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
...
@@ -384,7 +384,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
break
;
break
;
/* Shift over the bits we have tested. Works well with 1 bit and 2
/* Shift over the bits we have tested. Works well with 1 bit and 2
* bits. */
* bits. */
tst_nr
>>=
(
RT_TIMER_SKIP_LIST_MASK
+
1
)
>>
1
;
tst_nr
>>=
(
RT_TIMER_SKIP_LIST_MASK
+
1
)
>>
1
;
}
}
timer
->
parent
.
flag
|=
RT_TIMER_FLAG_ACTIVATED
;
timer
->
parent
.
flag
|=
RT_TIMER_FLAG_ACTIVATED
;
...
@@ -498,7 +498,7 @@ void rt_timer_check(void)
...
@@ -498,7 +498,7 @@ void rt_timer_check(void)
/* disable interrupt */
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
level
=
rt_hw_interrupt_disable
();
while
(
!
rt_list_isempty
(
&
rt_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]))
while
(
!
rt_list_isempty
(
&
rt_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]))
{
{
t
=
rt_list_entry
(
rt_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
,
t
=
rt_list_entry
(
rt_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
...
@@ -507,7 +507,7 @@ void rt_timer_check(void)
...
@@ -507,7 +507,7 @@ void rt_timer_check(void)
* It supposes that the new tick shall less than the half duration of
* It supposes that the new tick shall less than the half duration of
* tick max.
* tick max.
*/
*/
if
((
current_tick
-
t
->
timeout_tick
)
<
RT_TICK_MAX
/
2
)
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_timeout_hook
,
(
t
));
...
@@ -570,13 +570,13 @@ void rt_soft_timer_check(void)
...
@@ -570,13 +570,13 @@ void rt_soft_timer_check(void)
current_tick
=
rt_tick_get
();
current_tick
=
rt_tick_get
();
/* lock scheduler */
/* lock scheduler */
rt_enter_critical
();
rt_enter_critical
();
for
(
n
=
rt_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
;
for
(
n
=
rt_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
;
n
!=
&
(
rt_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);)
n
!=
&
(
rt_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);)
{
{
t
=
rt_list_entry
(
n
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
t
=
rt_list_entry
(
n
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
/*
/*
* It supposes that the new tick shall less than the half duration of
* It supposes that the new tick shall less than the half duration of
...
@@ -592,8 +592,8 @@ void rt_soft_timer_check(void)
...
@@ -592,8 +592,8 @@ void rt_soft_timer_check(void)
/* remove timer from timer list firstly */
/* remove timer from timer list firstly */
_rt_timer_remove
(
t
);
_rt_timer_remove
(
t
);
/* not lock scheduler when performing timeout function */
/* not lock scheduler when performing timeout function */
rt_exit_critical
();
rt_exit_critical
();
/* call timeout function */
/* call timeout function */
t
->
timeout_func
(
t
->
parameter
);
t
->
timeout_func
(
t
->
parameter
);
...
@@ -602,8 +602,8 @@ void rt_soft_timer_check(void)
...
@@ -602,8 +602,8 @@ void rt_soft_timer_check(void)
RT_DEBUG_LOG
(
RT_DEBUG_TIMER
,
(
"current tick: %d
\n
"
,
current_tick
));
RT_DEBUG_LOG
(
RT_DEBUG_TIMER
,
(
"current tick: %d
\n
"
,
current_tick
));
/* lock scheduler */
/* lock scheduler */
rt_enter_critical
();
rt_enter_critical
();
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
))
...
@@ -621,8 +621,8 @@ void rt_soft_timer_check(void)
...
@@ -621,8 +621,8 @@ void rt_soft_timer_check(void)
else
break
;
/* not check anymore */
else
break
;
/* not check anymore */
}
}
/* unlock scheduler */
/* unlock scheduler */
rt_exit_critical
();
rt_exit_critical
();
RT_DEBUG_LOG
(
RT_DEBUG_TIMER
,
(
"software timer check leave
\n
"
));
RT_DEBUG_LOG
(
RT_DEBUG_TIMER
,
(
"software timer check leave
\n
"
));
}
}
...
@@ -649,7 +649,7 @@ static void rt_thread_timer_entry(void *parameter)
...
@@ -649,7 +649,7 @@ static void rt_thread_timer_entry(void *parameter)
/* get current tick */
/* get current tick */
current_tick
=
rt_tick_get
();
current_tick
=
rt_tick_get
();
if
((
next_timeout
-
current_tick
)
<
RT_TICK_MAX
/
2
)
if
((
next_timeout
-
current_tick
)
<
RT_TICK_MAX
/
2
)
{
{
/* get the delta timeout tick */
/* get the delta timeout tick */
next_timeout
=
next_timeout
-
current_tick
;
next_timeout
=
next_timeout
-
current_tick
;
...
@@ -672,9 +672,9 @@ void rt_system_timer_init(void)
...
@@ -672,9 +672,9 @@ void rt_system_timer_init(void)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
rt_timer_list
)
/
sizeof
(
rt_timer_list
[
0
]);
i
++
)
for
(
i
=
0
;
i
<
sizeof
(
rt_timer_list
)
/
sizeof
(
rt_timer_list
[
0
]);
i
++
)
{
{
rt_list_init
(
rt_timer_list
+
i
);
rt_list_init
(
rt_timer_list
+
i
);
}
}
}
}
...
@@ -689,10 +689,10 @@ void rt_system_timer_thread_init(void)
...
@@ -689,10 +689,10 @@ void rt_system_timer_thread_init(void)
int
i
;
int
i
;
for
(
i
=
0
;
for
(
i
=
0
;
i
<
sizeof
(
rt_soft_timer_list
)
/
sizeof
(
rt_soft_timer_list
[
0
]);
i
<
sizeof
(
rt_soft_timer_list
)
/
sizeof
(
rt_soft_timer_list
[
0
]);
i
++
)
i
++
)
{
{
rt_list_init
(
rt_soft_timer_list
+
i
);
rt_list_init
(
rt_soft_timer_list
+
i
);
}
}
/* start software timer thread */
/* start software timer thread */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录