mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-08 20:05:29 +08:00
@@ -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_uint32_t)thread->sp - (rt_uint32_t)thread->stack_addr),
|
||||
((rt_ubase_t)thread->sp - (rt_ubase_t)thread->stack_addr),
|
||||
thread->stack_size,
|
||||
((rt_uint32_t)ptr - (rt_uint32_t)thread->stack_addr) * 100 / thread->stack_size,
|
||||
((rt_ubase_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);
|
||||
|
||||
@@ -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_uint32_t *msg_pool; /**< start address of message buffer */
|
||||
rt_ubase_t *msg_pool; /**< start address of message buffer */
|
||||
|
||||
rt_uint16_t size; /**< size of message pool */
|
||||
|
||||
|
||||
@@ -98,14 +98,14 @@ void rt_hw_interrupt_enable(rt_base_t level);
|
||||
/*
|
||||
* Context interfaces
|
||||
*/
|
||||
void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to);
|
||||
void rt_hw_context_switch_to(rt_uint32_t to);
|
||||
void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to);
|
||||
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
|
||||
void rt_hw_context_switch_to(rt_ubase_t to);
|
||||
void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);
|
||||
|
||||
void rt_hw_console_output(const char *str);
|
||||
|
||||
void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_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_ubase_t thread_entry);
|
||||
void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size);
|
||||
|
||||
/*
|
||||
* Exception interfaces
|
||||
|
||||
@@ -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_uint32_t value);
|
||||
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value);
|
||||
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
|
||||
rt_uint32_t value,
|
||||
rt_ubase_t value,
|
||||
rt_int32_t timeout);
|
||||
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout);
|
||||
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
||||
rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
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
|
||||
|
||||
|
||||
13
src/ipc.c
13
src/ipc.c
@@ -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_uint32_t value;
|
||||
rt_ubase_t value;
|
||||
|
||||
/* get value */
|
||||
value = (rt_uint32_t)arg;
|
||||
value = (rt_ubase_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_uint32_t));
|
||||
mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_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_uint32_t value,
|
||||
rt_ubase_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_uint32_t value)
|
||||
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_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_uint32_t *value, rt_int32_t timeout)
|
||||
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
|
||||
{
|
||||
struct rt_thread *thread;
|
||||
register rt_ubase_t temp;
|
||||
|
||||
@@ -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, int base)
|
||||
{
|
||||
rt_int32_t res;
|
||||
int 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_uint32_t)ptr & (align - 1)) == 0)
|
||||
if (((rt_ubase_t)ptr & (align - 1)) == 0)
|
||||
{
|
||||
align_ptr = (void *)((rt_uint32_t)ptr + align);
|
||||
align_ptr = (void *)((rt_ubase_t)ptr + align);
|
||||
}
|
||||
else
|
||||
{
|
||||
align_ptr = (void *)(((rt_uint32_t)ptr + (align - 1)) & ~(align - 1));
|
||||
align_ptr = (void *)(((rt_ubase_t)ptr + (align - 1)) & ~(align - 1));
|
||||
}
|
||||
|
||||
/* set the pointer before alignment pointer to the real pointer */
|
||||
*((rt_uint32_t *)((rt_uint32_t)align_ptr - sizeof(void *))) = (rt_uint32_t)ptr;
|
||||
*((rt_ubase_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_uint32_t *)((rt_uint32_t)ptr - sizeof(void *));
|
||||
real_ptr = (void *) * (rt_ubase_t *)((rt_ubase_t)ptr - sizeof(void *));
|
||||
rt_free(real_ptr);
|
||||
}
|
||||
RTM_EXPORT(rt_free_align);
|
||||
|
||||
43
src/mem.c
43
src/mem.c
@@ -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_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
|
||||
rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
|
||||
rt_ubase_t begin_align = RT_ALIGN((rt_ubase_t)begin_addr, RT_ALIGN_SIZE);
|
||||
rt_ubase_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_uint32_t)begin_addr, (rt_uint32_t)end_addr);
|
||||
(rt_ubase_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_uint32_t)heap_ptr, mem_size_aligned));
|
||||
(rt_ubase_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_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)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||
RT_ASSERT((rt_ubase_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_ubase_t)heap_end);
|
||||
RT_ASSERT((rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
||||
RT_ASSERT((((rt_ubase_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
||||
("allocate memory at 0x%x, size: %d\n",
|
||||
(rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
|
||||
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
||||
(rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
|
||||
(rt_ubase_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_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||
RT_ASSERT((((rt_ubase_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_uint32_t)rmem,
|
||||
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
||||
(rt_ubase_t)rmem,
|
||||
(rt_ubase_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_uint32_t level;
|
||||
rt_ubase_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_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
||||
position = (rt_ubase_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_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
||||
int position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
|
||||
int size;
|
||||
|
||||
rt_kprintf("[0x%08x - ", mem);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_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->stack_size)
|
||||
(rt_ubase_t)thread->sp <= (rt_ubase_t)thread->stack_addr ||
|
||||
(rt_ubase_t)thread->sp >
|
||||
(rt_ubase_t)thread->stack_addr + (rt_ubase_t)thread->stack_size)
|
||||
{
|
||||
rt_uint32_t level;
|
||||
rt_ubase_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_uint32_t)thread->sp > ((rt_uint32_t)thread->stack_addr + thread->stack_size))
|
||||
else if ((rt_ubase_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_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32))
|
||||
else if ((rt_ubase_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_uint32_t)&to_thread->sp);
|
||||
rt_hw_context_switch_to((rt_ubase_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_uint32_t)&from_thread->sp,
|
||||
(rt_uint32_t)&to_thread->sp);
|
||||
rt_hw_context_switch((rt_ubase_t)&from_thread->sp,
|
||||
(rt_ubase_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_uint32_t)&from_thread->sp,
|
||||
(rt_uint32_t)&to_thread->sp);
|
||||
rt_hw_context_switch_interrupt((rt_ubase_t)&from_thread->sp,
|
||||
(rt_ubase_t)&to_thread->sp);
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user