mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
This commit is contained in:
commit
cccff34fca
2436 files changed
+1661497
-119417
No files matched your search
+17
-11
@@ -33,9 +33,15 @@
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef RT_USING_USER_MAIN
|
||||
#ifndef RT_MAIN_THREAD_STACK_SIZE
|
||||
#define RT_MAIN_THREAD_STACK_SIZE 2048
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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:
|
||||
* rti_start --> 0
|
||||
* BOARD_EXPORT --> 1
|
||||
@@ -45,17 +51,17 @@
|
||||
* COMPONENT_EXPORT --> 3
|
||||
* FS_EXPORT --> 4
|
||||
* ENV_EXPORT --> 5
|
||||
* APP_EXPORT --> 6
|
||||
*
|
||||
* APP_EXPORT --> 6
|
||||
*
|
||||
* 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:
|
||||
* INIT_BOARD_EXPORT(fn);
|
||||
* INIT_DEVICE_EXPORT(fn);
|
||||
* ...
|
||||
* INIT_APP_EXPORT(fn);
|
||||
* etc.
|
||||
* etc.
|
||||
*/
|
||||
static int rti_start(void)
|
||||
{
|
||||
@@ -149,11 +155,11 @@ int $Sub$$main(void)
|
||||
#elif defined(__ICCARM__)
|
||||
extern int main(void);
|
||||
/* __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)
|
||||
{
|
||||
// call IAR table copy function.
|
||||
__iar_data_init3();
|
||||
// call IAR table copy function.
|
||||
__iar_data_init3();
|
||||
rt_hw_interrupt_disable();
|
||||
rtthread_startup();
|
||||
return 0;
|
||||
@@ -172,7 +178,7 @@ int entry(void)
|
||||
#ifndef RT_USING_HEAP
|
||||
/* if there is not enable heap, we should use static thread and stack. */
|
||||
ALIGN(8)
|
||||
static rt_uint8_t main_stack[2048];
|
||||
static rt_uint8_t main_stack[RT_MAIN_THREAD_STACK_SIZE];
|
||||
struct rt_thread main_thread;
|
||||
#endif
|
||||
|
||||
@@ -199,7 +205,7 @@ void rt_application_init(void)
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
tid = rt_thread_create("main", main_thread_entry, RT_NULL,
|
||||
2048, RT_THREAD_PRIORITY_MAX / 3, 20);
|
||||
RT_MAIN_THREAD_STACK_SIZE, RT_THREAD_PRIORITY_MAX / 3, 20);
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
#else
|
||||
rt_err_t result;
|
||||
@@ -215,7 +221,7 @@ void rt_application_init(void)
|
||||
|
||||
int rtthread_startup(void)
|
||||
{
|
||||
rt_hw_interrupt_disable();
|
||||
rt_hw_interrupt_disable();
|
||||
|
||||
/* board level initalization
|
||||
* NOTE: please initialize heap inside board initialization.
|
||||
|
||||
+6
-6
@@ -55,7 +55,7 @@ static void (*rt_thread_idle_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.
|
||||
*
|
||||
* @param hook the specified hook function
|
||||
@@ -77,7 +77,7 @@ rt_inline int _has_defunct_thread(void)
|
||||
* into a "if".
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
@@ -155,8 +155,8 @@ void rt_thread_idle_excute(void)
|
||||
rt_module_free((rt_module_t)thread->module_id, thread->stack_addr);
|
||||
else
|
||||
#endif
|
||||
/* release thread's stack */
|
||||
RT_KERNEL_FREE(thread->stack_addr);
|
||||
/* release thread's stack */
|
||||
RT_KERNEL_FREE(thread->stack_addr);
|
||||
/* delete thread object */
|
||||
rt_object_delete((rt_object_t)thread);
|
||||
#endif
|
||||
@@ -185,12 +185,12 @@ static void rt_thread_idle_entry(void *parameter)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
#ifdef RT_USING_IDLE_HOOK
|
||||
#ifdef RT_USING_IDLE_HOOK
|
||||
if (rt_thread_idle_hook != RT_NULL)
|
||||
{
|
||||
rt_thread_idle_hook();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
rt_thread_idle_excute();
|
||||
}
|
||||
|
||||
@@ -1384,8 +1384,8 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb)
|
||||
else
|
||||
#endif
|
||||
|
||||
/* free mailbox pool */
|
||||
RT_KERNEL_FREE(mb->msg_pool);
|
||||
/* free mailbox pool */
|
||||
RT_KERNEL_FREE(mb->msg_pool);
|
||||
|
||||
/* delete mailbox object */
|
||||
rt_object_delete(&(mb->parent.parent));
|
||||
@@ -1777,7 +1777,7 @@ rt_err_t rt_mq_init(rt_mq_t mq,
|
||||
for (temp = 0; temp < mq->max_msgs; temp ++)
|
||||
{
|
||||
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;
|
||||
mq->msg_queue_free = head;
|
||||
}
|
||||
@@ -1851,7 +1851,7 @@ rt_mq_t rt_mq_create(const char *name,
|
||||
mq->max_msgs = max_msgs;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
rt_mq_delete(mq);
|
||||
@@ -1868,7 +1868,7 @@ rt_mq_t rt_mq_create(const char *name,
|
||||
for (temp = 0; temp < mq->max_msgs; temp ++)
|
||||
{
|
||||
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;
|
||||
mq->msg_queue_free = head;
|
||||
}
|
||||
@@ -1904,8 +1904,8 @@ rt_err_t rt_mq_delete(rt_mq_t mq)
|
||||
else
|
||||
#endif
|
||||
|
||||
/* free message queue pool */
|
||||
RT_KERNEL_FREE(mq->msg_pool);
|
||||
/* free message queue pool */
|
||||
RT_KERNEL_FREE(mq->msg_pool);
|
||||
|
||||
/* delete message queue object */
|
||||
rt_object_delete(&(mq->parent.parent));
|
||||
@@ -1944,7 +1944,7 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
|
||||
temp = rt_hw_interrupt_disable();
|
||||
|
||||
/* 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 */
|
||||
if (msg == RT_NULL)
|
||||
{
|
||||
|
||||
+44
-43
File diff suppressed because it is too large.
Load diff
@@ -24,6 +24,7 @@
|
||||
* fix memory check in rt_realloc function
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -334,7 +335,7 @@ void *rt_malloc(rt_size_t size)
|
||||
*/
|
||||
mem->used = 1;
|
||||
#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)
|
||||
max_mem = used_mem;
|
||||
#endif
|
||||
@@ -354,7 +355,7 @@ 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_uint32_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
||||
("allocate memory at 0x%x, size: %d\n",
|
||||
@@ -400,6 +401,11 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
else if (newsize == 0)
|
||||
{
|
||||
rt_free(rmem);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* allocate a new memory block */
|
||||
if (rmem == RT_NULL)
|
||||
@@ -437,7 +443,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
|
||||
|
||||
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
|
||||
mem2 = (struct heap_mem *)&heap_ptr[ptr2];
|
||||
mem2->magic= HEAP_MAGIC;
|
||||
mem2->magic = HEAP_MAGIC;
|
||||
mem2->used = 0;
|
||||
mem2->next = mem->next;
|
||||
mem2->prev = ptr;
|
||||
@@ -510,7 +516,7 @@ void rt_free(void *rmem)
|
||||
|
||||
if (rmem == RT_NULL)
|
||||
return;
|
||||
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
|
||||
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
|
||||
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
|
||||
|
||||
@@ -550,7 +556,7 @@ void rt_free(void *rmem)
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
/* finally, see if prev or next are free also */
|
||||
@@ -589,4 +595,3 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
|
||||
|
||||
#endif /* end of RT_USING_HEAP */
|
||||
#endif /* end of RT_USING_MEMHEAP_AS_HEAP */
|
||||
|
||||
+8
-8
@@ -96,7 +96,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
|
||||
item->prev_free = 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;
|
||||
|
||||
/* block list header */
|
||||
@@ -315,10 +315,10 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
|
||||
header_ptr = (struct rt_memheap_item *)
|
||||
((rt_uint8_t *)ptr - RT_MEMHEAP_SIZE);
|
||||
oldsize = MEMITEM_SIZE(header_ptr);
|
||||
/* re-allocate memory */
|
||||
/* re-allocate memory */
|
||||
if (newsize > oldsize)
|
||||
{
|
||||
void* new_ptr;
|
||||
void *new_ptr;
|
||||
struct rt_memheap_item *next_ptr;
|
||||
|
||||
/* lock memheap */
|
||||
@@ -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;
|
||||
|
||||
/* 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,
|
||||
("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)
|
||||
rt_sem_release(&(heap->lock));
|
||||
|
||||
/* 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)
|
||||
{
|
||||
rt_memcpy(new_ptr, ptr, oldsize < newsize ? oldsize : newsize);
|
||||
@@ -503,8 +503,8 @@ void rt_memheap_free(void *ptr)
|
||||
struct rt_memheap_item *header_ptr, *new_ptr;
|
||||
rt_uint32_t insert_header;
|
||||
|
||||
/* NULL check */
|
||||
if (ptr == RT_NULL) return;
|
||||
/* NULL check */
|
||||
if (ptr == RT_NULL) return;
|
||||
|
||||
/* set initial status as OK */
|
||||
insert_header = 1;
|
||||
@@ -610,7 +610,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||
|
||||
void *rt_malloc(rt_size_t size)
|
||||
{
|
||||
void* ptr;
|
||||
void *ptr;
|
||||
|
||||
/* try to allocate in system heap */
|
||||
ptr = rt_memheap_alloc(&_heap, size);
|
||||
|
||||
+2
-2
@@ -299,8 +299,8 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
|
||||
else
|
||||
#endif
|
||||
|
||||
/* release allocated room */
|
||||
rt_free(mp->start_address);
|
||||
/* release allocated room */
|
||||
rt_free(mp->start_address);
|
||||
|
||||
/* detach object */
|
||||
rt_object_delete(&(mp->parent));
|
||||
|
||||
+58
-46
File diff suppressed because it is too large.
Load diff
@@ -208,6 +208,13 @@ typedef struct
|
||||
#define R_ARM_THM_JUMP24 30
|
||||
#define R_ARM_V4BX 40
|
||||
|
||||
/*
|
||||
* Relocation type for arm
|
||||
*/
|
||||
#define R_386_GLOB_DAT 6
|
||||
#define R_386_JUMP_SLOT 7
|
||||
#define R_386_RELATIVE 8
|
||||
|
||||
/* Program Header */
|
||||
typedef struct
|
||||
{
|
||||
|
||||
+7
-7
@@ -211,7 +211,7 @@ void rt_object_init(struct rt_object *object,
|
||||
#ifdef RT_USING_MODULE
|
||||
/* get module object information */
|
||||
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
|
||||
/* get object information */
|
||||
information = &rt_object_container[type];
|
||||
@@ -362,8 +362,8 @@ void rt_object_delete(rt_object_t object)
|
||||
else
|
||||
#endif
|
||||
|
||||
/* free the memory of object */
|
||||
RT_KERNEL_FREE(object);
|
||||
/* free the memory of object */
|
||||
RT_KERNEL_FREE(object);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -424,7 +424,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
|
||||
|
||||
if (*name_ptr == '/')
|
||||
{
|
||||
struct rt_module* module = RT_NULL;
|
||||
struct rt_module *module = RT_NULL;
|
||||
|
||||
/* get the name length of module */
|
||||
module_name_length = name_ptr - name;
|
||||
@@ -435,15 +435,15 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
|
||||
/* find module */
|
||||
information = &rt_object_container[RT_Object_Class_Module];
|
||||
for (node = information->object_list.next;
|
||||
node != &(information->object_list);
|
||||
node = node->next)
|
||||
node != &(information->object_list);
|
||||
node = node->next)
|
||||
{
|
||||
object = rt_list_entry(node, struct rt_object, list);
|
||||
if ((rt_strncmp(object->name, name, module_name_length) == 0) &&
|
||||
(module_name_length == RT_NAME_MAX || object->name[module_name_length] == '\0'))
|
||||
{
|
||||
/* get module */
|
||||
module = (struct rt_module*)object;
|
||||
module = (struct rt_module *)object;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -42,7 +42,7 @@
|
||||
|
||||
static rt_int16_t rt_scheduler_lock_nest;
|
||||
extern volatile rt_uint8_t rt_interrupt_nest;
|
||||
extern int __rt_ffs(int value);
|
||||
extern rt_ubase_t __rt_ffs(rt_ubase_t value);
|
||||
|
||||
rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
|
||||
struct rt_thread *rt_current_thread;
|
||||
@@ -90,19 +90,19 @@ 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->sp >
|
||||
(rt_uint32_t)thread->stack_addr + (rt_uint32_t)thread->stack_size)
|
||||
{
|
||||
rt_uint32_t level;
|
||||
|
||||
rt_kprintf("thread:%s stack overflow\n", thread->name);
|
||||
#ifdef RT_USING_FINSH
|
||||
#ifdef RT_USING_FINSH
|
||||
{
|
||||
extern long list_thread(void);
|
||||
list_thread();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
level = rt_hw_interrupt_disable();
|
||||
while (level);
|
||||
}
|
||||
|
||||
+17
-17
@@ -222,8 +222,8 @@ static int zone_page_cnt;
|
||||
#define PAGE_TYPE_LARGE 0x02
|
||||
struct memusage
|
||||
{
|
||||
rt_uint32_t type:2 ; /* page type */
|
||||
rt_uint32_t size:30; /* pages allocated or offset from zone */
|
||||
rt_uint32_t type: 2 ; /* page type */
|
||||
rt_uint32_t size: 30; /* pages allocated or offset from zone */
|
||||
};
|
||||
static struct memusage *memusage = RT_NULL;
|
||||
#define btokup(addr) \
|
||||
@@ -238,7 +238,7 @@ struct rt_page_head
|
||||
rt_size_t page; /* number of page */
|
||||
|
||||
/* 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_semaphore heap_sem;
|
||||
@@ -248,7 +248,7 @@ void *rt_page_alloc(rt_size_t npages)
|
||||
struct rt_page_head *b, *n;
|
||||
struct rt_page_head **prev;
|
||||
|
||||
if(npages == 0)
|
||||
if (npages == 0)
|
||||
return RT_NULL;
|
||||
|
||||
/* lock heap */
|
||||
@@ -383,7 +383,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||
|
||||
/* calculate 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_limit = zone_size / 4;
|
||||
@@ -398,7 +398,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||
/* allocate memusage array */
|
||||
limsize = npages * sizeof(struct memusage);
|
||||
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_uint32_t)memusage, limsize));
|
||||
@@ -411,20 +411,20 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||
rt_inline int zoneindex(rt_uint32_t *bytes)
|
||||
{
|
||||
/* unsigned for shift opt */
|
||||
rt_uint32_t n = (rt_uint32_t)*bytes;
|
||||
rt_uint32_t n = (rt_uint32_t) * bytes;
|
||||
|
||||
if (n < 128)
|
||||
{
|
||||
*bytes = n = (n + 7) & ~7;
|
||||
|
||||
/* 8 byte chunks, 16 zones */
|
||||
return(n / 8 - 1);
|
||||
return (n / 8 - 1);
|
||||
}
|
||||
if (n < 256)
|
||||
{
|
||||
*bytes = n = (n + 15) & ~15;
|
||||
|
||||
return(n / 16 + 7);
|
||||
return (n / 16 + 7);
|
||||
}
|
||||
if (n < 8192)
|
||||
{
|
||||
@@ -432,35 +432,35 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
|
||||
{
|
||||
*bytes = n = (n + 31) & ~31;
|
||||
|
||||
return(n / 32 + 15);
|
||||
return (n / 32 + 15);
|
||||
}
|
||||
if (n < 1024)
|
||||
{
|
||||
*bytes = n = (n + 63) & ~63;
|
||||
|
||||
return(n / 64 + 23);
|
||||
return (n / 64 + 23);
|
||||
}
|
||||
if (n < 2048)
|
||||
{
|
||||
*bytes = n = (n + 127) & ~127;
|
||||
|
||||
return(n / 128 + 31);
|
||||
return (n / 128 + 31);
|
||||
}
|
||||
if (n < 4096)
|
||||
{
|
||||
*bytes = n = (n + 255) & ~255;
|
||||
|
||||
return(n / 256 + 39);
|
||||
return (n / 256 + 39);
|
||||
}
|
||||
*bytes = n = (n + 511) & ~511;
|
||||
|
||||
return(n / 512 + 47);
|
||||
return (n / 512 + 47);
|
||||
}
|
||||
if (n < 16384)
|
||||
{
|
||||
*bytes = n = (n + 1023) & ~1023;
|
||||
|
||||
return(n / 1024 + 55);
|
||||
return (n / 1024 + 55);
|
||||
}
|
||||
|
||||
rt_kprintf("Unexpected byte count %d", n);
|
||||
@@ -737,7 +737,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
|
||||
|
||||
zoneindex(&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
|
||||
@@ -803,7 +803,7 @@ void rt_free(void *ptr)
|
||||
RT_OBJECT_HOOK_CALL(rt_free_hook, (ptr));
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
if(rt_module_self() != RT_NULL)
|
||||
if (rt_module_self() != RT_NULL)
|
||||
{
|
||||
rt_module_free(rt_module_self(), ptr);
|
||||
|
||||
|
||||
+15
-9
@@ -55,7 +55,7 @@ static void (*rt_thread_inited_hook) (rt_thread_t thread);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
@@ -68,7 +68,7 @@ void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
@@ -81,13 +81,13 @@ void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
|
||||
{
|
||||
rt_thread_inited_hook = hook;
|
||||
rt_thread_inited_hook = hook;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -151,14 +151,20 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
|
||||
/* init thread stack */
|
||||
rt_memset(thread->stack_addr, '#', thread->stack_size);
|
||||
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
|
||||
(void *)((char *)thread->stack_addr + thread->stack_size - 4),
|
||||
(void *)rt_thread_exit);
|
||||
(void *)((char *)thread->stack_addr + thread->stack_size - 4),
|
||||
(void *)rt_thread_exit);
|
||||
|
||||
/* priority init */
|
||||
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
|
||||
thread->init_priority = priority;
|
||||
thread->current_priority = priority;
|
||||
|
||||
thread->number_mask = 0;
|
||||
#if RT_THREAD_PRIORITY_MAX > 32
|
||||
thread->number = 0;
|
||||
thread->high_mask = 0;
|
||||
#endif
|
||||
|
||||
/* tick init */
|
||||
thread->init_tick = tick;
|
||||
thread->remaining_tick = tick;
|
||||
@@ -179,7 +185,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
|
||||
0,
|
||||
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;
|
||||
}
|
||||
@@ -637,7 +643,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
|
||||
/* enable interrupt */
|
||||
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;
|
||||
}
|
||||
RTM_EXPORT(rt_thread_suspend);
|
||||
@@ -680,7 +686,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
|
||||
/* insert to schedule ready list */
|
||||
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;
|
||||
}
|
||||
RTM_EXPORT(rt_thread_resume);
|
||||
|
||||
+30
-30
@@ -28,7 +28,7 @@
|
||||
* 2010-05-12 Bernard fix the timer check bug.
|
||||
* 2010-11-02 Charlie re-implement tick overflow issue
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -147,13 +147,13 @@ void rt_timer_dump(rt_list_t timer_heads[])
|
||||
{
|
||||
rt_list_t *list;
|
||||
|
||||
for (list = timer_heads[RT_TIMER_SKIP_LIST_LEVEL-1].next;
|
||||
list != &timer_heads[RT_TIMER_SKIP_LIST_LEVEL-1];
|
||||
for (list = timer_heads[RT_TIMER_SKIP_LIST_LEVEL - 1].next;
|
||||
list != &timer_heads[RT_TIMER_SKIP_LIST_LEVEL - 1];
|
||||
list = list->next)
|
||||
{
|
||||
struct rt_timer *timer = rt_list_entry(list,
|
||||
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("\n");
|
||||
@@ -303,9 +303,9 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
/* timer check */
|
||||
RT_ASSERT(timer != RT_NULL);
|
||||
|
||||
/* stop timer firstly */
|
||||
level = rt_hw_interrupt_disable();
|
||||
/* remove timer from list */
|
||||
/* stop timer firstly */
|
||||
level = rt_hw_interrupt_disable();
|
||||
/* remove timer from list */
|
||||
_rt_timer_remove(timer);
|
||||
/* change status of timer */
|
||||
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
|
||||
@@ -339,7 +339,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
row_head[0] = &timer_list[0];
|
||||
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)
|
||||
{
|
||||
struct rt_timer *t;
|
||||
@@ -363,7 +363,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
}
|
||||
}
|
||||
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
|
||||
@@ -373,8 +373,8 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
random_nr++;
|
||||
tst_nr = random_nr;
|
||||
|
||||
rt_list_insert_after(row_head[RT_TIMER_SKIP_LIST_LEVEL-1],
|
||||
&(timer->row[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]));
|
||||
for (row_lvl = 2; row_lvl <= RT_TIMER_SKIP_LIST_LEVEL; row_lvl++)
|
||||
{
|
||||
if (!(tst_nr & RT_TIMER_SKIP_LIST_MASK))
|
||||
@@ -384,7 +384,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
break;
|
||||
/* Shift over the bits we have tested. Works well with 1 bit and 2
|
||||
* 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;
|
||||
@@ -498,7 +498,7 @@ void rt_timer_check(void)
|
||||
/* disable interrupt */
|
||||
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,
|
||||
struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
|
||||
@@ -507,7 +507,7 @@ void rt_timer_check(void)
|
||||
* It supposes that the new tick shall less than the half duration of
|
||||
* 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));
|
||||
|
||||
@@ -570,13 +570,13 @@ void rt_soft_timer_check(void)
|
||||
|
||||
current_tick = rt_tick_get();
|
||||
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
|
||||
for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1].next;
|
||||
n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]);)
|
||||
for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next;
|
||||
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
|
||||
@@ -592,8 +592,8 @@ void rt_soft_timer_check(void)
|
||||
/* remove timer from timer list firstly */
|
||||
_rt_timer_remove(t);
|
||||
|
||||
/* not lock scheduler when performing timeout function */
|
||||
rt_exit_critical();
|
||||
/* not lock scheduler when performing timeout function */
|
||||
rt_exit_critical();
|
||||
/* call timeout function */
|
||||
t->timeout_func(t->parameter);
|
||||
|
||||
@@ -602,8 +602,8 @@ void rt_soft_timer_check(void)
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
|
||||
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
|
||||
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
|
||||
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
|
||||
@@ -621,8 +621,8 @@ void rt_soft_timer_check(void)
|
||||
else break; /* not check anymore */
|
||||
}
|
||||
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
|
||||
}
|
||||
@@ -649,7 +649,7 @@ static void rt_thread_timer_entry(void *parameter)
|
||||
/* get current tick */
|
||||
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 */
|
||||
next_timeout = next_timeout - current_tick;
|
||||
@@ -672,9 +672,9 @@ void rt_system_timer_init(void)
|
||||
{
|
||||
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)
|
||||
int i;
|
||||
|
||||
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++)
|
||||
{
|
||||
rt_list_init(rt_soft_timer_list+i);
|
||||
rt_list_init(rt_soft_timer_list + i);
|
||||
}
|
||||
|
||||
/* start software timer thread */
|
||||
|
||||
Reference in new issue
Block a user