fix code style
This commit is contained in:
parent
ef0d5ed3cd
commit
2340408e3c
|
@ -222,15 +222,15 @@ void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
|
||||||
char *tmp = (char *)dst, *s = (char *)src;
|
char *tmp = (char *)dst, *s = (char *)src;
|
||||||
rt_ubase_t len;
|
rt_ubase_t len;
|
||||||
|
|
||||||
if(tmp <= s || tmp > (s + count))
|
if (tmp <= s || tmp > (s + count))
|
||||||
{
|
{
|
||||||
while (count--)
|
while (count--)
|
||||||
*tmp ++ = *s ++;
|
*tmp ++ = *s ++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(len = count; len > 0; len --)
|
for (len = count; len > 0; len --)
|
||||||
tmp[len -1] = s[len - 1];
|
tmp[len - 1] = s[len - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
|
|
22
src/mem.c
22
src/mem.c
|
@ -237,9 +237,9 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||||
mem->next = mem_size_aligned + SIZEOF_STRUCT_MEM;
|
mem->next = mem_size_aligned + SIZEOF_STRUCT_MEM;
|
||||||
mem->prev = 0;
|
mem->prev = 0;
|
||||||
mem->used = 0;
|
mem->used = 0;
|
||||||
#ifdef RT_USING_MEMTRACE
|
#ifdef RT_USING_MEMTRACE
|
||||||
rt_mem_setname(mem, "INIT");
|
rt_mem_setname(mem, "INIT");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* initialize the end of the heap */
|
/* initialize the end of the heap */
|
||||||
heap_end = (struct heap_mem *)&heap_ptr[mem->next];
|
heap_end = (struct heap_mem *)&heap_ptr[mem->next];
|
||||||
|
@ -247,9 +247,9 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||||
heap_end->used = 1;
|
heap_end->used = 1;
|
||||||
heap_end->next = mem_size_aligned + SIZEOF_STRUCT_MEM;
|
heap_end->next = mem_size_aligned + SIZEOF_STRUCT_MEM;
|
||||||
heap_end->prev = mem_size_aligned + SIZEOF_STRUCT_MEM;
|
heap_end->prev = mem_size_aligned + SIZEOF_STRUCT_MEM;
|
||||||
#ifdef RT_USING_MEMTRACE
|
#ifdef RT_USING_MEMTRACE
|
||||||
rt_mem_setname(heap_end, "INIT");
|
rt_mem_setname(heap_end, "INIT");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
|
rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
|
||||||
|
|
||||||
|
@ -335,9 +335,9 @@ void *rt_malloc(rt_size_t size)
|
||||||
mem2->used = 0;
|
mem2->used = 0;
|
||||||
mem2->next = mem->next;
|
mem2->next = mem->next;
|
||||||
mem2->prev = ptr;
|
mem2->prev = ptr;
|
||||||
#ifdef RT_USING_MEMTRACE
|
#ifdef RT_USING_MEMTRACE
|
||||||
rt_mem_setname(mem2, " ");
|
rt_mem_setname(mem2, " ");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* and insert it between mem and mem->next */
|
/* and insert it between mem and mem->next */
|
||||||
mem->next = ptr2;
|
mem->next = ptr2;
|
||||||
|
@ -371,12 +371,12 @@ void *rt_malloc(rt_size_t size)
|
||||||
}
|
}
|
||||||
/* set memory block magic */
|
/* set memory block magic */
|
||||||
mem->magic = HEAP_MAGIC;
|
mem->magic = HEAP_MAGIC;
|
||||||
#ifdef RT_USING_MEMTRACE
|
#ifdef RT_USING_MEMTRACE
|
||||||
if (rt_thread_self())
|
if (rt_thread_self())
|
||||||
rt_mem_setname(mem, rt_thread_self()->name);
|
rt_mem_setname(mem, rt_thread_self()->name);
|
||||||
else
|
else
|
||||||
rt_mem_setname(mem, "NONE");
|
rt_mem_setname(mem, "NONE");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mem == lfree)
|
if (mem == lfree)
|
||||||
{
|
{
|
||||||
|
@ -642,7 +642,7 @@ int memcheck(void)
|
||||||
rt_uint32_t level;
|
rt_uint32_t level;
|
||||||
struct heap_mem *mem;
|
struct heap_mem *mem;
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
for (mem = (struct heap_mem*)heap_ptr; mem != heap_end; mem = (struct heap_mem*)&heap_ptr[mem->next])
|
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_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
||||||
if (position < 0) goto __exit;
|
if (position < 0) goto __exit;
|
||||||
|
@ -665,7 +665,7 @@ __exit:
|
||||||
}
|
}
|
||||||
MSH_CMD_EXPORT(memcheck, check memory data);
|
MSH_CMD_EXPORT(memcheck, check memory data);
|
||||||
|
|
||||||
int memtrace(int argc, char** argv)
|
int memtrace(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct heap_mem *mem;
|
struct heap_mem *mem;
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ int memtrace(int argc, char** argv)
|
||||||
rt_kprintf("heap_end: 0x%08x\n", heap_end);
|
rt_kprintf("heap_end: 0x%08x\n", heap_end);
|
||||||
|
|
||||||
rt_kprintf("\n--memory item information --\n");
|
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])
|
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_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
||||||
int size;
|
int size;
|
||||||
|
|
95
src/signal.c
95
src/signal.c
|
@ -31,7 +31,7 @@
|
||||||
#ifdef RT_USING_SIGNALS
|
#ifdef RT_USING_SIGNALS
|
||||||
|
|
||||||
#ifndef RT_SIG_INFO_MAX
|
#ifndef RT_SIG_INFO_MAX
|
||||||
#define RT_SIG_INFO_MAX 32
|
#define RT_SIG_INFO_MAX 32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// #define DBG_ENABLE
|
// #define DBG_ENABLE
|
||||||
|
@ -59,7 +59,7 @@ static void _signal_default_handler(int signo)
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _signal_entry(void* parameter)
|
static void _signal_entry(void *parameter)
|
||||||
{
|
{
|
||||||
rt_thread_t tid = rt_thread_self();
|
rt_thread_t tid = rt_thread_self();
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ static void _signal_entry(void* parameter)
|
||||||
/* handle signal */
|
/* handle signal */
|
||||||
rt_thread_handle_sig(RT_FALSE);
|
rt_thread_handle_sig(RT_FALSE);
|
||||||
|
|
||||||
/* never come back... */
|
/* never come back... */
|
||||||
rt_hw_interrupt_disable();
|
rt_hw_interrupt_disable();
|
||||||
/* return to thread */
|
/* return to thread */
|
||||||
tid->sp = tid->sig_ret;
|
tid->sp = tid->sig_ret;
|
||||||
tid->sig_ret = RT_NULL;
|
tid->sig_ret = RT_NULL;
|
||||||
|
@ -77,7 +77,7 @@ static void _signal_entry(void* parameter)
|
||||||
dbg_log(DBG_LOG, "switch back to: 0x%08x\n", tid->sp);
|
dbg_log(DBG_LOG, "switch back to: 0x%08x\n", tid->sp);
|
||||||
tid->stat &= ~RT_THREAD_STAT_SIGNAL;
|
tid->stat &= ~RT_THREAD_STAT_SIGNAL;
|
||||||
|
|
||||||
rt_hw_context_switch_to((rt_uint32_t)&(tid->sp));
|
rt_hw_context_switch_to((rt_uint32_t) & (tid->sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _signal_deliver(rt_thread_t tid)
|
static void _signal_deliver(rt_thread_t tid)
|
||||||
|
@ -92,8 +92,8 @@ static void _signal_deliver(rt_thread_t tid)
|
||||||
{
|
{
|
||||||
/* resume thread to handle signal */
|
/* resume thread to handle signal */
|
||||||
rt_thread_resume(tid);
|
rt_thread_resume(tid);
|
||||||
/* add signal state */
|
/* add signal state */
|
||||||
tid->stat |= RT_THREAD_STAT_SIGNAL;
|
tid->stat |= RT_THREAD_STAT_SIGNAL;
|
||||||
|
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
|
@ -104,8 +104,8 @@ static void _signal_deliver(rt_thread_t tid)
|
||||||
{
|
{
|
||||||
if (tid == rt_thread_self())
|
if (tid == rt_thread_self())
|
||||||
{
|
{
|
||||||
/* add signal state */
|
/* add signal state */
|
||||||
tid->stat |= RT_THREAD_STAT_SIGNAL;
|
tid->stat |= RT_THREAD_STAT_SIGNAL;
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
/* do signal action in self thread context */
|
/* do signal action in self thread context */
|
||||||
|
@ -116,8 +116,8 @@ static void _signal_deliver(rt_thread_t tid)
|
||||||
tid->stat |= RT_THREAD_STAT_SIGNAL;
|
tid->stat |= RT_THREAD_STAT_SIGNAL;
|
||||||
/* point to the signal handle entry */
|
/* point to the signal handle entry */
|
||||||
tid->sig_ret = tid->sp;
|
tid->sig_ret = tid->sp;
|
||||||
tid->sp = rt_hw_stack_init((void*)_signal_entry, RT_NULL,
|
tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL,
|
||||||
(void *)((char *)tid->sig_ret - 32), RT_NULL);
|
(void *)((char *)tid->sig_ret - 32), RT_NULL);
|
||||||
|
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
dbg_log(DBG_LOG, "signal stack pointer @ 0x%08x\n", tid->sp);
|
dbg_log(DBG_LOG, "signal stack pointer @ 0x%08x\n", tid->sp);
|
||||||
|
@ -137,7 +137,7 @@ rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler)
|
||||||
rt_sighandler_t old;
|
rt_sighandler_t old;
|
||||||
rt_thread_t tid = rt_thread_self();
|
rt_thread_t tid = rt_thread_self();
|
||||||
|
|
||||||
if (!sig_valid(signo)) return SIG_ERR;
|
if (!sig_valid(signo)) return SIG_ERR;
|
||||||
|
|
||||||
rt_enter_critical();
|
rt_enter_critical();
|
||||||
if (tid->sig_vectors == RT_NULL)
|
if (tid->sig_vectors == RT_NULL)
|
||||||
|
@ -193,34 +193,34 @@ void rt_signal_unmask(int signo)
|
||||||
|
|
||||||
void rt_thread_handle_sig(rt_bool_t clean_state)
|
void rt_thread_handle_sig(rt_bool_t clean_state)
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
|
|
||||||
rt_thread_t tid = rt_thread_self();
|
rt_thread_t tid = rt_thread_self();
|
||||||
struct siginfo_node *si_node;
|
struct siginfo_node *si_node;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
while (tid->sig_pending & tid->sig_mask)
|
while (tid->sig_pending & tid->sig_mask)
|
||||||
{
|
{
|
||||||
int signo, error;
|
int signo, error;
|
||||||
rt_sighandler_t handler;
|
rt_sighandler_t handler;
|
||||||
|
|
||||||
si_node = (struct siginfo_node *)tid->si_list;
|
si_node = (struct siginfo_node *)tid->si_list;
|
||||||
if (!si_node) break;
|
if (!si_node) break;
|
||||||
|
|
||||||
/* remove this sig info node from list */
|
/* remove this sig info node from list */
|
||||||
if (si_node->list.next == RT_NULL)
|
if (si_node->list.next == RT_NULL)
|
||||||
tid->si_list = RT_NULL;
|
tid->si_list = RT_NULL;
|
||||||
else
|
else
|
||||||
tid->si_list = (void*)rt_slist_entry(si_node->list.next, struct siginfo_node, list);
|
tid->si_list = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list);
|
||||||
|
|
||||||
signo = si_node->si.si_signo;
|
signo = si_node->si.si_signo;
|
||||||
handler = tid->sig_vectors[signo];
|
handler = tid->sig_vectors[signo];
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
dbg_log(DBG_LOG, "handle signal: %d, handler 0x%08x\n", signo, handler);
|
dbg_log(DBG_LOG, "handle signal: %d, handler 0x%08x\n", signo, handler);
|
||||||
if (handler) handler(signo);
|
if (handler) handler(signo);
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
tid->sig_pending &= ~sig_mask(signo);
|
tid->sig_pending &= ~sig_mask(signo);
|
||||||
error = si_node->si.si_errno;
|
error = si_node->si.si_errno;
|
||||||
|
|
||||||
|
@ -229,10 +229,10 @@ void rt_thread_handle_sig(rt_bool_t clean_state)
|
||||||
tid->error = error;
|
tid->error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* whether clean signal status */
|
/* whether clean signal status */
|
||||||
if (clean_state == RT_TRUE) tid->stat &= ~RT_THREAD_STAT_SIGNAL;
|
if (clean_state == RT_TRUE) tid->stat &= ~RT_THREAD_STAT_SIGNAL;
|
||||||
|
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rt_thread_alloc_sig(rt_thread_t tid)
|
void rt_thread_alloc_sig(rt_thread_t tid)
|
||||||
|
@ -261,7 +261,7 @@ void rt_thread_free_sig(rt_thread_t tid)
|
||||||
rt_sighandler_t *sig_vectors;
|
rt_sighandler_t *sig_vectors;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
si_list = (struct siginfo_node*)tid->si_list;
|
si_list = (struct siginfo_node *)tid->si_list;
|
||||||
tid->si_list = RT_NULL;
|
tid->si_list = RT_NULL;
|
||||||
|
|
||||||
sig_vectors = tid->sig_vectors;
|
sig_vectors = tid->sig_vectors;
|
||||||
|
@ -275,7 +275,8 @@ void rt_thread_free_sig(rt_thread_t tid)
|
||||||
|
|
||||||
dbg_log(DBG_LOG, "free signal info list\n");
|
dbg_log(DBG_LOG, "free signal info list\n");
|
||||||
node = &(si_list->list);
|
node = &(si_list->list);
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
si_node = rt_slist_entry(node, struct siginfo_node, list);
|
si_node = rt_slist_entry(node, struct siginfo_node, list);
|
||||||
rt_mp_free(si_node);
|
rt_mp_free(si_node);
|
||||||
|
|
||||||
|
@ -292,8 +293,8 @@ void rt_thread_free_sig(rt_thread_t tid)
|
||||||
int rt_thread_kill(rt_thread_t tid, int sig)
|
int rt_thread_kill(rt_thread_t tid, int sig)
|
||||||
{
|
{
|
||||||
siginfo_t si;
|
siginfo_t si;
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
struct siginfo_node *si_node;
|
struct siginfo_node *si_node;
|
||||||
|
|
||||||
RT_ASSERT(tid != RT_NULL);
|
RT_ASSERT(tid != RT_NULL);
|
||||||
if (!sig_valid(sig)) return -RT_EINVAL;
|
if (!sig_valid(sig)) return -RT_EINVAL;
|
||||||
|
@ -304,56 +305,56 @@ int rt_thread_kill(rt_thread_t tid, int sig)
|
||||||
si.si_code = SI_USER;
|
si.si_code = SI_USER;
|
||||||
si.si_value.sival_ptr = RT_NULL;
|
si.si_value.sival_ptr = RT_NULL;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
if (tid->sig_pending & sig_mask(sig))
|
if (tid->sig_pending & sig_mask(sig))
|
||||||
{
|
{
|
||||||
/* whether already emits this signal? */
|
/* whether already emits this signal? */
|
||||||
struct rt_slist_node *node;
|
struct rt_slist_node *node;
|
||||||
struct siginfo_node *entry;
|
struct siginfo_node *entry;
|
||||||
|
|
||||||
node = (struct rt_slist_node *)tid->si_list;
|
node = (struct rt_slist_node *)tid->si_list;
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
/* update sig infor */
|
/* update sig infor */
|
||||||
rt_enter_critical();
|
rt_enter_critical();
|
||||||
for (; (node) != RT_NULL; node = node->next)
|
for (; (node) != RT_NULL; node = node->next)
|
||||||
{
|
{
|
||||||
entry = rt_slist_entry(node, struct siginfo_node, list);
|
entry = rt_slist_entry(node, struct siginfo_node, list);
|
||||||
if (entry->si.si_signo == sig)
|
if (entry->si.si_signo == sig)
|
||||||
{
|
{
|
||||||
memcpy(&(entry->si), &si, sizeof(siginfo_t));
|
memcpy(&(entry->si), &si, sizeof(siginfo_t));
|
||||||
rt_exit_critical();
|
rt_exit_critical();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rt_exit_critical();
|
rt_exit_critical();
|
||||||
|
|
||||||
/* disable interrupt to protect tcb */
|
/* disable interrupt to protect tcb */
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* a new signal */
|
/* a new signal */
|
||||||
tid->sig_pending |= sig_mask(sig);
|
tid->sig_pending |= sig_mask(sig);
|
||||||
}
|
}
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
si_node = (struct siginfo_node*) rt_mp_alloc(_rt_siginfo_pool, 0);
|
si_node = (struct siginfo_node *) rt_mp_alloc(_rt_siginfo_pool, 0);
|
||||||
if (si_node)
|
if (si_node)
|
||||||
{
|
{
|
||||||
rt_slist_init(&(si_node->list));
|
rt_slist_init(&(si_node->list));
|
||||||
memcpy(&(si_node->si), &si, sizeof(siginfo_t));
|
memcpy(&(si_node->si), &si, sizeof(siginfo_t));
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
if (!tid->si_list) tid->si_list = si_node;
|
if (!tid->si_list) tid->si_list = si_node;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct siginfo_node *si_list;
|
struct siginfo_node *si_list;
|
||||||
|
|
||||||
si_list = (struct siginfo_node*)tid->si_list;
|
si_list = (struct siginfo_node *)tid->si_list;
|
||||||
rt_slist_append(&(si_list->list), &(si_node->list));
|
rt_slist_append(&(si_list->list), &(si_node->list));
|
||||||
}
|
}
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue