Merge branch 'master' into RT_MACRO

This commit is contained in:
geniusgogo 2017-09-18 16:27:20 +08:00 committed by GitHub
commit 2aae989f40
15 changed files with 226 additions and 225 deletions

View File

@ -976,7 +976,7 @@ struct rt_module
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

View File

@ -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);
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);
#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);
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);
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 */
/**@}*/ /**@}*/

View File

@ -155,7 +155,7 @@ 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.

View File

@ -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;
} }
@ -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();
} }

View File

@ -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);
@ -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)
{ {

View File

@ -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;
} }
@ -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)
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,
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,
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,
#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,
++ 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,
/* 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;
} }
@ -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, ...)
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);
* *
* @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;
@ -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)
#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,7 +1302,7 @@ 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;
@ -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")));

View File

@ -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)
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)
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)
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)
} }
#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 */

View File

@ -318,7 +318,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
/* 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)
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)
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);
@ -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);

View File

@ -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))
@ -622,7 +622,7 @@ 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;
@ -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,
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,
} }
#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[])
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[])
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[])
} }
/* 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)
} }
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;
@ -960,7 +960,7 @@ static void module_main_entry(void* parameter)
*/ */
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,
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)
#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)
/* 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)
* *
* @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)
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,
} }
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;
@ -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));
@ -1922,7 +1922,7 @@ 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)
{ {
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);

View File

@ -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;
@ -443,7 +443,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
(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;
} }
} }

View File

@ -97,12 +97,12 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
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);
} }

View File

@ -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
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)
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)
/* 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)
/* 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)
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)
{ {
*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)
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)
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);

View File

@ -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)
/* 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)
/* 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);

View File

@ -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");
@ -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)
} }
} }
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)
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)
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)
/* 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)
* 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));
@ -573,10 +573,10 @@ void rt_soft_timer_check(void)
/* 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
@ -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)
{ {
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)
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 */