Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
25ee668f
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
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看板
未验证
提交
25ee668f
编写于
11月 20, 2018
作者:
B
Bernard Xiong
提交者:
GitHub
11月 20, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1988 from RT-Thread/dev-4.0.x
Dev 4.0.x
上级
6b6d122e
46dae3f3
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
131 addition
and
89 deletion
+131
-89
components/finsh/cmd.c
components/finsh/cmd.c
+4
-4
include/rtdef.h
include/rtdef.h
+14
-6
include/rthw.h
include/rthw.h
+5
-5
include/rtthread.h
include/rtthread.h
+6
-6
libcpu/Kconfig
libcpu/Kconfig
+15
-0
src/ipc.c
src/ipc.c
+7
-6
src/kservice.c
src/kservice.c
+36
-31
src/mem.c
src/mem.c
+28
-15
src/memheap.c
src/memheap.c
+2
-2
src/scheduler.c
src/scheduler.c
+13
-13
src/thread.c
src/thread.c
+1
-1
未找到文件。
components/finsh/cmd.c
浏览文件 @
25ee668f
...
...
@@ -106,9 +106,9 @@ static long _list_thread(struct rt_list_node *list)
while
(
*
ptr
==
'#'
)
ptr
--
;
rt_kprintf
(
" 0x%08x 0x%08x %02d%% 0x%08x %03d
\n
"
,
((
rt_u
int32_t
)
thread
->
sp
-
(
rt_uint32
_t
)
thread
->
stack_addr
),
((
rt_u
base_t
)
thread
->
sp
-
(
rt_ubase
_t
)
thread
->
stack_addr
),
thread
->
stack_size
,
((
rt_u
int32_t
)
ptr
-
(
rt_uint32
_t
)
thread
->
stack_addr
)
*
100
/
thread
->
stack_size
,
((
rt_u
base_t
)
ptr
-
(
rt_ubase
_t
)
thread
->
stack_addr
)
*
100
/
thread
->
stack_size
,
thread
->
remaining_tick
,
thread
->
error
);
#else
...
...
@@ -116,9 +116,9 @@ static long _list_thread(struct rt_list_node *list)
while
(
*
ptr
==
'#'
)
ptr
++
;
rt_kprintf
(
" 0x%08x 0x%08x %02d%% 0x%08x %03d
\n
"
,
(
thread
->
stack_size
+
(
rt_uint32_t
)
thread
->
stack_addr
-
(
rt_uint32
_t
)
thread
->
sp
),
thread
->
stack_size
+
((
rt_ubase_t
)
thread
->
stack_addr
-
(
rt_ubase
_t
)
thread
->
sp
),
thread
->
stack_size
,
(
thread
->
stack_size
+
(
rt_uint32_t
)
thread
->
stack_addr
-
(
rt_uint32_t
)
ptr
)
*
100
(
thread
->
stack_size
-
((
rt_ubase_t
)
ptr
-
(
rt_ubase_t
)
thread
->
stack_addr
)
)
*
100
/
thread
->
stack_size
,
thread
->
remaining_tick
,
thread
->
error
);
...
...
include/rtdef.h
浏览文件 @
25ee668f
...
...
@@ -24,7 +24,8 @@
* 2018-05-31 Bernard change version number to v3.1.0
* 2018-09-04 Bernard change version number to v3.1.1
* 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel
* 2018-11-18 Bernard change version number to v4.0.0
* 2018-10-13 Bernard change version number to v4.0.0
* 2018-10-02 Bernard add 64bit arch support
*/
#ifndef __RT_DEF_H__
...
...
@@ -55,13 +56,20 @@ extern "C" {
/* RT-Thread basic data type definitions */
typedef
signed
char
rt_int8_t
;
/**< 8bit integer type */
typedef
signed
short
rt_int16_t
;
/**< 16bit integer type */
typedef
signed
long
rt_int32_t
;
/**< 32bit integer type */
typedef
signed
int
rt_int32_t
;
/**< 32bit integer type */
typedef
unsigned
char
rt_uint8_t
;
/**< 8bit unsigned integer type */
typedef
unsigned
short
rt_uint16_t
;
/**< 16bit unsigned integer type */
typedef
unsigned
long
rt_uint32_t
;
/**< 32bit unsigned integer type */
typedef
int
rt_bool_t
;
/**< boolean type */
typedef
unsigned
int
rt_uint32_t
;
/**< 32bit unsigned integer type */
/* 32bit CPU */
#ifdef ARCH_CPU_64BIT
typedef
signed
long
rt_int64_t
;
/**< 64bit integer type */
typedef
unsigned
long
rt_uint64_t
;
/**< 64bit unsigned integer type */
#else
typedef
signed
long
long
rt_int64_t
;
/**< 64bit integer type */
typedef
unsigned
long
long
rt_uint64_t
;
/**< 64bit unsigned integer type */
#endif
typedef
int
rt_bool_t
;
/**< boolean type */
typedef
long
rt_base_t
;
/**< Nbit CPU related date type */
typedef
unsigned
long
rt_ubase_t
;
/**< Nbit unsigned CPU related data type */
...
...
@@ -648,7 +656,7 @@ struct rt_mailbox
{
struct
rt_ipc_object
parent
;
/**< inherit from ipc_object */
rt_u
int32_t
*
msg_pool
;
/**< start address of message buffer */
rt_u
base_t
*
msg_pool
;
/**< start address of message buffer */
rt_uint16_t
size
;
/**< size of message pool */
...
...
include/rthw.h
浏览文件 @
25ee668f
...
...
@@ -98,14 +98,14 @@ void rt_hw_interrupt_enable(rt_base_t level);
/*
* Context interfaces
*/
void
rt_hw_context_switch
(
rt_u
int32_t
from
,
rt_uint32
_t
to
);
void
rt_hw_context_switch_to
(
rt_u
int32
_t
to
);
void
rt_hw_context_switch_interrupt
(
rt_u
int32_t
from
,
rt_uint32
_t
to
);
void
rt_hw_context_switch
(
rt_u
base_t
from
,
rt_ubase
_t
to
);
void
rt_hw_context_switch_to
(
rt_u
base
_t
to
);
void
rt_hw_context_switch_interrupt
(
rt_u
base_t
from
,
rt_ubase
_t
to
);
void
rt_hw_console_output
(
const
char
*
str
);
void
rt_hw_backtrace
(
rt_uint32_t
*
fp
,
rt_u
int32
_t
thread_entry
);
void
rt_hw_show_memory
(
rt_uint32_t
addr
,
rt_
uint32
_t
size
);
void
rt_hw_backtrace
(
rt_uint32_t
*
fp
,
rt_u
base
_t
thread_entry
);
void
rt_hw_show_memory
(
rt_uint32_t
addr
,
rt_
size
_t
size
);
/*
* Exception interfaces
...
...
include/rtthread.h
浏览文件 @
25ee668f
...
...
@@ -257,7 +257,7 @@ void rt_page_free(void *addr, rt_size_t npages);
#endif
#ifdef RT_USING_HOOK
void
rt_malloc_sethook
(
void
(
*
hook
)(
void
*
ptr
,
rt_
uint32
_t
size
));
void
rt_malloc_sethook
(
void
(
*
hook
)(
void
*
ptr
,
rt_
size
_t
size
));
void
rt_free_sethook
(
void
(
*
hook
)(
void
*
ptr
));
#endif
...
...
@@ -270,9 +270,9 @@ void rt_free_sethook(void (*hook)(void *ptr));
rt_err_t
rt_memheap_init
(
struct
rt_memheap
*
memheap
,
const
char
*
name
,
void
*
start_addr
,
rt_
uint32_t
size
);
rt_
size_t
size
);
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_
size
_t
size
);
void
*
rt_memheap_realloc
(
struct
rt_memheap
*
heap
,
void
*
ptr
,
rt_size_t
newsize
);
void
rt_memheap_free
(
void
*
ptr
);
#endif
...
...
@@ -348,11 +348,11 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb);
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_send
(
rt_mailbox_t
mb
,
rt_u
int32
_t
value
);
rt_err_t
rt_mb_send
(
rt_mailbox_t
mb
,
rt_u
base
_t
value
);
rt_err_t
rt_mb_send_wait
(
rt_mailbox_t
mb
,
rt_u
int32
_t
value
,
rt_u
base
_t
value
,
rt_int32_t
timeout
);
rt_err_t
rt_mb_recv
(
rt_mailbox_t
mb
,
rt_u
int32
_t
*
value
,
rt_int32_t
timeout
);
rt_err_t
rt_mb_recv
(
rt_mailbox_t
mb
,
rt_u
base
_t
*
value
,
rt_int32_t
timeout
);
rt_err_t
rt_mb_control
(
rt_mailbox_t
mb
,
int
cmd
,
void
*
arg
);
#endif
...
...
libcpu/Kconfig
浏览文件 @
25ee668f
config ARCH_CPU_64BIT
bool
config ARCH_ARM
bool
...
...
@@ -83,6 +86,18 @@ config ARCH_POWERPC
config ARCH_RISCV
bool
config ARCH_RISCV_FPU
bool
config ARCH_RISCV32
select ARCH_RISCV
bool
config ARCH_RISCV64
select ARCH_RISCV
select ARCH_CPU_64BIT
bool
config ARCH_IA32
bool
...
...
src/ipc.c
浏览文件 @
25ee668f
...
...
@@ -32,6 +32,7 @@
* 2010-11-10 Bernard add IPC reset command implementation.
* 2011-12-18 Bernard add more parameter checking in message queue
* 2013-09-14 Grissiom add an option check in rt_event_recv
* 2018-10-02 Bernard add 64bit support for mailbox
*/
#include <rtthread.h>
...
...
@@ -486,10 +487,10 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
if
(
cmd
==
RT_IPC_CMD_RESET
)
{
rt_u
int32
_t
value
;
rt_u
base
_t
value
;
/* get value */
value
=
(
rt_u
int32
_t
)
arg
;
value
=
(
rt_u
base
_t
)
arg
;
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
...
...
@@ -1373,7 +1374,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
/* init mailbox */
mb
->
size
=
size
;
mb
->
msg_pool
=
RT_KERNEL_MALLOC
(
mb
->
size
*
sizeof
(
rt_u
int32
_t
));
mb
->
msg_pool
=
RT_KERNEL_MALLOC
(
mb
->
size
*
sizeof
(
rt_u
base
_t
));
if
(
mb
->
msg_pool
==
RT_NULL
)
{
/* delete mailbox object */
...
...
@@ -1436,7 +1437,7 @@ RTM_EXPORT(rt_mb_delete);
* @return the error code
*/
rt_err_t
rt_mb_send_wait
(
rt_mailbox_t
mb
,
rt_u
int32_t
value
,
rt_u
base_t
value
,
rt_int32_t
timeout
)
{
struct
rt_thread
*
thread
;
...
...
@@ -1567,7 +1568,7 @@ RTM_EXPORT(rt_mb_send_wait);
*
* @return the error code
*/
rt_err_t
rt_mb_send
(
rt_mailbox_t
mb
,
rt_u
int32
_t
value
)
rt_err_t
rt_mb_send
(
rt_mailbox_t
mb
,
rt_u
base
_t
value
)
{
return
rt_mb_send_wait
(
mb
,
value
,
0
);
}
...
...
@@ -1583,7 +1584,7 @@ RTM_EXPORT(rt_mb_send);
*
* @return the error code
*/
rt_err_t
rt_mb_recv
(
rt_mailbox_t
mb
,
rt_u
int32
_t
*
value
,
rt_int32_t
timeout
)
rt_err_t
rt_mb_recv
(
rt_mailbox_t
mb
,
rt_u
base
_t
*
value
,
rt_int32_t
timeout
)
{
struct
rt_thread
*
thread
;
register
rt_ubase_t
temp
;
...
...
src/kservice.c
浏览文件 @
25ee668f
...
...
@@ -133,20 +133,21 @@ void *rt_memset(void *s, int c, rt_ubase_t count)
return
s
;
#else
#define LBLOCKSIZE (sizeof(
rt_int32_t
))
#define UNALIGNED(X) ((
rt_int32_t
)X & (LBLOCKSIZE - 1))
#define LBLOCKSIZE (sizeof(
long
))
#define UNALIGNED(X) ((
long
)X & (LBLOCKSIZE - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
int
i
;
unsigned
int
i
;
char
*
m
=
(
char
*
)
s
;
rt_uint32_t
buffer
;
rt_uint32_t
*
aligned_addr
;
rt_uint32_t
d
=
c
&
0xff
;
unsigned
long
buffer
;
unsigned
long
*
aligned_addr
;
unsigned
int
d
=
c
&
0xff
;
/* To avoid sign extension, copy C to an
unsigned variable. */
if
(
!
TOO_SMALL
(
count
)
&&
!
UNALIGNED
(
s
))
{
/* If we get this far, we know that n is large and m is word-aligned. */
aligned_addr
=
(
rt_uint32_t
*
)
s
;
aligned_addr
=
(
unsigned
long
*
)
s
;
/* Store D into each char sized location in BUFFER so that
* we can set large blocks quickly.
...
...
@@ -226,25 +227,24 @@ void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
return
dst
;
#else
#define UNALIGNED(X, Y) \
(((rt_int32_t)X & (sizeof(rt_int32_t) - 1)) | \
((rt_int32_t)Y & (sizeof(rt_int32_t) - 1)))
#define BIGBLOCKSIZE (sizeof(rt_int32_t) << 2)
#define LITTLEBLOCKSIZE (sizeof(rt_int32_t))
#define UNALIGNED(X, Y) \
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
#define BIGBLOCKSIZE (sizeof (long) << 2)
#define LITTLEBLOCKSIZE (sizeof (long))
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
char
*
dst_ptr
=
(
char
*
)
dst
;
char
*
src_ptr
=
(
char
*
)
src
;
rt_int32_t
*
aligned_dst
;
rt_int32_t
*
aligned_src
;
long
*
aligned_dst
;
long
*
aligned_src
;
int
len
=
count
;
/* If the size is small, or either SRC or DST is unaligned,
then punt into the byte copy loop. This should be rare. */
if
(
!
TOO_SMALL
(
len
)
&&
!
UNALIGNED
(
src_ptr
,
dst_ptr
))
{
aligned_dst
=
(
rt_int32_t
*
)
dst_ptr
;
aligned_src
=
(
rt_int32_t
*
)
src_ptr
;
aligned_dst
=
(
long
*
)
dst_ptr
;
aligned_src
=
(
long
*
)
src_ptr
;
/* Copy 4X long words at a time if possible. */
while
(
len
>=
BIGBLOCKSIZE
)
...
...
@@ -542,20 +542,20 @@ RTM_EXPORT(rt_show_version);
/* private function */
#define isdigit(c) ((unsigned)((c) - '0') < 10)
rt_inline
rt_int32_t
divide
(
rt_int32_t
*
n
,
rt_int32_
t
base
)
rt_inline
int
divide
(
long
*
n
,
in
t
base
)
{
rt_int32_
t
res
;
in
t
res
;
/* optimized for processor which does not support divide instructions. */
if
(
base
==
10
)
{
res
=
(
(
rt_uint32_t
)
*
n
)
%
10U
;
*
n
=
(
(
rt_uint32_t
)
*
n
)
/
10U
;
res
=
(
int
)(((
unsigned
long
)
*
n
)
%
10U
)
;
*
n
=
(
long
)(((
unsigned
long
)
*
n
)
/
10U
)
;
}
else
{
res
=
(
(
rt_uint32_t
)
*
n
)
%
16U
;
*
n
=
(
(
rt_uint32_t
)
*
n
)
/
16U
;
res
=
(
int
)(((
unsigned
long
)
*
n
)
%
16U
)
;
*
n
=
(
long
)(((
unsigned
long
)
*
n
)
/
16U
)
;
}
return
res
;
...
...
@@ -1189,31 +1189,36 @@ RTM_EXPORT(rt_kprintf);
*/
void
*
rt_malloc_align
(
rt_size_t
size
,
rt_size_t
align
)
{
void
*
align_ptr
;
void
*
ptr
;
void
*
align_ptr
;
int
uintptr_size
;
rt_size_t
align_size
;
/* align the alignment size to 4 byte */
align
=
((
align
+
0x03
)
&
~
0x03
);
/* sizeof pointer */
uintptr_size
=
sizeof
(
void
*
);
uintptr_size
-=
1
;
/* align the alignment size to uintptr size byte */
align
=
((
align
+
uintptr_size
)
&
~
uintptr_size
);
/* get total aligned size */
align_size
=
((
size
+
0x03
)
&
~
0x03
)
+
align
;
align_size
=
((
size
+
uintptr_size
)
&
~
uintptr_size
)
+
align
;
/* allocate memory block from heap */
ptr
=
rt_malloc
(
align_size
);
if
(
ptr
!=
RT_NULL
)
{
/* the allocated memory block is aligned */
if
(((
rt_u
int32
_t
)
ptr
&
(
align
-
1
))
==
0
)
if
(((
rt_u
base
_t
)
ptr
&
(
align
-
1
))
==
0
)
{
align_ptr
=
(
void
*
)((
rt_u
int32
_t
)
ptr
+
align
);
align_ptr
=
(
void
*
)((
rt_u
base
_t
)
ptr
+
align
);
}
else
{
align_ptr
=
(
void
*
)(((
rt_u
int32
_t
)
ptr
+
(
align
-
1
))
&
~
(
align
-
1
));
align_ptr
=
(
void
*
)(((
rt_u
base
_t
)
ptr
+
(
align
-
1
))
&
~
(
align
-
1
));
}
/* set the pointer before alignment pointer to the real pointer */
*
((
rt_u
int32_t
*
)((
rt_uint32_t
)
align_ptr
-
sizeof
(
void
*
)))
=
(
rt_uint32
_t
)
ptr
;
*
((
rt_u
base_t
*
)((
rt_ubase_t
)
align_ptr
-
sizeof
(
void
*
)))
=
(
rt_ubase
_t
)
ptr
;
ptr
=
align_ptr
;
}
...
...
@@ -1232,7 +1237,7 @@ void rt_free_align(void *ptr)
{
void
*
real_ptr
;
real_ptr
=
(
void
*
)
*
(
rt_u
int32_t
*
)((
rt_uint32
_t
)
ptr
-
sizeof
(
void
*
));
real_ptr
=
(
void
*
)
*
(
rt_u
base_t
*
)((
rt_ubase
_t
)
ptr
-
sizeof
(
void
*
));
rt_free
(
real_ptr
);
}
RTM_EXPORT
(
rt_free_align
);
...
...
src/mem.c
浏览文件 @
25ee668f
...
...
@@ -11,6 +11,7 @@
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
* 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer.
* 2017-07-14 armink fix rt_realloc issue when new size is 0
* 2018-10-02 Bernard Add 64bit support
*/
/*
...
...
@@ -97,12 +98,19 @@ struct heap_mem
/* magic and used flag */
rt_uint16_t
magic
;
rt_uint16_t
used
;
#ifdef ARCH_CPU_64BIT
rt_uint32_t
resv
;
#endif
rt_size_t
next
,
prev
;
#ifdef RT_USING_MEMTRACE
#ifdef ARCH_CPU_64BIT
rt_uint8_t
thread
[
8
];
#else
rt_uint8_t
thread
[
4
];
/* thread name */
#endif
#endif
};
/** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
...
...
@@ -111,7 +119,12 @@ static rt_uint8_t *heap_ptr;
/** the last entry, always unused! */
static
struct
heap_mem
*
heap_end
;
#ifdef ARCH_CPU_64BIT
#define MIN_SIZE 24
#else
#define MIN_SIZE 12
#endif
#define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
#define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
...
...
@@ -191,8 +204,8 @@ static void plug_holes(struct heap_mem *mem)
void
rt_system_heap_init
(
void
*
begin_addr
,
void
*
end_addr
)
{
struct
heap_mem
*
mem
;
rt_u
int32_t
begin_align
=
RT_ALIGN
((
rt_uint32
_t
)
begin_addr
,
RT_ALIGN_SIZE
);
rt_u
int32_t
end_align
=
RT_ALIGN_DOWN
((
rt_uint32
_t
)
end_addr
,
RT_ALIGN_SIZE
);
rt_u
base_t
begin_align
=
RT_ALIGN
((
rt_ubase
_t
)
begin_addr
,
RT_ALIGN_SIZE
);
rt_u
base_t
end_align
=
RT_ALIGN_DOWN
((
rt_ubase
_t
)
end_addr
,
RT_ALIGN_SIZE
);
RT_DEBUG_NOT_IN_INTERRUPT
;
...
...
@@ -206,7 +219,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
else
{
rt_kprintf
(
"mem init, error begin address 0x%x, and end address 0x%x
\n
"
,
(
rt_u
int32_t
)
begin_addr
,
(
rt_uint32
_t
)
end_addr
);
(
rt_u
base_t
)
begin_addr
,
(
rt_ubase
_t
)
end_addr
);
return
;
}
...
...
@@ -215,7 +228,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
heap_ptr
=
(
rt_uint8_t
*
)
begin_align
;
RT_DEBUG_LOG
(
RT_DEBUG_MEM
,
(
"mem init, heap begin address 0x%x, size %d
\n
"
,
(
rt_u
int32
_t
)
heap_ptr
,
mem_size_aligned
));
(
rt_u
base
_t
)
heap_ptr
,
mem_size_aligned
));
/* initialize the start of the heap */
mem
=
(
struct
heap_mem
*
)
heap_ptr
;
...
...
@@ -374,14 +387,14 @@ void *rt_malloc(rt_size_t size)
}
rt_sem_release
(
&
heap_sem
);
RT_ASSERT
((
rt_u
int32_t
)
mem
+
SIZEOF_STRUCT_MEM
+
size
<=
(
rt_uint32
_t
)
heap_end
);
RT_ASSERT
((
rt_u
int32
_t
)((
rt_uint8_t
*
)
mem
+
SIZEOF_STRUCT_MEM
)
%
RT_ALIGN_SIZE
==
0
);
RT_ASSERT
((((
rt_u
int32
_t
)
mem
)
&
(
RT_ALIGN_SIZE
-
1
))
==
0
);
RT_ASSERT
((
rt_u
base_t
)
mem
+
SIZEOF_STRUCT_MEM
+
size
<=
(
rt_ubase
_t
)
heap_end
);
RT_ASSERT
((
rt_u
base
_t
)((
rt_uint8_t
*
)
mem
+
SIZEOF_STRUCT_MEM
)
%
RT_ALIGN_SIZE
==
0
);
RT_ASSERT
((((
rt_u
base
_t
)
mem
)
&
(
RT_ALIGN_SIZE
-
1
))
==
0
);
RT_DEBUG_LOG
(
RT_DEBUG_MEM
,
(
"allocate memory at 0x%x, size: %d
\n
"
,
(
rt_u
int32
_t
)((
rt_uint8_t
*
)
mem
+
SIZEOF_STRUCT_MEM
),
(
rt_u
int32
_t
)(
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
))));
(
rt_u
base
_t
)((
rt_uint8_t
*
)
mem
+
SIZEOF_STRUCT_MEM
),
(
rt_u
base
_t
)(
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
))));
RT_OBJECT_HOOK_CALL
(
rt_malloc_hook
,
(((
void
*
)((
rt_uint8_t
*
)
mem
+
SIZEOF_STRUCT_MEM
)),
size
));
...
...
@@ -539,7 +552,7 @@ void rt_free(void *rmem)
RT_DEBUG_NOT_IN_INTERRUPT
;
RT_ASSERT
((((
rt_u
int32
_t
)
rmem
)
&
(
RT_ALIGN_SIZE
-
1
))
==
0
);
RT_ASSERT
((((
rt_u
base
_t
)
rmem
)
&
(
RT_ALIGN_SIZE
-
1
))
==
0
);
RT_ASSERT
((
rt_uint8_t
*
)
rmem
>=
(
rt_uint8_t
*
)
heap_ptr
&&
(
rt_uint8_t
*
)
rmem
<
(
rt_uint8_t
*
)
heap_end
);
...
...
@@ -558,8 +571,8 @@ void rt_free(void *rmem)
RT_DEBUG_LOG
(
RT_DEBUG_MEM
,
(
"release memory 0x%x, size: %d
\n
"
,
(
rt_u
int32
_t
)
rmem
,
(
rt_u
int32
_t
)(
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
))));
(
rt_u
base
_t
)
rmem
,
(
rt_u
base
_t
)(
mem
->
next
-
((
rt_uint8_t
*
)
mem
-
heap_ptr
))));
/* protect the heap from concurrent access */
...
...
@@ -624,12 +637,12 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
int
memcheck
(
void
)
{
int
position
;
rt_u
int32
_t
level
;
rt_u
base
_t
level
;
struct
heap_mem
*
mem
;
level
=
rt_hw_interrupt_disable
();
for
(
mem
=
(
struct
heap_mem
*
)
heap_ptr
;
mem
!=
heap_end
;
mem
=
(
struct
heap_mem
*
)
&
heap_ptr
[
mem
->
next
])
{
position
=
(
rt_u
int32_t
)
mem
-
(
rt_uint32
_t
)
heap_ptr
;
position
=
(
rt_u
base_t
)
mem
-
(
rt_ubase
_t
)
heap_ptr
;
if
(
position
<
0
)
goto
__exit
;
if
(
position
>
mem_size_aligned
)
goto
__exit
;
if
(
mem
->
magic
!=
HEAP_MAGIC
)
goto
__exit
;
...
...
@@ -664,7 +677,7 @@ int memtrace(int argc, char **argv)
rt_kprintf
(
"
\n
--memory item information --
\n
"
);
for
(
mem
=
(
struct
heap_mem
*
)
heap_ptr
;
mem
!=
heap_end
;
mem
=
(
struct
heap_mem
*
)
&
heap_ptr
[
mem
->
next
])
{
int
position
=
(
rt_u
int32_t
)
mem
-
(
rt_uint32
_t
)
heap_ptr
;
int
position
=
(
rt_u
base_t
)
mem
-
(
rt_ubase
_t
)
heap_ptr
;
int
size
;
rt_kprintf
(
"[0x%08x - "
,
mem
);
...
...
src/memheap.c
浏览文件 @
25ee668f
...
...
@@ -50,7 +50,7 @@
rt_err_t
rt_memheap_init
(
struct
rt_memheap
*
memheap
,
const
char
*
name
,
void
*
start_addr
,
rt_
uint32_t
size
)
rt_
size_t
size
)
{
struct
rt_memheap_item
*
item
;
...
...
@@ -135,7 +135,7 @@ rt_err_t rt_memheap_detach(struct rt_memheap *heap)
}
RTM_EXPORT
(
rt_memheap_detach
);
void
*
rt_memheap_alloc
(
struct
rt_memheap
*
heap
,
rt_
uint32
_t
size
)
void
*
rt_memheap_alloc
(
struct
rt_memheap
*
heap
,
rt_
size
_t
size
)
{
rt_err_t
result
;
rt_uint32_t
free_size
;
...
...
src/scheduler.c
浏览文件 @
25ee668f
...
...
@@ -75,11 +75,11 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
RT_ASSERT
(
thread
!=
RT_NULL
);
if
(
*
((
rt_uint8_t
*
)
thread
->
stack_addr
)
!=
'#'
||
(
rt_u
int32_t
)
thread
->
sp
<=
(
rt_uint32
_t
)
thread
->
stack_addr
||
(
rt_u
int32
_t
)
thread
->
sp
>
(
rt_u
int32_t
)
thread
->
stack_addr
+
(
rt_uint32
_t
)
thread
->
stack_size
)
(
rt_u
base_t
)
thread
->
sp
<=
(
rt_ubase
_t
)
thread
->
stack_addr
||
(
rt_u
base
_t
)
thread
->
sp
>
(
rt_u
base_t
)
thread
->
stack_addr
+
(
rt_ubase
_t
)
thread
->
stack_size
)
{
rt_u
int32
_t
level
;
rt_u
base
_t
level
;
rt_kprintf
(
"thread:%s stack overflow
\n
"
,
thread
->
name
);
#ifdef RT_USING_FINSH
...
...
@@ -92,13 +92,13 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
while
(
level
);
}
#if defined(ARCH_CPU_STACK_GROWS_UPWARD)
else
if
((
rt_u
int32_t
)
thread
->
sp
>
((
rt_uint32
_t
)
thread
->
stack_addr
+
thread
->
stack_size
))
else
if
((
rt_u
base_t
)
thread
->
sp
>
((
rt_ubase
_t
)
thread
->
stack_addr
+
thread
->
stack_size
))
{
rt_kprintf
(
"warning: %s stack is close to the top of stack address.
\n
"
,
thread
->
name
);
}
#else
else
if
((
rt_u
int32_t
)
thread
->
sp
<=
((
rt_uint32
_t
)
thread
->
stack_addr
+
32
))
else
if
((
rt_u
base_t
)
thread
->
sp
<=
((
rt_ubase
_t
)
thread
->
stack_addr
+
32
))
{
rt_kprintf
(
"warning: %s stack is close to the bottom of stack address.
\n
"
,
thread
->
name
);
...
...
@@ -167,7 +167,7 @@ void rt_system_scheduler_start(void)
rt_current_thread
=
to_thread
;
/* switch to new thread */
rt_hw_context_switch_to
((
rt_u
int32
_t
)
&
to_thread
->
sp
);
rt_hw_context_switch_to
((
rt_u
base
_t
)
&
to_thread
->
sp
);
/* never come back */
}
...
...
@@ -222,8 +222,8 @@ void rt_schedule(void)
/* switch to new thread */
RT_DEBUG_LOG
(
RT_DEBUG_SCHEDULER
,
(
"[%d]switch to priority#%d "
"thread:%.*s(sp:0x%
p
), "
"from thread:%.*s(sp: 0x%
p
)
\n
"
,
"thread:%.*s(sp:0x%
08x
), "
"from thread:%.*s(sp: 0x%
08x
)
\n
"
,
rt_interrupt_nest
,
highest_ready_priority
,
RT_NAME_MAX
,
to_thread
->
name
,
to_thread
->
sp
,
RT_NAME_MAX
,
from_thread
->
name
,
from_thread
->
sp
));
...
...
@@ -236,8 +236,8 @@ void rt_schedule(void)
{
extern
void
rt_thread_handle_sig
(
rt_bool_t
clean_state
);
rt_hw_context_switch
((
rt_u
int32
_t
)
&
from_thread
->
sp
,
(
rt_u
int32
_t
)
&
to_thread
->
sp
);
rt_hw_context_switch
((
rt_u
base
_t
)
&
from_thread
->
sp
,
(
rt_u
base
_t
)
&
to_thread
->
sp
);
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
@@ -251,8 +251,8 @@ void rt_schedule(void)
{
RT_DEBUG_LOG
(
RT_DEBUG_SCHEDULER
,
(
"switch in interrupt
\n
"
));
rt_hw_context_switch_interrupt
((
rt_u
int32
_t
)
&
from_thread
->
sp
,
(
rt_u
int32
_t
)
&
to_thread
->
sp
);
rt_hw_context_switch_interrupt
((
rt_u
base
_t
)
&
from_thread
->
sp
,
(
rt_u
base
_t
)
&
to_thread
->
sp
);
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
}
...
...
src/thread.c
浏览文件 @
25ee668f
...
...
@@ -142,7 +142,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
(
void
*
)
rt_thread_exit
);
#else
thread
->
sp
=
(
void
*
)
rt_hw_stack_init
(
thread
->
entry
,
thread
->
parameter
,
(
void
*
)((
char
*
)
thread
->
stack_addr
+
thread
->
stack_size
-
4
),
(
void
*
)((
char
*
)
thread
->
stack_addr
+
thread
->
stack_size
-
sizeof
(
rt_ubase_t
)
),
(
void
*
)
rt_thread_exit
);
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录