From 02331fd30d1f1ca8c886aac4db6c8c111987913c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 17 May 2021 21:00:40 +0800 Subject: revert #3647 --- src/ipc.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 111d724c23..27ee92e3fd 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -38,7 +38,6 @@ * event without pending * 2020-10-11 Meco Man add value overflow-check code * 2021-01-03 Meco Man add rt_mb_urgent() - * 2021-01-20 hupu fix priority inversion bug of mutex */ #include @@ -192,31 +191,6 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) return RT_EOK; } -/** - * This function will get the highest priority from the specified - * list of threads - * - * @param list of the threads - * - * @return the highest priority - */ -rt_uint8_t rt_ipc_get_highest_priority(rt_list_t *list) -{ - struct rt_list_node *n; - struct rt_thread *sthread; - rt_uint8_t priority = RT_THREAD_PRIORITY_MAX - 1; - - for (n = list->next; n != list; n = n->next) - { - sthread = rt_list_entry(n, struct rt_thread, tlist); - - priority = priority < sthread->current_priority ? - priority : - sthread->current_priority; - } - return priority; -} - #ifdef RT_USING_SEMAPHORE /** * This function will initialize a semaphore and put it under control of @@ -855,7 +829,6 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) register rt_base_t temp; struct rt_thread *thread; rt_bool_t need_schedule; - rt_uint8_t max_priority_in_queue = RT_THREAD_PRIORITY_MAX - 1; /* parameter check */ RT_ASSERT(mutex != RT_NULL); @@ -917,21 +890,6 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) mutex->owner = thread; mutex->original_priority = thread->current_priority; - /* Priority adjustment occurs only when the following conditions - * are met simultaneously: - * 1.The type of mutex is RT_IPC_FLAG_FIFO; - * 2.The priority of the thread to be resumed is not equal to the - * highest priority in the queue; - */ - max_priority_in_queue = rt_ipc_get_highest_priority(&mutex->parent.suspend_thread); - if (mutex->parent.parent.flag == RT_IPC_FLAG_FIFO && - thread->current_priority != max_priority_in_queue) - { - rt_thread_control(thread, - RT_THREAD_CTRL_CHANGE_PRIORITY, - &(max_priority_in_queue)); - } - if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; -- cgit v1.3.1 From 37960723b8fe6c91d14c7c4c1c30a97d17e0033b Mon Sep 17 00:00:00 2001 From: geniusgogo Date: Fri, 28 May 2021 09:43:06 +0800 Subject: fix rt_tick_increase critical code protection --- src/clock.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 0880d8d241..8746d463c1 100644 --- a/src/clock.c +++ b/src/clock.c @@ -76,10 +76,14 @@ void rt_tick_increase(void) -- thread->remaining_tick; if (thread->remaining_tick == 0) { + rt_base_t level; + /* change to initialized tick */ thread->remaining_tick = thread->init_tick; + level = rt_hw_interrupt_disable(); thread->stat |= RT_THREAD_STAT_YIELD; + rt_hw_interrupt_enable(level); rt_schedule(); } -- cgit v1.3.1 From 039d7979d83666e96d7f6efb84255de0047e3e67 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 29 May 2021 17:30:18 +0800 Subject: [kernel][thread.c] 规范内部函数命名方式 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index e03c027eff..6304a4ebe6 100644 --- a/src/thread.c +++ b/src/thread.c @@ -79,7 +79,7 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread)) #endif /* must be invoke witch rt_hw_interrupt_disable */ -static void _thread_cleanup_execute(rt_thread_t thread) +static void _rt_thread_cleanup_execute(rt_thread_t thread) { register rt_base_t level; #ifdef RT_USING_MODULE @@ -103,7 +103,7 @@ static void _thread_cleanup_execute(rt_thread_t thread) rt_hw_interrupt_enable(level); } -void rt_thread_exit(void) +static void _rt_thread_exit(void) { struct rt_thread *thread; register rt_base_t level; @@ -114,7 +114,7 @@ void rt_thread_exit(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _thread_cleanup_execute(thread); + _rt_thread_cleanup_execute(thread); /* remove from schedule */ rt_schedule_remove_thread(thread); @@ -165,11 +165,11 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, #ifdef ARCH_CPU_STACK_GROWS_UPWARD thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, (void *)((char *)thread->stack_addr), - (void *)rt_thread_exit); + (void *)_rt_thread_exit); #else thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, (rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), - (void *)rt_thread_exit); + (void *)_rt_thread_exit); #endif /* priority init */ @@ -374,7 +374,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread) rt_schedule_remove_thread(thread); } - _thread_cleanup_execute(thread); + _rt_thread_cleanup_execute(thread); /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); @@ -472,7 +472,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) rt_schedule_remove_thread(thread); } - _thread_cleanup_execute(thread); + _rt_thread_cleanup_execute(thread); /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); -- cgit v1.3.1 From 2e11562772938ec253bb60123283d476da0bdd2e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 29 May 2021 19:10:48 +0800 Subject: [kernel][注释] 明确rt_schedule的调度时刻 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scheduler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/scheduler.c b/src/scheduler.c index c03c20d030..ed0f30fc81 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -404,7 +404,7 @@ __exit: #else /** * This function will perform one schedule. It will select one thread - * with the highest priority level, then switch to it. + * with the highest priority level, and switch to it immediately. */ void rt_schedule(void) { -- cgit v1.3.1 From 8b82b834826249dff299353da44188429d18dde2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 30 May 2021 11:43:44 +0800 Subject: [kernel] 增加rt_mutex_trytake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 1 + src/ipc.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/include/rtthread.h b/include/rtthread.h index 784b208a76..ccd2d147a8 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -322,6 +322,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag); rt_err_t rt_mutex_delete(rt_mutex_t mutex); rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time); +rt_err_t rt_mutex_trytake(rt_mutex_t mutex); rt_err_t rt_mutex_release(rt_mutex_t mutex); rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg); #endif diff --git a/src/ipc.c b/src/ipc.c index 22e0f06bc6..6cd38b74ab 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -37,7 +37,8 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add value overflow-check code - * 2021-01-03 Meco Man add rt_mb_urgent() + * 2021-01-03 Meco Man implement rt_mb_urgent() + * 2021-05-30 Meco Man implement rt_mutex_trytake() * 2021-01-20 hupu fix priority inversion bug of mutex */ @@ -452,7 +453,7 @@ RTM_EXPORT(rt_sem_take); */ rt_err_t rt_sem_trytake(rt_sem_t sem) { - return rt_sem_take(sem, 0); + return rt_sem_take(sem, RT_WAITING_NO); } RTM_EXPORT(rt_sem_trytake); @@ -843,6 +844,19 @@ __again: } RTM_EXPORT(rt_mutex_take); +/** + * This function will try to take a mutex and immediately return + * + * @param mutex the mutex object + * + * @return the error code + */ +rt_err_t rt_mutex_trytake(rt_mutex_t mutex) +{ + return rt_mutex_take(mutex, RT_WAITING_NO); +} +RTM_EXPORT(rt_mutex_trytake); + /** * This function will release a mutex, if there are threads suspended on mutex, * it will be waked up. -- cgit v1.3.1 From f34e9323b430813a6dbb62a609cfb3980aa645b0 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 1 Jun 2021 11:42:47 +0800 Subject: 对rt_tick_increase临界区进行保护 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 8746d463c1..045555933d 100644 --- a/src/clock.c +++ b/src/clock.c @@ -62,6 +62,9 @@ void rt_tick_set(rt_tick_t tick) void rt_tick_increase(void) { struct rt_thread *thread; + rt_base_t level; + + level = rt_hw_interrupt_disable(); /* increase the global tick */ #ifdef RT_USING_SMP @@ -76,17 +79,17 @@ void rt_tick_increase(void) -- thread->remaining_tick; if (thread->remaining_tick == 0) { - rt_base_t level; - /* change to initialized tick */ thread->remaining_tick = thread->init_tick; - - level = rt_hw_interrupt_disable(); thread->stat |= RT_THREAD_STAT_YIELD; - rt_hw_interrupt_enable(level); + rt_hw_interrupt_enable(level); rt_schedule(); } + else + { + rt_hw_interrupt_enable(level); + } /* check timer */ rt_timer_check(); -- cgit v1.3.1 From 8e8ae9c95183c4b0c7bf02b9f79a0b0c151cd7c8 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Thu, 3 Jun 2021 15:02:00 +0800 Subject: [src][memheap] Fix the crash problem after opening Oz optimization on ac6. --- src/memheap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/memheap.c b/src/memheap.c index 63327575cc..2cfdd73ad4 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -17,6 +17,7 @@ * 2013-05-24 Bernard fix the rt_memheap_realloc issue. * 2013-07-11 Grissiom fix the memory block splitting issue. * 2013-07-15 Grissiom optimize rt_memheap_realloc + * 2021-06-03 Flybreak Fix the crash problem after opening Oz optimization on ac6. */ #include @@ -369,7 +370,8 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize) if (newsize > oldsize) { void *new_ptr; - struct rt_memheap_item *next_ptr; + /* Fix the crash problem after opening Oz optimization on ac6 */ + volatile struct rt_memheap_item *next_ptr; /* lock memheap */ result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); @@ -441,14 +443,14 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize) next_ptr->prev = header_ptr; next_ptr->next = header_ptr->next; - header_ptr->next->prev = next_ptr; - header_ptr->next = next_ptr; + header_ptr->next->prev = (struct rt_memheap_item *)next_ptr; + header_ptr->next = (struct rt_memheap_item *)next_ptr; /* insert next_ptr to free list */ next_ptr->next_free = heap->free_list->next_free; next_ptr->prev_free = heap->free_list; - heap->free_list->next_free->prev_free = next_ptr; - heap->free_list->next_free = next_ptr; + heap->free_list->next_free->prev_free = (struct rt_memheap_item *)next_ptr; + heap->free_list->next_free = (struct rt_memheap_item *)next_ptr; RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("new ptr: next_free 0x%08x, prev_free 0x%08x", next_ptr->next_free, next_ptr->prev_free)); -- cgit v1.3.1 From 51ec75f71d7a0a74bba0fe979cba79c9732ccad1 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Thu, 3 Jun 2021 15:13:47 +0800 Subject: [update]format memheap.c --- src/memheap.c | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/memheap.c b/src/memheap.c index 2cfdd73ad4..35a04c14b1 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -42,31 +42,31 @@ rt_inline void rt_memheap_setname(struct rt_memheap_item *item, const char *name) { int index; - rt_uint8_t* ptr; + rt_uint8_t *ptr; - ptr = (rt_uint8_t*)&(item->next_free); - for (index = 0; index < sizeof(void*); index ++) + ptr = (rt_uint8_t *) & (item->next_free); + for (index = 0; index < sizeof(void *); index ++) { if (name[index] == '\0') break; ptr[index] = name[index]; } if (name[index] == '\0') ptr[index] = '\0'; - else + else { - ptr = (rt_uint8_t*)&(item->prev_free); - for (index = 0; index < sizeof(void*) && (index + sizeof(void*))< RT_NAME_MAX; index ++) + ptr = (rt_uint8_t *) & (item->prev_free); + for (index = 0; index < sizeof(void *) && (index + sizeof(void *)) < RT_NAME_MAX; index ++) { - if (name[sizeof(void*) + index] == '\0') break; - ptr[index] = name[sizeof(void*) + index]; + if (name[sizeof(void *) + index] == '\0') break; + ptr[index] = name[sizeof(void *) + index]; } - if (name[sizeof(void*) + index] == '\0') ptr[index] = '\0'; + if (name[sizeof(void *) + index] == '\0') ptr[index] = '\0'; } } -void rt_mem_set_tag(void* ptr, const char* name) +void rt_mem_set_tag(void *ptr, const char *name) { - struct rt_memheap_item* item; + struct rt_memheap_item *item; if (ptr && name) { @@ -668,17 +668,17 @@ void rt_memheap_free(void *ptr) RTM_EXPORT(rt_memheap_free); #ifdef RT_USING_FINSH -static void _memheap_dump_tag(struct rt_memheap_item* item) +static void _memheap_dump_tag(struct rt_memheap_item *item) { - rt_uint8_t name[2 * sizeof(void*)]; - rt_uint8_t* ptr; + rt_uint8_t name[2 * sizeof(void *)]; + rt_uint8_t *ptr; - ptr = (rt_uint8_t*)&(item->next_free); - rt_memcpy(name, ptr, sizeof(void*)); - ptr = (rt_uint8_t*)&(item->prev_free); - rt_memcpy(&name[sizeof(void*)], ptr, sizeof(void*)); + ptr = (rt_uint8_t *) & (item->next_free); + rt_memcpy(name, ptr, sizeof(void *)); + ptr = (rt_uint8_t *) & (item->prev_free); + rt_memcpy(&name[sizeof(void *)], ptr, sizeof(void *)); - rt_kprintf("%.*s", 2 * sizeof(void*), name); + rt_kprintf("%.*s", 2 * sizeof(void *), name); } int rt_memheap_dump(struct rt_memheap *heap) @@ -688,15 +688,15 @@ int rt_memheap_dump(struct rt_memheap *heap) if (heap == RT_NULL) return 0; RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); - rt_kprintf("\n[%.*s] [0x%08x - 0x%08x]->\n", RT_NAME_MAX, heap->parent.name, - (rt_ubase_t)heap->start_addr, (rt_ubase_t)heap->start_addr + heap->pool_size); + rt_kprintf("\n[%.*s] [0x%08x - 0x%08x]->\n", RT_NAME_MAX, heap->parent.name, + (rt_ubase_t)heap->start_addr, (rt_ubase_t)heap->start_addr + heap->pool_size); rt_kprintf("------------------------------\n"); /* lock memheap */ rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); item = heap->block_list; - end = (struct rt_memheap_item *) ((rt_uint8_t *)heap->start_addr + heap->pool_size - RT_MEMHEAP_SIZE); + end = (struct rt_memheap_item *)((rt_uint8_t *)heap->start_addr + heap->pool_size - RT_MEMHEAP_SIZE); /* for each memory block */ while ((rt_ubase_t)item < ((rt_ubase_t)end)) @@ -732,13 +732,13 @@ int memheaptrace(void) int index; extern int list_memheap(void); - heaps = (struct rt_memheap**)rt_malloc(sizeof(struct rt_memheap*) * count); + heaps = (struct rt_memheap **)rt_malloc(sizeof(struct rt_memheap *) * count); if (heaps == RT_NULL) return 0; list_memheap(); rt_kprintf("memheap header size: %d\n", RT_MEMHEAP_SIZE); - count = rt_object_get_pointers(RT_Object_Class_MemHeap, (rt_object_t*)heaps, count); + count = rt_object_get_pointers(RT_Object_Class_MemHeap, (rt_object_t *)heaps, count); for (index = 0; index < count; index++) { rt_memheap_dump(heaps[index]); @@ -968,15 +968,15 @@ void dump_used_memheap(struct rt_memheap *mh) { /* dump information */ rt_kprintf("[0x%08x - %d - %c%c%c%c] used\n", header_ptr, block_size, - header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1], - header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]); + header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1], + header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]); } else { /* dump information */ rt_kprintf("[0x%08x - %d - %c%c%c%c] free\n", header_ptr, block_size, - header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1], - header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]); + header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1], + header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]); } /* move to next used memory block */ -- cgit v1.3.1 From 5a6bc9900689ba2d21850cc520c3621c57037025 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 2 Jun 2021 15:30:32 +0800 Subject: [bug][kernel] 保持空闲任务钩子函数调用的原子性 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 3 ++- src/idle.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 045555933d..191525411a 100644 --- a/src/clock.c +++ b/src/clock.c @@ -13,7 +13,8 @@ * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca * 2011-06-26 Bernard add rt_tick_set function. * 2018-11-22 Jesven add per cpu tick - * 2020-12-29 Meco Man add function rt_tick_get_millisecond() + * 2020-12-29 Meco Man implement rt_tick_get_millisecond() + * 2021-06-01 Meco Man add critical section projection for rt_tick_increase() */ #include diff --git a/src/idle.c b/src/idle.c index 59868352d8..e73a78be9c 100644 --- a/src/idle.c +++ b/src/idle.c @@ -202,12 +202,14 @@ static void rt_thread_idle_entry(void *parameter) { #ifdef RT_USING_IDLE_HOOK rt_size_t i; + void (*idle_hook)(void); for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++) { - if (idle_hook_list[i] != RT_NULL) + idle_hook = idle_hook_list[i]; + if (idle_hook != RT_NULL) { - idle_hook_list[i](); + idle_hook(); } } #endif -- cgit v1.3.1 From e0b66ccab87bd5142769e0f4fd3f2b5ac14796ba Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 3 Jun 2021 20:09:26 +0800 Subject: [kernel] 对rt_tick变量增加volatile修饰,防止编译器优化时出现问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 045555933d..f02c524380 100644 --- a/src/clock.c +++ b/src/clock.c @@ -22,7 +22,7 @@ #ifdef RT_USING_SMP #define rt_tick rt_cpu_index(0)->tick #else -static rt_tick_t rt_tick = 0; +static volatile rt_tick_t rt_tick = 0; #endif /** -- cgit v1.3.1 From 2b6762e85955a10e0150a3f32b869104a106acbd Mon Sep 17 00:00:00 2001 From: Meco Jianting Man <920369182@qq.com> Date: Sat, 5 Jun 2021 13:05:11 +0800 Subject: remove fix priority inversion bug of mutex --- src/ipc.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 74b47df3b6..bda32dbf26 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -39,7 +39,6 @@ * 2020-10-11 Meco Man add value overflow-check code * 2021-01-03 Meco Man implement rt_mb_urgent() * 2021-05-30 Meco Man implement rt_mutex_trytake() - * 2021-01-20 hupu fix priority inversion bug of mutex */ #include -- cgit v1.3.1 From b2dd3f00f0617abd5757ca75a5579d493dc8bd85 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 7 Jun 2021 16:45:39 +0800 Subject: [bug][kernel][heap] 将内存堆保护机制由FIFO改为PRIO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mem.c | 2 +- src/memheap.c | 2 +- src/slab.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mem.c b/src/mem.c index ac0d27f2c3..2b4d3a03be 100644 --- a/src/mem.c +++ b/src/mem.c @@ -250,7 +250,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) rt_mem_setname(heap_end, "INIT"); #endif - rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO); + rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_PRIO); /* initialize the lowest-free pointer to the start of the heap */ lfree = (struct heap_mem *)heap_ptr; diff --git a/src/memheap.c b/src/memheap.c index 35a04c14b1..d3ad6d2c36 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -155,7 +155,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap, item->next_free = item->prev_free = RT_NULL; /* initialize semaphore lock */ - rt_sem_init(&(memheap->lock), name, 1, RT_IPC_FLAG_FIFO); + rt_sem_init(&(memheap->lock), name, 1, RT_IPC_FLAG_PRIO); RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("memory heap: start addr 0x%08x, size %d, free list header 0x%08x\n", diff --git a/src/slab.c b/src/slab.c index 114259002f..2769892b68 100644 --- a/src/slab.c +++ b/src/slab.c @@ -363,7 +363,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) npages = limsize / RT_MM_PAGE_SIZE; /* initialize heap semaphore */ - rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO); + rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_PRIO); RT_DEBUG_LOG(RT_DEBUG_SLAB, ("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n", heap_start, heap_end, limsize, npages)); -- cgit v1.3.1 From 24b4b6cbb9d4b646ed52f1fc996e90f638a7aba6 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 9 Jun 2021 19:50:03 +0800 Subject: [kernel]补充endif后缀注释 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 6 +++--- src/components.c | 26 +++++++++++++------------- src/cpu.c | 2 +- src/device.c | 14 +++++++------- src/idle.c | 32 ++++++++++++++++---------------- 5 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 7df13775b2..77516b3775 100644 --- a/src/clock.c +++ b/src/clock.c @@ -24,7 +24,7 @@ #define rt_tick rt_cpu_index(0)->tick #else static volatile rt_tick_t rt_tick = 0; -#endif +#endif /* RT_USING_SMP */ /** * @addtogroup Clock @@ -72,7 +72,7 @@ void rt_tick_increase(void) rt_cpu_self()->tick ++; #else ++ rt_tick; -#endif +#endif /* RT_USING_SMP */ /* check time slice */ thread = rt_thread_self(); @@ -138,7 +138,7 @@ RT_WEAK rt_tick_t rt_tick_get_millisecond(void) #warning "rt-thread cannot provide a correct 1ms-based tick any longer,\ please redefine this function in another file by using a high-precision hard-timer." return 0; -#endif +#endif /* 1000 % RT_TICK_PER_SECOND == 0u */ } /**@}*/ diff --git a/src/components.c b/src/components.c index 9709d0aae2..d684d5e6fd 100644 --- a/src/components.c +++ b/src/components.c @@ -23,11 +23,11 @@ #ifdef RT_USING_USER_MAIN #ifndef RT_MAIN_THREAD_STACK_SIZE #define RT_MAIN_THREAD_STACK_SIZE 2048 -#endif +#endif /* RT_MAIN_THREAD_STACK_SIZE */ #ifndef RT_MAIN_THREAD_PRIORITY #define RT_MAIN_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 3) -#endif -#endif +#endif /* RT_MAIN_THREAD_PRIORITY */ +#endif /* RT_USING_USER_MAIN */ #ifdef RT_USING_COMPONENTS_INIT /* @@ -98,7 +98,7 @@ void rt_components_board_init(void) { (*fn_ptr)(); } -#endif +#endif /* RT_DEBUG_INIT */ } /** @@ -124,9 +124,9 @@ void rt_components_init(void) { (*fn_ptr)(); } -#endif +#endif /* RT_DEBUG_INIT */ } -#endif /* RT_USING_COMPONENTS_INIT */ +#endif /* RT_USING_COMPONENTS_INIT */ #ifdef RT_USING_USER_MAIN @@ -167,7 +167,7 @@ int entry(void) ALIGN(8) static rt_uint8_t main_stack[RT_MAIN_THREAD_STACK_SIZE]; struct rt_thread main_thread; -#endif +#endif /* RT_USING_HEAP */ /* the system main thread */ void main_thread_entry(void *parameter) @@ -177,11 +177,11 @@ void main_thread_entry(void *parameter) #ifdef RT_USING_COMPONENTS_INIT /* RT-Thread components initialization */ rt_components_init(); -#endif +#endif /* RT_USING_COMPONENTS_INIT */ #ifdef RT_USING_SMP rt_hw_secondary_cpu_up(); -#endif +#endif /* RT_USING_SMP */ /* invoke system main function */ #if defined(__CC_ARM) || defined(__CLANG_ARM) { @@ -211,7 +211,7 @@ void rt_application_init(void) /* if not define RT_USING_HEAP, using to eliminate the warning */ (void)result; -#endif +#endif /* RT_USING_HEAP */ rt_thread_startup(tid); } @@ -237,7 +237,7 @@ int rtthread_startup(void) #ifdef RT_USING_SIGNALS /* signal system initialization */ rt_system_signal_init(); -#endif +#endif /* RT_USING_SIGNALS */ /* create init_thread */ rt_application_init(); @@ -250,7 +250,7 @@ int rtthread_startup(void) #ifdef RT_USING_SMP rt_hw_spin_lock(&_cpus_lock); -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /* start scheduler */ rt_system_scheduler_start(); @@ -258,4 +258,4 @@ int rtthread_startup(void) /* never reach here */ return 0; } -#endif +#endif /* RT_USING_USER_MAIN */ diff --git a/src/cpu.c b/src/cpu.c index 48ddb12c46..a7d56ba999 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -185,4 +185,4 @@ void rt_cpus_lock_status_restore(struct rt_thread *thread) } RTM_EXPORT(rt_cpus_lock_status_restore); -#endif +#endif /* RT_USING_SMP */ diff --git a/src/device.c b/src/device.c index 50b83c7692..a9c244d306 100644 --- a/src/device.c +++ b/src/device.c @@ -16,9 +16,9 @@ */ #include -#if defined(RT_USING_POSIX) +#ifdef RT_USING_POSIX #include /* for wqueue_init */ -#endif +#endif /* RT_USING_POSIX */ #ifdef RT_USING_DEVICE @@ -36,7 +36,7 @@ #define device_read (dev->read) #define device_write (dev->write) #define device_control (dev->control) -#endif +#endif /* RT_USING_DEVICE_OPS */ /** * This function registers a device driver with specified name. @@ -62,10 +62,10 @@ rt_err_t rt_device_register(rt_device_t dev, dev->ref_count = 0; dev->open_flag = 0; -#if defined(RT_USING_POSIX) +#ifdef RT_USING_POSIX dev->fops = RT_NULL; rt_wqueue_init(&(dev->wait_queue)); -#endif +#endif /* RT_USING_POSIX */ return RT_EOK; } @@ -150,7 +150,7 @@ void rt_device_destroy(rt_device_t dev) rt_free(dev); } RTM_EXPORT(rt_device_destroy); -#endif +#endif /* RT_USING_HEAP */ /** * This function will initialize the specified device @@ -434,4 +434,4 @@ rt_device_set_tx_complete(rt_device_t dev, } RTM_EXPORT(rt_device_set_tx_complete); -#endif +#endif /* RT_USING_DEVICE */ diff --git a/src/idle.c b/src/idle.c index e73a78be9c..db256a6010 100644 --- a/src/idle.c +++ b/src/idle.c @@ -22,27 +22,27 @@ #ifdef RT_USING_MODULE #include -#endif +#endif /* RT_USING_MODULE */ -#if defined (RT_USING_HOOK) +#ifdef RT_USING_HOOK #ifndef RT_USING_IDLE_HOOK #define RT_USING_IDLE_HOOK -#endif -#endif +#endif /* RT_USING_IDLE_HOOK */ +#endif /* RT_USING_HOOK */ #ifndef IDLE_THREAD_STACK_SIZE #if defined (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP) #define IDLE_THREAD_STACK_SIZE 256 #else #define IDLE_THREAD_STACK_SIZE 128 -#endif -#endif +#endif /* (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP) */ +#endif /* IDLE_THREAD_STACK_SIZE */ #ifdef RT_USING_SMP #define _CPUS_NR RT_CPUS_NR #else #define _CPUS_NR 1 -#endif +#endif /* RT_USING_SMP */ extern rt_list_t rt_thread_defunct; @@ -53,7 +53,7 @@ static rt_uint8_t rt_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE]; #ifdef RT_USING_IDLE_HOOK #ifndef RT_IDLE_HOOK_LIST_SIZE #define RT_IDLE_HOOK_LIST_SIZE 4 -#endif +#endif /* RT_IDLE_HOOK_LIST_SIZE */ static void (*idle_hook_list[RT_IDLE_HOOK_LIST_SIZE])(void); @@ -125,7 +125,7 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void)) return ret; } -#endif +#endif /* RT_USING_IDLE_HOOK */ #ifdef RT_USING_HEAP /* Return whether there is defunctional thread to be deleted. */ @@ -141,7 +141,7 @@ rt_inline int _has_defunct_thread(void) return l->next != l; } -#endif +#endif /* RT_USING_HEAP */ /** * @ingroup Thread @@ -182,7 +182,7 @@ void rt_thread_idle_excute(void) rt_object_delete((rt_object_t)thread); rt_hw_interrupt_enable(lock); } -#endif +#endif /* RT_USING_HEAP */ } extern void rt_system_power_manager(void); @@ -196,7 +196,7 @@ static void rt_thread_idle_entry(void *parameter) rt_hw_secondary_cpu_idle_exec(); } } -#endif +#endif /* RT_USING_SMP */ while (1) { @@ -212,12 +212,12 @@ static void rt_thread_idle_entry(void *parameter) idle_hook(); } } -#endif +#endif /* RT_USING_IDLE_HOOK */ rt_thread_idle_excute(); #ifdef RT_USING_PM rt_system_power_manager(); -#endif +#endif /* RT_USING_PM */ } } @@ -246,7 +246,7 @@ void rt_thread_idle_init(void) 32); #ifdef RT_USING_SMP rt_thread_control(&idle[i], RT_THREAD_CTRL_BIND_CPU, (void*)i); -#endif +#endif /* RT_USING_SMP */ /* startup */ rt_thread_startup(&idle[i]); } @@ -264,7 +264,7 @@ rt_thread_t rt_thread_idle_gethandler(void) register int id = rt_hw_cpu_id(); #else register int id = 0; -#endif +#endif /* RT_USING_SMP */ return (rt_thread_t)(&idle[id]); } -- cgit v1.3.1 From e019a57ff30b9fda5aa43fdc97eac5cca80bbc3b Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 10 Jun 2021 17:58:31 +0800 Subject: [kernel] 补充endif后缀注释(2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 30 ++++++++++++++--------------- src/irq.c | 6 ++---- src/kservice.c | 60 +++++++++++++++++++++++++++++----------------------------- 3 files changed, 47 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index bda32dbf26..c981aabe43 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -48,7 +48,7 @@ extern void (*rt_object_trytake_hook)(struct rt_object *object); extern void (*rt_object_take_hook)(struct rt_object *object); extern void (*rt_object_put_hook)(struct rt_object *object); -#endif +#endif /* RT_USING_HOOK */ /** * @addtogroup IPC @@ -93,7 +93,7 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, { case RT_IPC_FLAG_FIFO: rt_list_insert_before(list, &(thread->tlist)); - break; + break; /* RT_IPC_FLAG_FIFO */ case RT_IPC_FLAG_PRIO: { @@ -121,7 +121,7 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, if (n == list) rt_list_insert_before(list, &(thread->tlist)); } - break; + break;/* RT_IPC_FLAG_PRIO */ default: RT_ASSERT(0); @@ -319,7 +319,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem) return RT_EOK; } RTM_EXPORT(rt_sem_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will take a semaphore, if the semaphore is unavailable, the @@ -533,7 +533,7 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_sem_control); -#endif /* end of RT_USING_SEMAPHORE */ +#endif /* RT_USING_SEMAPHORE */ #ifdef RT_USING_MUTEX /** @@ -659,7 +659,7 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex) return RT_EOK; } RTM_EXPORT(rt_mutex_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will take a mutex, if the mutex is unavailable, the @@ -714,7 +714,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) { #ifdef RT_USING_SIGNALS __again: -#endif /* end of RT_USING_SIGNALS */ +#endif /* RT_USING_SIGNALS */ /* The value of mutex is 1 in initial status. Therefore, if the * value is great than 0, it indicates the mutex is avaible. */ @@ -794,7 +794,7 @@ __again: #ifdef RT_USING_SIGNALS /* interrupt by signal, try it again */ if (thread->error == -RT_EINTR) goto __again; -#endif /* end of RT_USING_SIGNALS */ +#endif /* RT_USING_SIGNALS */ /* return error */ return thread->error; @@ -968,7 +968,7 @@ rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_mutex_control); -#endif /* end of RT_USING_MUTEX */ +#endif /* RT_USING_MUTEX */ #ifdef RT_USING_EVENT /** @@ -1084,7 +1084,7 @@ rt_err_t rt_event_delete(rt_event_t event) return RT_EOK; } RTM_EXPORT(rt_event_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will send an event to the event object, if there are threads @@ -1361,7 +1361,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_event_control); -#endif /* end of RT_USING_EVENT */ +#endif /* RT_USING_EVENT */ #ifdef RT_USING_MAILBOX /** @@ -1512,7 +1512,7 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb) return RT_EOK; } RTM_EXPORT(rt_mb_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will send a mail to mailbox object. If the mailbox is full, @@ -1919,7 +1919,7 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_mb_control); -#endif /* end of RT_USING_MAILBOX */ +#endif /* RT_USING_MAILBOX */ #ifdef RT_USING_MESSAGEQUEUE struct rt_mq_message @@ -2121,7 +2121,7 @@ rt_err_t rt_mq_delete(rt_mq_t mq) return RT_EOK; } RTM_EXPORT(rt_mq_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will send a message to message queue object. If the message queue is full, @@ -2625,6 +2625,6 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_mq_control); -#endif /* end of RT_USING_MESSAGEQUEUE */ +#endif /* RT_USING_MESSAGEQUEUE */ /**@}*/ diff --git a/src/irq.c b/src/irq.c index 65fc2ea5e0..e89b8504dc 100644 --- a/src/irq.c +++ b/src/irq.c @@ -39,9 +39,7 @@ void rt_interrupt_leave_sethook(void (*hook)(void)) { rt_interrupt_leave_hook = hook; } -#endif - -/* #define IRQ_DEBUG */ +#endif /* RT_USING_HOOK */ /** * @addtogroup Kernel @@ -53,7 +51,7 @@ void rt_interrupt_leave_sethook(void (*hook)(void)) #define rt_interrupt_nest rt_cpu_self()->irq_nest #else volatile rt_uint8_t rt_interrupt_nest = 0; -#endif +#endif /* RT_USING_SMP */ /** * This function will be invoked by BSP, when enter interrupt service routine diff --git a/src/kservice.c b/src/kservice.c index 7ed05b6651..c4bbdd9151 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -25,7 +25,7 @@ #ifdef RT_USING_MODULE #include -#endif +#endif /* RT_USING_MODULE */ /* use precision */ #define RT_PRINTF_PRECISION @@ -194,7 +194,7 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) #undef LBLOCKSIZE #undef UNALIGNED #undef TOO_SMALL -#endif +#endif /* RT_KSERVICE_USING_TINY_SIZE */ } RTM_EXPORT(rt_memset); @@ -277,7 +277,7 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) #undef BIGBLOCKSIZE #undef LITTLEBLOCKSIZE #undef TOO_SMALL -#endif +#endif /* RT_KSERVICE_USING_TINY_SIZE */ } RTM_EXPORT(rt_memcpy); @@ -509,7 +509,7 @@ rt_size_t rt_strlen(const char *s) } RTM_EXPORT(rt_strlen); -#endif /*RT_KSERVICE_USING_STDLIB*/ +#endif /* RT_KSERVICE_USING_STDLIB */ #ifdef RT_USING_HEAP /** @@ -535,7 +535,7 @@ RTM_EXPORT(rt_strdup); #if defined(__CC_ARM) || defined(__CLANG_ARM) char *strdup(const char *s) __attribute__((alias("rt_strdup"))); #endif -#endif +#endif /* RT_USING_HEAP */ /** * This function will show the version of rt-thread rtos @@ -591,7 +591,7 @@ rt_inline int divide(long *n, int base) return res; } -#endif +#endif /* RT_PRINTF_LONGLONG */ rt_inline int skip_atoi(const char **s) { @@ -617,7 +617,7 @@ static char *print_number(char *buf, long long num, #else long num, -#endif +#endif /* RT_PRINTF_LONGLONG */ int base, int s, int precision, @@ -629,18 +629,18 @@ static char *print_number(char *buf, long long num, #else long num, -#endif +#endif /* RT_PRINTF_LONGLONG */ int base, int s, int type) -#endif +#endif /* RT_PRINTF_PRECISION */ { char c, sign; #ifdef RT_PRINTF_LONGLONG char tmp[32]; #else char tmp[16]; -#endif +#endif /* RT_PRINTF_LONGLONG */ int precision_bak = precision; const char *digits; static const char small_digits[] = "0123456789abcdef"; @@ -679,7 +679,7 @@ static char *print_number(char *buf, else if (base == 8) size--; } -#endif +#endif /* RT_PRINTF_SPECIAL */ i = 0; if (num == 0) @@ -696,7 +696,7 @@ static char *print_number(char *buf, size -= precision; #else size -= i; -#endif +#endif /* RT_PRINTF_PRECISION */ if (!(type & (ZEROPAD | LEFT))) { @@ -742,7 +742,7 @@ static char *print_number(char *buf, ++ buf; } } -#endif +#endif /* RT_PRINTF_SPECIAL */ /* no align to the left */ if (!(type & LEFT)) @@ -762,7 +762,7 @@ static char *print_number(char *buf, *buf = '0'; ++ buf; } -#endif +#endif /* RT_PRINTF_PRECISION */ /* put number in the temporary buffer */ while (i-- > 0 && (precision_bak != 0)) @@ -791,7 +791,7 @@ rt_int32_t rt_vsnprintf(char *buf, unsigned long long num; #else rt_uint32_t num; -#endif +#endif /* RT_PRINTF_LONGLONG */ int i, len; char *str, *end, c; const char *s; @@ -803,7 +803,7 @@ rt_int32_t rt_vsnprintf(char *buf, #ifdef RT_PRINTF_PRECISION int precision; /* min. # of digits for integers and max for a string */ -#endif +#endif /* RT_PRINTF_PRECISION */ str = buf; end = buf + size; @@ -870,14 +870,14 @@ rt_int32_t rt_vsnprintf(char *buf, } if (precision < 0) precision = 0; } -#endif +#endif /* RT_PRINTF_PRECISION */ /* get the conversion qualifier */ qualifier = 0; #ifdef RT_PRINTF_LONGLONG if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') #else if (*fmt == 'h' || *fmt == 'l') -#endif +#endif /* RT_PRINTF_LONGLONG */ { qualifier = *fmt; ++ fmt; @@ -887,7 +887,7 @@ rt_int32_t rt_vsnprintf(char *buf, qualifier = 'L'; ++ fmt; } -#endif +#endif /* RT_PRINTF_LONGLONG */ } /* the default base */ @@ -925,7 +925,7 @@ rt_int32_t rt_vsnprintf(char *buf, for (len = 0; (len != field_width) && (s[len] != '\0'); len++); #ifdef RT_PRINTF_PRECISION if (precision > 0 && len > precision) len = precision; -#endif +#endif /* RT_PRINTF_PRECISION */ if (!(flags & LEFT)) { @@ -964,7 +964,7 @@ rt_int32_t rt_vsnprintf(char *buf, str = print_number(str, end, (long)va_arg(args, void *), 16, field_width, flags); -#endif +#endif /* RT_PRINTF_PRECISION */ continue; case '%': @@ -1010,7 +1010,7 @@ rt_int32_t rt_vsnprintf(char *buf, else if (qualifier == 'l') #else if (qualifier == 'l') -#endif +#endif /* RT_PRINTF_LONGLONG */ { num = va_arg(args, rt_uint32_t); if (flags & SIGN) num = (rt_int32_t)num; @@ -1029,7 +1029,7 @@ rt_int32_t rt_vsnprintf(char *buf, str = print_number(str, end, num, base, field_width, precision, flags); #else str = print_number(str, end, num, base, field_width, flags); -#endif +#endif /* RT_PRINTF_PRECISION */ } if (size > 0) @@ -1152,7 +1152,7 @@ rt_device_t rt_console_set_device(const char *name) return old_device; } RTM_EXPORT(rt_console_set_device); -#endif +#endif /* RT_USING_DEVICE */ RT_WEAK void rt_hw_console_output(const char *str) { @@ -1184,7 +1184,7 @@ void rt_kputs(const char *str) } #else rt_hw_console_output(str); -#endif +#endif /* RT_USING_DEVICE */ } /** @@ -1222,11 +1222,11 @@ RT_WEAK void rt_kprintf(const char *fmt, ...) } #else rt_hw_console_output(rt_log_buf); -#endif +#endif /* RT_USING_DEVICE */ va_end(args); } RTM_EXPORT(rt_kprintf); -#endif +#endif /* RT_USING_CONSOLE */ #ifdef RT_USING_HEAP /** @@ -1292,7 +1292,7 @@ void rt_free_align(void *ptr) rt_free(real_ptr); } RTM_EXPORT(rt_free_align); -#endif +#endif /* RT_USING_HEAP */ #ifndef RT_USING_CPU_FFS const rt_uint8_t __lowest_bit_bitmap[] = @@ -1340,7 +1340,7 @@ int __rt_ffs(int value) return __lowest_bit_bitmap[(value & 0xff000000) >> 24] + 25; } -#endif +#endif /* RT_USING_CPU_FFS */ #ifdef RT_DEBUG /* RT_ASSERT(EX)'s hook */ @@ -1377,7 +1377,7 @@ void rt_assert_handler(const char *ex_string, const char *func, rt_size_t line) dlmodule_exit(-1); } else -#endif +#endif /*RT_USING_MODULE*/ { rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line); while (dummy == 0); -- cgit v1.3.1 From 8b53609f574209b11f649f946466fd0e0244eb60 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 10 Jun 2021 18:33:47 +0800 Subject: [kernel] 补充endif后缀注释(3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/memheap.c | 30 +++++++++++------------ src/mempool.c | 7 +++--- src/object.c | 14 +++++------ src/scheduler.c | 76 ++++++++++++++++++++++++++++----------------------------- src/signal.c | 12 ++++----- src/slab.c | 22 ++++++++--------- src/thread.c | 34 +++++++++++++------------- src/timer.c | 20 +++++++-------- 8 files changed, 107 insertions(+), 108 deletions(-) (limited to 'src') diff --git a/src/memheap.c b/src/memheap.c index 35a04c14b1..feac8bb4aa 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -74,7 +74,7 @@ void rt_mem_set_tag(void *ptr, const char *name) rt_memheap_setname(item, name); } } -#endif +#endif /* RT_USING_MEMTRACE */ /* * The initialized memory pool will be: @@ -127,7 +127,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap, #ifdef RT_USING_MEMTRACE rt_memset(item->owner_thread_name, ' ', sizeof(item->owner_thread_name)); -#endif +#endif /* RT_USING_MEMTRACE */ item->next = (struct rt_memheap_item *) ((rt_uint8_t *)item + memheap->available_size + RT_MEMHEAP_SIZE); @@ -252,7 +252,7 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size) #ifdef RT_USING_MEMTRACE rt_memset(new_ptr->owner_thread_name, ' ', sizeof(new_ptr->owner_thread_name)); -#endif +#endif /* RT_USING_MEMTRACE */ /* break down the block list */ new_ptr->prev = header_ptr; @@ -310,7 +310,7 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size) rt_memcpy(header_ptr->owner_thread_name, rt_thread_self()->name, sizeof(header_ptr->owner_thread_name)); else rt_memcpy(header_ptr->owner_thread_name, "NONE", sizeof(header_ptr->owner_thread_name)); -#endif +#endif /* RT_USING_MEMTRACE */ /* release lock */ rt_sem_release(&(heap->lock)); @@ -439,7 +439,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize) #ifdef RT_USING_MEMTRACE rt_memset(next_ptr->owner_thread_name, ' ', sizeof(next_ptr->owner_thread_name)); -#endif +#endif /* RT_USING_MEMTRACE */ next_ptr->prev = header_ptr; next_ptr->next = header_ptr->next; @@ -507,7 +507,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize) #ifdef RT_USING_MEMTRACE rt_memset(new_ptr->owner_thread_name, ' ', sizeof(new_ptr->owner_thread_name)); -#endif +#endif /* RT_USING_MEMTRACE */ /* break down the block list */ new_ptr->prev = header_ptr; @@ -660,7 +660,7 @@ void rt_memheap_free(void *ptr) #ifdef RT_USING_MEMTRACE rt_memset(header_ptr->owner_thread_name, ' ', sizeof(header_ptr->owner_thread_name)); -#endif +#endif /* RT_USING_MEMTRACE */ /* release lock */ rt_sem_release(&(heap->lock)); @@ -750,7 +750,7 @@ int memheaptrace(void) return 0; } MSH_CMD_EXPORT(memheaptrace, dump memory trace information); -#endif +#endif /* RT_USING_FINSH */ #ifdef RT_USING_MEMHEAP_AS_HEAP static struct rt_memheap _heap; @@ -816,7 +816,7 @@ void *rt_malloc(rt_size_t size) RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("malloc => 0x%08x : %d", ptr, size)); } -#endif +#endif /* RT_USING_MEMTRACE */ return ptr; } @@ -882,7 +882,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize) RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("realloc => 0x%08x : %d", new_ptr, newsize)); } -#endif +#endif /* RT_USING_MEMTRACE */ return new_ptr; } @@ -912,7 +912,7 @@ void *rt_calloc(rt_size_t count, rt_size_t size) RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("calloc => 0x%08x : %d", ptr, count * size)); } -#endif +#endif /* RT_USING_MEMTRACE */ return ptr; } @@ -932,7 +932,7 @@ void rt_memory_info(rt_uint32_t *total, *max_used = _heap.max_used_size; } -#endif +#endif /* RT_USING_MEMHEAP_AS_HEAP */ #ifdef RT_USING_MEMTRACE @@ -1004,8 +1004,8 @@ void memtrace_heap() #ifdef RT_USING_FINSH #include MSH_CMD_EXPORT(memtrace_heap, dump memory trace for heap); -#endif /* end of RT_USING_FINSH */ +#endif /* RT_USING_FINSH */ -#endif /* end of RT_USING_MEMTRACE */ +#endif /* RT_USING_MEMTRACE */ -#endif /* end of RT_USING_MEMHEAP */ +#endif /* RT_USING_MEMHEAP */ diff --git a/src/mempool.c b/src/mempool.c index 1de48940d7..5ac87d2bc8 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -54,7 +54,7 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block)) } /**@}*/ -#endif +#endif /* RT_USING_HOOK */ /** * @addtogroup MM @@ -290,7 +290,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp) return RT_EOK; } RTM_EXPORT(rt_mp_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will allocate a block from memory pool @@ -451,5 +451,4 @@ RTM_EXPORT(rt_mp_free); /**@}*/ -#endif - +#endif /* RT_USING_MEMPOOL */ diff --git a/src/object.c b/src/object.c index 013e2d1e33..ff96037c52 100644 --- a/src/object.c +++ b/src/object.c @@ -20,7 +20,7 @@ #ifdef RT_USING_MODULE #include -#endif +#endif /* RT_USING_MODULE */ /* * define object_info for the number of rt_object_container items. @@ -189,7 +189,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object)) } /**@}*/ -#endif +#endif /* RT_USING_HOOK */ /** * @addtogroup KernelObject @@ -305,7 +305,7 @@ void rt_object_init(struct rt_object *object, struct rt_object_information *information; #ifdef RT_USING_MODULE struct rt_dlmodule *module = dlmodule_self(); -#endif +#endif /* RT_USING_MODULE */ /* get object information */ information = rt_object_get_information(type); @@ -349,7 +349,7 @@ void rt_object_init(struct rt_object *object, object->module_id = (void *)module; } else -#endif +#endif /* RT_USING_MODULE */ { /* insert object into information object list */ rt_list_insert_after(&(information->object_list), &(object->list)); @@ -403,7 +403,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) struct rt_object_information *information; #ifdef RT_USING_MODULE struct rt_dlmodule *module = dlmodule_self(); -#endif +#endif /* RT_USING_MODULE */ RT_DEBUG_NOT_IN_INTERRUPT; @@ -444,7 +444,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) object->module_id = (void *)module; } else -#endif +#endif /* RT_USING_MODULE */ { /* insert object into information object list */ rt_list_insert_after(&(information->object_list), &(object->list)); @@ -487,7 +487,7 @@ void rt_object_delete(rt_object_t object) /* free the memory of object */ RT_KERNEL_FREE(object); } -#endif +#endif /* RT_USING_HEAP */ /** * This function will judge the object is system object or not. diff --git a/src/scheduler.c b/src/scheduler.c index ed0f30fc81..eec660a8aa 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -38,14 +38,14 @@ rt_uint32_t rt_thread_ready_priority_group; #if RT_THREAD_PRIORITY_MAX > 32 /* Maximum priority level, 256 */ rt_uint8_t rt_thread_ready_table[32]; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ #ifndef RT_USING_SMP extern volatile rt_uint8_t rt_interrupt_nest; static rt_int16_t rt_scheduler_lock_nest; struct rt_thread *rt_current_thread = RT_NULL; rt_uint8_t rt_current_priority; -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ rt_list_t rt_thread_defunct; @@ -71,18 +71,18 @@ rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to)) } /**@}*/ -#endif +#endif /* RT_USING_HOOK */ #ifdef RT_USING_OVERFLOW_CHECK static void _rt_scheduler_stack_check(struct rt_thread *thread) { RT_ASSERT(thread != RT_NULL); -#if defined(ARCH_CPU_STACK_GROWS_UPWARD) +#ifdef ARCH_CPU_STACK_GROWS_UPWARD if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' || #else if (*((rt_uint8_t *)thread->stack_addr) != '#' || -#endif +#endif /* ARCH_CPU_STACK_GROWS_UPWARD */ (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) @@ -94,7 +94,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) level = rt_hw_interrupt_disable(); while (level); } -#if defined(ARCH_CPU_STACK_GROWS_UPWARD) +#ifdef ARCH_CPU_STACK_GROWS_UPWARD 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", @@ -106,9 +106,9 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) rt_kprintf("warning: %s stack is close to end of stack address.\n", thread->name); } -#endif +#endif /* ARCH_CPU_STACK_GROWS_UPWARD */ } -#endif +#endif /* RT_USING_OVERFLOW_CHECK */ /* * get the highest priority thread in ready queue @@ -129,7 +129,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio) #else highest_ready_priority = __rt_ffs(rt_thread_ready_priority_group) - 1; local_highest_ready_priority = __rt_ffs(pcpu->priority_group) - 1; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ /* get highest ready priority thread */ if (highest_ready_priority < local_highest_ready_priority) @@ -162,7 +162,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio) highest_ready_priority = (number << 3) + __rt_ffs(rt_thread_ready_table[number]) - 1; #else highest_ready_priority = __rt_ffs(rt_thread_ready_priority_group) - 1; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ /* get highest ready priority thread */ highest_priority_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next, @@ -173,7 +173,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio) return highest_priority_thread; } -#endif +#endif /* RT_USING_SMP */ /** * @ingroup SystemInit @@ -183,12 +183,12 @@ void rt_system_scheduler_init(void) { #ifdef RT_USING_SMP int cpu; -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ register rt_base_t offset; #ifndef RT_USING_SMP rt_scheduler_lock_nest = 0; -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("start scheduler: max priority 0x%02x\n", RT_THREAD_PRIORITY_MAX)); @@ -213,9 +213,9 @@ void rt_system_scheduler_init(void) #if RT_THREAD_PRIORITY_MAX > 32 rt_memset(pcpu->ready_table, 0, sizeof(pcpu->ready_table)); -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /* initialize ready priority group */ rt_thread_ready_priority_group = 0; @@ -223,7 +223,7 @@ void rt_system_scheduler_init(void) #if RT_THREAD_PRIORITY_MAX > 32 /* initialize ready table */ rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table)); -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ /* initialize thread defunct */ rt_list_init(&rt_thread_defunct); @@ -245,7 +245,7 @@ void rt_system_scheduler_start(void) to_thread->oncpu = rt_hw_cpu_id(); #else rt_current_thread = to_thread; -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ rt_schedule_remove_thread(to_thread); to_thread->stat = RT_THREAD_RUNNING; @@ -255,7 +255,7 @@ void rt_system_scheduler_start(void) rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp, to_thread); #else rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp); -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /* never come back */ } @@ -319,7 +319,7 @@ void rt_schedule(void) rt_thread_resume(current_thread); } } -#endif +#endif /* RT_USING_SIGNALS */ if (current_thread->scheduler_lock_nest == 1) /* whether lock scheduler */ { @@ -367,7 +367,7 @@ void rt_schedule(void) #ifdef RT_USING_OVERFLOW_CHECK _rt_scheduler_stack_check(to_thread); -#endif +#endif /* RT_USING_OVERFLOW_CHECK */ rt_hw_context_switch((rt_ubase_t)¤t_thread->sp, (rt_ubase_t)&to_thread->sp, to_thread); @@ -396,7 +396,7 @@ void rt_schedule(void) { rt_hw_interrupt_enable(level); } -#endif +#endif /* RT_USING_SIGNALS */ __exit: return ; @@ -472,7 +472,7 @@ void rt_schedule(void) #ifdef RT_USING_OVERFLOW_CHECK _rt_scheduler_stack_check(to_thread); -#endif +#endif /* RT_USING_OVERFLOW_CHECK */ if (rt_interrupt_nest == 0) { @@ -502,7 +502,7 @@ void rt_schedule(void) { rt_hw_interrupt_enable(level); } -#endif +#endif /* RT_USING_SIGNALS */ goto __exit; } else @@ -527,7 +527,7 @@ void rt_schedule(void) __exit: return; } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /** * This function checks if a scheduling is needed after IRQ context. If yes, @@ -559,7 +559,7 @@ void rt_scheduler_do_irq_switch(void *context) rt_thread_resume(current_thread); } } -#endif +#endif /* RT_USING_SIGNALS */ if (pcpu->irq_switch_flag == 0) { @@ -608,7 +608,7 @@ void rt_scheduler_do_irq_switch(void *context) #ifdef RT_USING_OVERFLOW_CHECK _rt_scheduler_stack_check(to_thread); -#endif +#endif /* RT_USING_OVERFLOW_CHECK */ RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("switch in interrupt\n")); current_thread->cpus_lock_nest--; @@ -621,7 +621,7 @@ void rt_scheduler_do_irq_switch(void *context) } rt_hw_interrupt_enable(level); } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /* * This function will insert a thread to system ready queue. The state of @@ -661,7 +661,7 @@ void rt_schedule_insert_thread(struct rt_thread *thread) { #if RT_THREAD_PRIORITY_MAX > 32 rt_thread_ready_table[thread->number] |= thread->high_mask; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ rt_thread_ready_priority_group |= thread->number_mask; rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]), @@ -675,7 +675,7 @@ void rt_schedule_insert_thread(struct rt_thread *thread) #if RT_THREAD_PRIORITY_MAX > 32 pcpu->ready_table[thread->number] |= thread->high_mask; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ pcpu->priority_group |= thread->number_mask; rt_list_insert_before(&(rt_cpu_index(bind_cpu)->priority_table[thread->current_priority]), @@ -724,14 +724,14 @@ void rt_schedule_insert_thread(struct rt_thread *thread) /* set priority mask */ #if RT_THREAD_PRIORITY_MAX > 32 rt_thread_ready_table[thread->number] |= thread->high_mask; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ rt_thread_ready_priority_group |= thread->number_mask; __exit: /* enable interrupt */ rt_hw_interrupt_enable(temp); } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /* * This function will remove a thread from system ready queue. @@ -768,7 +768,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread) } #else rt_thread_ready_priority_group &= ~thread->number_mask; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ } } else @@ -785,7 +785,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread) } #else pcpu->priority_group &= ~thread->number_mask; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ } } @@ -818,13 +818,13 @@ void rt_schedule_remove_thread(struct rt_thread *thread) } #else rt_thread_ready_priority_group &= ~thread->number_mask; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ } /* enable interrupt */ rt_hw_interrupt_enable(level); } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /** * This function will lock the thread scheduler. @@ -885,7 +885,7 @@ void rt_enter_critical(void) /* enable interrupt */ rt_hw_interrupt_enable(level); } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ RTM_EXPORT(rt_enter_critical); /** @@ -959,7 +959,7 @@ void rt_exit_critical(void) rt_hw_interrupt_enable(level); } } -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ RTM_EXPORT(rt_exit_critical); /** @@ -975,7 +975,7 @@ rt_uint16_t rt_critical_level(void) return current_thread->critical_lock_nest; #else return rt_scheduler_lock_nest; -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ } RTM_EXPORT(rt_critical_level); diff --git a/src/signal.c b/src/signal.c index c2c3e975cb..bb7706d9ef 100644 --- a/src/signal.c +++ b/src/signal.c @@ -20,7 +20,7 @@ #ifndef RT_SIG_INFO_MAX #define RT_SIG_INFO_MAX 32 -#endif +#endif /* RT_SIG_INFO_MAX */ #define DBG_TAG "SIGN" #define DBG_LVL DBG_WARNING @@ -67,7 +67,7 @@ static void _signal_entry(void *parameter) /* return to thread */ tid->sp = tid->sig_ret; tid->sig_ret = RT_NULL; -#endif +#endif /* RT_USING_SMP */ LOG_D("switch back to: 0x%08x\n", tid->sp); tid->stat &= ~RT_THREAD_STAT_SIGNAL; @@ -76,7 +76,7 @@ static void _signal_entry(void *parameter) rt_hw_context_switch_to((rt_base_t)¶meter, tid); #else rt_hw_context_switch_to((rt_ubase_t)&(tid->sp)); -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ } /* @@ -153,7 +153,7 @@ static void _signal_deliver(rt_thread_t tid) tid->sig_ret = tid->sp; tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL, (void *)((char *)tid->sig_ret - 32), RT_NULL); -#endif +#endif /* RT_USING_SMP */ rt_hw_interrupt_enable(level); LOG_D("signal stack pointer @ 0x%08x", tid->sp); @@ -204,7 +204,7 @@ void *rt_signal_check(void* context) rt_hw_interrupt_enable(level); return context; } -#endif +#endif /* RT_USING_SMP */ rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler) { @@ -586,4 +586,4 @@ int rt_system_signal_init(void) return 0; } -#endif +#endif /* RT_USING_SIGNALS */ diff --git a/src/slab.c b/src/slab.c index 114259002f..bec826ef18 100644 --- a/src/slab.c +++ b/src/slab.c @@ -61,7 +61,7 @@ /* some statistical variable */ #ifdef RT_MEM_STATS static rt_size_t used_mem, max_mem; -#endif +#endif /* RT_MEM_STATS */ #ifdef RT_USING_HOOK static void (*rt_malloc_hook)(void *ptr, rt_size_t size); @@ -99,7 +99,7 @@ RTM_EXPORT(rt_free_sethook); /**@}*/ -#endif +#endif /* RT_USING_HOOK */ /* * slab allocator implementation @@ -516,7 +516,7 @@ void *rt_malloc(rt_size_t size) used_mem += size; if (used_mem > max_mem) max_mem = used_mem; -#endif +#endif /* RT_MEM_STATS */ goto done; } @@ -571,7 +571,7 @@ void *rt_malloc(rt_size_t size) used_mem += z->z_chunksize; if (used_mem > max_mem) max_mem = used_mem; -#endif +#endif /* RT_MEM_STATS */ goto done; } @@ -655,7 +655,7 @@ void *rt_malloc(rt_size_t size) used_mem += z->z_chunksize; if (used_mem > max_mem) max_mem = used_mem; -#endif +#endif /* RT_MEM_STATS */ } done: @@ -790,7 +790,7 @@ void rt_free(void *ptr) (rt_ubase_t)addr, ((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS)); } -#endif +#endif /* RT_DEBUG_SLAB */ kup = btokup((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK); /* release large allocation */ @@ -806,7 +806,7 @@ void rt_free(void *ptr) #ifdef RT_MEM_STATS used_mem -= size * RT_MM_PAGE_SIZE; -#endif +#endif /* RT_MEM_STATS */ rt_sem_release(&heap_sem); RT_DEBUG_LOG(RT_DEBUG_SLAB, @@ -833,7 +833,7 @@ void rt_free(void *ptr) #ifdef RT_MEM_STATS used_mem -= z->z_chunksize; -#endif +#endif /* RT_MEM_STATS */ /* * Bump the number of free chunks. If it becomes non-zero the zone @@ -929,9 +929,9 @@ void list_mem(void) rt_kprintf("maximum allocated memory: %d\n", max_mem); } FINSH_FUNCTION_EXPORT(list_mem, list memory usage information) -#endif -#endif +#endif /* RT_USING_FINSH */ +#endif /* RT_MEM_STATS */ /**@}*/ -#endif +#endif /* defined (RT_USING_HEAP) && defined (RT_USING_SLAB) */ diff --git a/src/thread.c b/src/thread.c index 6304a4ebe6..c0a8f0ee74 100644 --- a/src/thread.c +++ b/src/thread.c @@ -76,7 +76,7 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread)) rt_thread_inited_hook = hook; } -#endif +#endif /* RT_USING_HOOK */ /* must be invoke witch rt_hw_interrupt_disable */ static void _rt_thread_cleanup_execute(rt_thread_t thread) @@ -84,7 +84,7 @@ static void _rt_thread_cleanup_execute(rt_thread_t thread) register rt_base_t level; #ifdef RT_USING_MODULE struct rt_dlmodule *module = RT_NULL; -#endif +#endif /* RT_USING_MODULE */ level = rt_hw_interrupt_disable(); #ifdef RT_USING_MODULE module = (struct rt_dlmodule*)thread->module_id; @@ -92,14 +92,14 @@ static void _rt_thread_cleanup_execute(rt_thread_t thread) { dlmodule_destroy(module); } -#endif +#endif /* RT_USING_MODULE */ /* invoke thread cleanup */ if (thread->cleanup != RT_NULL) thread->cleanup(thread); #ifdef RT_USING_SIGNALS rt_thread_free_sig(thread); -#endif +#endif /* RT_USING_SIGNALS */ rt_hw_interrupt_enable(level); } @@ -170,7 +170,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, (rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), (void *)_rt_thread_exit); -#endif +#endif /* ARCH_CPU_STACK_GROWS_UPWARD */ /* priority init */ RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX); @@ -181,7 +181,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, #if RT_THREAD_PRIORITY_MAX > 32 thread->number = 0; thread->high_mask = 0; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ /* tick init */ thread->init_tick = tick; @@ -200,7 +200,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->scheduler_lock_nest = 0; thread->cpus_lock_nest = 0; thread->critical_lock_nest = 0; -#endif /*RT_USING_SMP*/ +#endif /* RT_USING_SMP */ /* initialize cleanup function and user data */ thread->cleanup = 0; @@ -221,14 +221,14 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, #ifndef RT_USING_SMP thread->sig_ret = RT_NULL; -#endif +#endif /* RT_USING_SMP */ thread->sig_vectors = RT_NULL; thread->si_list = RT_NULL; -#endif +#endif /* RT_USING_SIGNALS */ #ifdef RT_USING_LWP thread->lwp = RT_NULL; -#endif +#endif /* RT_USING_LWP */ RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread)); @@ -302,7 +302,7 @@ rt_thread_t rt_thread_self(void) extern rt_thread_t rt_current_thread; return rt_current_thread; -#endif +#endif /* RT_USING_SMP */ } RTM_EXPORT(rt_thread_self); @@ -330,7 +330,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread) thread->high_mask = 1L << (thread->current_priority & 0x07); /* 3bit */ #else thread->number_mask = 1L << thread->current_priority; -#endif +#endif /* RT_THREAD_PRIORITY_MAX > 32 */ RT_DEBUG_LOG(RT_DEBUG_THREAD, ("startup a thread:%s with priority:%d\n", thread->name, thread->init_priority)); @@ -492,7 +492,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) return RT_EOK; } RTM_EXPORT(rt_thread_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will let current thread yield processor, and scheduler will @@ -690,7 +690,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */ #else thread->number_mask = 1 << thread->current_priority; - #endif + #endif /* RT_THREAD_PRIORITY_MAX > 32 */ /* insert thread to schedule queue again */ rt_schedule_insert_thread(thread); @@ -706,7 +706,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */ #else thread->number_mask = 1 << thread->current_priority; - #endif + #endif /* RT_THREAD_PRIORITY_MAX > 32 */ } /* enable interrupt */ @@ -732,7 +732,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) { rt_err = rt_thread_delete(thread); } - #endif + #endif /* RT_USING_HEAP */ rt_schedule(); return rt_err; } @@ -752,7 +752,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) thread->bind_cpu = cpu > RT_CPUS_NR? RT_CPUS_NR : cpu; break; } - #endif /*RT_USING_SMP*/ + #endif /* RT_USING_SMP */ default: break; diff --git a/src/timer.c b/src/timer.c index 9b0db6c6a5..1c8e70fccc 100644 --- a/src/timer.c +++ b/src/timer.c @@ -31,11 +31,11 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #ifndef RT_TIMER_THREAD_STACK_SIZE #define RT_TIMER_THREAD_STACK_SIZE 512 -#endif +#endif /* RT_TIMER_THREAD_STACK_SIZE */ #ifndef RT_TIMER_THREAD_PRIO #define RT_TIMER_THREAD_PRIO 0 -#endif +#endif /* RT_TIMER_THREAD_PRIO */ /* soft timer status */ static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE; @@ -44,7 +44,7 @@ static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; static struct rt_thread timer_thread; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; -#endif +#endif /* RT_USING_TIMER_SOFT */ #ifdef RT_USING_HOOK extern void (*rt_object_take_hook)(struct rt_object *object); @@ -81,7 +81,7 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) } /**@}*/ -#endif +#endif /* RT_USING_HOOK */ static void _rt_timer_init(rt_timer_t timer, void (*timeout)(void *parameter), @@ -171,7 +171,7 @@ void rt_timer_dump(rt_list_t timer_heads[]) } rt_kprintf("\n"); } -#endif +#endif /* RT_DEBUG_TIMER */ /** * @addtogroup Clock @@ -303,7 +303,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer) return RT_EOK; } RTM_EXPORT(rt_timer_delete); -#endif +#endif /* RT_USING_HEAP */ /** * This function will start the timer @@ -348,7 +348,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) timer_list = rt_soft_timer_list; } else -#endif +#endif /* RT_USING_TIMER_SOFT */ { /* insert timer to system timer list */ timer_list = rt_timer_list; @@ -422,7 +422,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) rt_schedule(); } } -#endif +#endif /* RT_USING_TIMER_SOFT */ return RT_EOK; } @@ -718,7 +718,7 @@ static void rt_thread_timer_entry(void *parameter) rt_soft_timer_check(); } } -#endif +#endif /* RT_USING_TIMER_SOFT */ /** * @ingroup SystemInit @@ -764,7 +764,7 @@ void rt_system_timer_thread_init(void) /* startup */ rt_thread_startup(&timer_thread); -#endif +#endif /* RT_USING_TIMER_SOFT */ } /**@}*/ -- cgit v1.3.1 From fa1f1ef485734d990f9a5aecb001d3a0aa0eb59a Mon Sep 17 00:00:00 2001 From: yangjie Date: Fri, 11 Jun 2021 10:00:23 +0800 Subject: [src] add RT_WEAK for rt_malloc_align,rt_free_align --- src/kservice.c | 4 ++-- src/memheap.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 7ed05b6651..40040f7885 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1238,7 +1238,7 @@ RTM_EXPORT(rt_kprintf); * * @return the allocated memory block on successful, otherwise returns RT_NULL */ -void *rt_malloc_align(rt_size_t size, rt_size_t align) +RT_WEAK void *rt_malloc_align(rt_size_t size, rt_size_t align) { void *ptr; void *align_ptr; @@ -1284,7 +1284,7 @@ RTM_EXPORT(rt_malloc_align); * * @param ptr the memory block pointer */ -void rt_free_align(void *ptr) +RT_WEAK void rt_free_align(void *ptr) { void *real_ptr; diff --git a/src/memheap.c b/src/memheap.c index 35a04c14b1..80f27a461f 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -757,6 +757,8 @@ static struct rt_memheap _heap; void rt_system_heap_init(void *begin_addr, void *end_addr) { + RT_ASSERT((rt_uint32_t)end_addr > (rt_uint32_t)begin_addr); + /* initialize a default heap in the system */ rt_memheap_init(&_heap, "heap", -- cgit v1.3.1 From 4fa92ae3f6766863035238da9ae2b46622abb8a9 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 11 Jun 2021 13:07:29 +0800 Subject: [kernel] 补充endif后缀注释(4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mem.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/mem.c b/src/mem.c index ac0d27f2c3..e2328cc234 100644 --- a/src/mem.c +++ b/src/mem.c @@ -52,7 +52,6 @@ #ifndef RT_USING_MEMHEAP_AS_HEAP -/* #define RT_MEM_DEBUG */ #define RT_MEM_STATS #if defined (RT_USING_HEAP) && defined (RT_USING_SMALL_MEM) @@ -90,7 +89,7 @@ void rt_free_sethook(void (*hook)(void *ptr)) /**@}*/ -#endif +#endif /* RT_USING_HOOK */ #define HEAP_MAGIC 0x1ea0 struct heap_mem @@ -100,7 +99,7 @@ struct heap_mem rt_uint16_t used; #ifdef ARCH_CPU_64BIT rt_uint32_t resv; -#endif +#endif /* ARCH_CPU_64BIT */ rt_size_t next, prev; @@ -109,8 +108,8 @@ struct heap_mem rt_uint8_t thread[8]; #else rt_uint8_t thread[4]; /* thread name */ -#endif -#endif +#endif /* ARCH_CPU_64BIT */ +#endif /* RT_USING_MEMTRACE */ }; /** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */ @@ -123,7 +122,7 @@ static struct heap_mem *heap_end; #define MIN_SIZE 24 #else #define MIN_SIZE 12 -#endif +#endif /* ARCH_CPU_64BIT */ #define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE) #define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE) @@ -135,7 +134,8 @@ static rt_size_t mem_size_aligned; #ifdef RT_MEM_STATS static rt_size_t used_mem, max_mem; -#endif +#endif /* RT_MEM_STATS */ + #ifdef RT_USING_MEMTRACE rt_inline void rt_mem_setname(struct heap_mem *mem, const char *name) { @@ -151,7 +151,7 @@ rt_inline void rt_mem_setname(struct heap_mem *mem, const char *name) mem->thread[index] = ' '; } } -#endif +#endif /* RT_USING_MEMTRACE */ static void plug_holes(struct heap_mem *mem) { @@ -238,7 +238,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) mem->used = 0; #ifdef RT_USING_MEMTRACE rt_mem_setname(mem, "INIT"); -#endif +#endif /* RT_USING_MEMTRACE */ /* initialize the end of the heap */ heap_end = (struct heap_mem *)&heap_ptr[mem->next]; @@ -248,7 +248,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) heap_end->prev = mem_size_aligned + SIZEOF_STRUCT_MEM; #ifdef RT_USING_MEMTRACE rt_mem_setname(heap_end, "INIT"); -#endif +#endif /* RT_USING_MEMTRACE */ rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO); @@ -336,7 +336,7 @@ void *rt_malloc(rt_size_t size) mem2->prev = ptr; #ifdef RT_USING_MEMTRACE rt_mem_setname(mem2, " "); -#endif +#endif /* RT_USING_MEMTRACE */ /* and insert it between mem and mem->next */ mem->next = ptr2; @@ -350,7 +350,7 @@ void *rt_malloc(rt_size_t size) used_mem += (size + SIZEOF_STRUCT_MEM); if (max_mem < used_mem) max_mem = used_mem; -#endif +#endif /* RT_MEM_STATS */ } else { @@ -366,7 +366,7 @@ void *rt_malloc(rt_size_t size) used_mem += mem->next - ((rt_uint8_t *)mem - heap_ptr); if (max_mem < used_mem) max_mem = used_mem; -#endif +#endif /* RT_MEM_STATS */ } /* set memory block magic */ mem->magic = HEAP_MAGIC; @@ -375,7 +375,7 @@ void *rt_malloc(rt_size_t size) rt_mem_setname(mem, rt_thread_self()->name); else rt_mem_setname(mem, "NONE"); -#endif +#endif /* RT_USING_MEMTRACE */ if (mem == lfree) { @@ -473,7 +473,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize) /* split memory block */ #ifdef RT_MEM_STATS used_mem -= (size - newsize); -#endif +#endif /* RT_MEM_STATS */ ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize; mem2 = (struct heap_mem *)&heap_ptr[ptr2]; @@ -483,7 +483,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize) mem2->prev = ptr; #ifdef RT_USING_MEMTRACE rt_mem_setname(mem2, " "); -#endif +#endif /* RT_USING_MEMTRACE */ mem->next = ptr2; if (mem2->next != mem_size_aligned + SIZEOF_STRUCT_MEM) { @@ -597,7 +597,7 @@ void rt_free(void *rmem) mem->magic = HEAP_MAGIC; #ifdef RT_USING_MEMTRACE rt_mem_setname(mem, " "); -#endif +#endif /* RT_USING_MEMTRACE */ if (mem < lfree) { @@ -607,7 +607,7 @@ void rt_free(void *rmem) #ifdef RT_MEM_STATS used_mem -= (mem->next - ((rt_uint8_t *)mem - heap_ptr)); -#endif +#endif /* RT_MEM_STATS */ /* finally, see if prev or next are free also */ plug_holes(mem); @@ -706,12 +706,12 @@ int memtrace(int argc, char **argv) return 0; } MSH_CMD_EXPORT(memtrace, dump memory trace information); -#endif /* end of RT_USING_MEMTRACE */ -#endif /* end of RT_USING_FINSH */ +#endif /* RT_USING_MEMTRACE */ +#endif /* RT_USING_FINSH */ -#endif +#endif /* defined (RT_USING_HEAP) && defined (RT_USING_SMALL_MEM) */ /**@}*/ -#endif /* end of RT_USING_HEAP */ -#endif /* end of RT_USING_MEMHEAP_AS_HEAP */ +#endif /* RT_MEM_STATS */ +#endif /* RT_USING_MEMHEAP_AS_HEAP */ -- cgit v1.3.1 From 921e6064260f7afa80f3d10424bd49526241a3ee Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 13 Jun 2021 17:36:42 +0800 Subject: 将defined(__CC_ARM) || defined(__CLANG_ARM) 改为 ifdef __ARMCC_VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/shell.c | 2 +- include/libc/libc_signal.h | 2 +- include/rtlibc.h | 2 +- include/rtthread.h | 2 +- src/components.c | 4 ++-- src/kservice.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/components/finsh/shell.c b/components/finsh/shell.c index a749660629..c89139c0ed 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -817,7 +817,7 @@ int finsh_system_init(void) rt_thread_t tid; #ifdef FINSH_USING_SYMTAB -#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ +#ifdef __ARMCC_VERSION /* ARM C Compiler */ extern const int FSymTab$$Base; extern const int FSymTab$$Limit; extern const int VSymTab$$Base; diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index 8a4cc0d738..1fb8194643 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -71,7 +71,7 @@ typedef unsigned long sigset_t; #include -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION #define SIGHUP 1 /* #define SIGINT 2 */ diff --git a/include/rtlibc.h b/include/rtlibc.h index a62051e157..4e7caa81fc 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -22,7 +22,7 @@ #include "libc/libc_stdio.h" #ifndef RT_USING_LIBC -#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) +#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) typedef signed long off_t; typedef int mode_t; #endif diff --git a/include/rtthread.h b/include/rtthread.h index ccd2d147a8..cf897b0e5e 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -567,7 +567,7 @@ rt_size_t rt_strlen(const char *src); #endif /*RT_KSERVICE_USING_STDLIB*/ char *rt_strdup(const char *s); -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION /* lack strdup interface */ char* strdup(const char* str); #endif diff --git a/src/components.c b/src/components.c index d684d5e6fd..e156b783e4 100644 --- a/src/components.c +++ b/src/components.c @@ -134,7 +134,7 @@ void rt_application_init(void); void rt_hw_board_init(void); int rtthread_startup(void); -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION extern int $Super$$main(void); /* re-define main function */ int $Sub$$main(void) @@ -183,7 +183,7 @@ void main_thread_entry(void *parameter) rt_hw_secondary_cpu_up(); #endif /* RT_USING_SMP */ /* invoke system main function */ -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION { extern int $Super$$main(void); $Super$$main(); /* for ARMCC. */ diff --git a/src/kservice.c b/src/kservice.c index 448b2d717d..49e1486078 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -532,7 +532,7 @@ char *rt_strdup(const char *s) return tmp; } RTM_EXPORT(rt_strdup); -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION char *strdup(const char *s) __attribute__((alias("rt_strdup"))); #endif #endif /* RT_USING_HEAP */ -- cgit v1.3.1 From ec3c1d4d0085c57d996a5c6acc21e7dbde85b30f Mon Sep 17 00:00:00 2001 From: 杨澄 <36236188+Eureka1024@users.noreply.github.com> Date: Wed, 23 Jun 2021 21:23:07 +0800 Subject: [kernel] Fix comment error for rt_mutex_detach(). --- src/ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index c981aabe43..959f0fb522 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -588,7 +588,7 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex) /* wakeup all suspended threads */ rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); - /* detach semaphore object */ + /* detach mutex object */ rt_object_detach(&(mutex->parent.parent)); return RT_EOK; -- cgit v1.3.1 From 05bb1a50b0d26b7c60c82ccb4ff8a66a501feac3 Mon Sep 17 00:00:00 2001 From: fenghuijie Date: Sat, 3 Jul 2021 17:54:58 +0800 Subject: 添加idle回收资源的修改 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 6 ++- src/Kconfig | 5 ++ src/idle.c | 154 +++++++++++++++++++++++++++++++++++++++++++++-------- src/scheduler.c | 5 -- src/thread.c | 40 ++++++++------ 5 files changed, 168 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/include/rtthread.h b/include/rtthread.h index 0583ce6434..f9d0b45e86 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -168,7 +168,6 @@ void rt_thread_idle_init(void); rt_err_t rt_thread_idle_sethook(void (*hook)(void)); rt_err_t rt_thread_idle_delhook(void (*hook)(void)); #endif -void rt_thread_idle_excute(void); rt_thread_t rt_thread_idle_gethandler(void); /* @@ -187,6 +186,7 @@ rt_uint16_t rt_critical_level(void); #ifdef RT_USING_HOOK void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to)); +void rt_scheduler_switchto_sethook(void (*hook)(struct rt_thread *tid)); #endif #ifdef RT_USING_SMP @@ -396,6 +396,10 @@ rt_err_t rt_mq_recv(rt_mq_t mq, rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg); #endif +/* defunct */ +void rt_thread_defunct_enqueue(rt_thread_t thread); +rt_thread_t rt_thread_defunct_dequeue(void); + /* * spinlock */ diff --git a/src/Kconfig b/src/Kconfig index 9a49146dff..e0582f5663 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -98,6 +98,11 @@ config IDLE_THREAD_STACK_SIZE int "The stack size of idle thread" default 256 +config SYSTEM_THREAD_STACK_SIZE + int "The stack size of system thread (for defunct etc.)" + depends on RT_USING_SMP + default IDLE_THREAD_STACK_SIZE + config RT_USING_TIMER_SOFT bool "Enable software timer with a timer thread" default y diff --git a/src/idle.c b/src/idle.c index db256a6010..a571e487cf 100644 --- a/src/idle.c +++ b/src/idle.c @@ -44,12 +44,22 @@ #define _CPUS_NR 1 #endif /* RT_USING_SMP */ -extern rt_list_t rt_thread_defunct; +static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);; static struct rt_thread idle[_CPUS_NR]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t rt_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE]; +#ifdef RT_USING_SMP +#ifndef SYSTEM_THREAD_STACK_SIZE +#define SYSTEM_THREAD_STACK_SIZE IDLE_THREAD_STACK_SIZE +#endif +static struct rt_thread rt_system_thread; +ALIGN(RT_ALIGN_SIZE) +static rt_uint8_t rt_system_stack[SYSTEM_THREAD_STACK_SIZE]; +static struct rt_semaphore system_sem; +#endif + #ifdef RT_USING_IDLE_HOOK #ifndef RT_IDLE_HOOK_LIST_SIZE #define RT_IDLE_HOOK_LIST_SIZE 4 @@ -127,43 +137,75 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void)) #endif /* RT_USING_IDLE_HOOK */ -#ifdef RT_USING_HEAP +#ifdef RT_USING_MODULE /* Return whether there is defunctional thread to be deleted. */ rt_inline int _has_defunct_thread(void) { /* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)". - * So the compiler has a good reason that the rt_thread_defunct list does - * not change within rt_thread_idle_excute thus optimize the "while" loop + * So the compiler has a good reason that the _rt_thread_defunct list does + * not change within rt_thread_defunct_exceute thus optimize the "while" loop * 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; } -#endif /* RT_USING_HEAP */ +#endif /* RT_USING_MODULE */ + +/* enqueue a thread to defunct queue + * it must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable + */ +void rt_thread_defunct_enqueue(rt_thread_t thread) +{ + rt_list_insert_after(&_rt_thread_defunct, &thread->tlist); +#ifdef RT_USING_SMP + rt_sem_release(&system_sem); +#endif +} + +/* dequeue a thread from defunct queue + * it must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable + */ +rt_thread_t rt_thread_defunct_dequeue(void) +{ + rt_thread_t thread = RT_NULL; + rt_list_t *l = &_rt_thread_defunct; + + if (l->next != l) + { + thread = rt_list_entry(l->next, + struct rt_thread, + tlist); + rt_list_remove(&(thread->tlist)); + } + return thread; +} /** * @ingroup Thread * * This function will perform system background job when system idle. */ -void rt_thread_idle_excute(void) +static void rt_defunct_execute(void) { - /* Loop until there is no dead thread. So one call to rt_thread_idle_excute + /* Loop until there is no dead thread. So one call to rt_defunct_execute * will do all the cleanups. */ - /* disable interrupt */ - - RT_DEBUG_NOT_IN_INTERRUPT; - -#ifdef RT_USING_HEAP while (1) { rt_base_t lock; rt_thread_t thread; + void (*cleanup)(struct rt_thread *tid); +#ifdef RT_USING_MODULE + struct rt_dlmodule *module = RT_NULL; +#endif + RT_DEBUG_NOT_IN_INTERRUPT; + + /* disable interrupt */ lock = rt_hw_interrupt_disable(); +#ifdef RT_USING_MODULE /* check whether list is empty */ if (!_has_defunct_thread()) { @@ -171,18 +213,56 @@ void rt_thread_idle_excute(void) break; } /* get defunct thread */ - thread = rt_list_entry(rt_thread_defunct.next, + thread = rt_list_entry(_rt_thread_defunct.next, struct rt_thread, tlist); + module = (struct rt_dlmodule*)thread->module_id; + if (module) + { + dlmodule_destroy(module); + } /* remove defunct thread */ rt_list_remove(&(thread->tlist)); - /* release thread's stack */ - RT_KERNEL_FREE(thread->stack_addr); - /* delete thread object */ - rt_object_delete((rt_object_t)thread); - rt_hw_interrupt_enable(lock); +#else + thread = rt_thread_defunct_dequeue(); + if (!thread) + { + rt_hw_interrupt_enable(lock); + break; + } +#endif + /* invoke thread cleanup */ + cleanup = thread->cleanup; + if (cleanup != RT_NULL) + { + rt_hw_interrupt_enable(lock); + cleanup(thread); + lock = rt_hw_interrupt_disable(); + } + +#ifdef RT_USING_SIGNALS + rt_thread_free_sig(thread); +#endif + + /* if it's a system object, not delete it */ + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + /* detach this object */ + rt_object_detach((rt_object_t)thread); + /* enable interrupt */ + rt_hw_interrupt_enable(lock); + } + else + { + rt_hw_interrupt_enable(lock); +#ifdef RT_USING_HEAP + /* release thread's stack */ + RT_KERNEL_FREE(thread->stack_addr); + /* delete thread object */ + rt_object_delete((rt_object_t)thread); +#endif + } } -#endif /* RT_USING_HEAP */ } extern void rt_system_power_manager(void); @@ -214,13 +294,27 @@ static void rt_thread_idle_entry(void *parameter) } #endif /* RT_USING_IDLE_HOOK */ - rt_thread_idle_excute(); +#ifndef RT_USING_SMP + rt_defunct_execute(); +#endif /* RT_USING_SMP */ + #ifdef RT_USING_PM rt_system_power_manager(); #endif /* RT_USING_PM */ } } +#ifdef RT_USING_SMP +static void rt_thread_system_entry(void *parameter) +{ + while (1) + { + rt_sem_take(&system_sem, RT_WAITING_FOREVER); + rt_defunct_execute(); + } +} +#endif + /** * @ingroup SystemInit * @@ -250,6 +344,24 @@ void rt_thread_idle_init(void) /* startup */ rt_thread_startup(&idle[i]); } + +#ifdef RT_USING_SMP + RT_ASSERT(RT_THREAD_PRIORITY_MAX > 2); + + rt_sem_init(&system_sem, "defunct", 1, RT_IPC_FLAG_FIFO); + + /* create defunct thread */ + rt_thread_init(&rt_system_thread, + "tsystem", + rt_thread_system_entry, + RT_NULL, + rt_system_stack, + sizeof(rt_system_stack), + RT_THREAD_PRIORITY_MAX - 2, + 32); + /* startup */ + rt_thread_startup(&rt_system_thread); +#endif } /** diff --git a/src/scheduler.c b/src/scheduler.c index eec660a8aa..956d95d7cc 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -47,8 +47,6 @@ struct rt_thread *rt_current_thread = RT_NULL; rt_uint8_t rt_current_priority; #endif /* RT_USING_SMP */ -rt_list_t rt_thread_defunct; - #ifdef RT_USING_HOOK static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); @@ -224,9 +222,6 @@ void rt_system_scheduler_init(void) /* initialize ready table */ rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table)); #endif /* RT_THREAD_PRIORITY_MAX > 32 */ - - /* initialize thread defunct */ - rt_list_init(&rt_thread_defunct); } /** diff --git a/src/thread.c b/src/thread.c index c0a8f0ee74..88cc7b61ba 100644 --- a/src/thread.c +++ b/src/thread.c @@ -32,8 +32,6 @@ #include #include -extern rt_list_t rt_thread_defunct; - #ifdef RT_USING_HOOK static void (*rt_thread_suspend_hook)(rt_thread_t thread); static void (*rt_thread_resume_hook) (rt_thread_t thread); @@ -131,7 +129,7 @@ static void _rt_thread_exit(void) else { /* insert to defunct thread list */ - rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); + rt_thread_defunct_enqueue(thread); } /* switch to next task */ @@ -379,17 +377,22 @@ rt_err_t rt_thread_detach(rt_thread_t thread) /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); - /* disable interrupt */ - lock = rt_hw_interrupt_disable(); - /* change stat */ thread->stat = RT_THREAD_CLOSE; - /* detach thread object */ - rt_object_detach((rt_object_t)thread); - - /* enable interrupt */ - rt_hw_interrupt_enable(lock); + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + rt_object_detach((rt_object_t)thread); + } + else + { + /* disable interrupt */ + lock = rt_hw_interrupt_disable(); + /* insert to defunct thread list */ + rt_thread_defunct_enqueue(thread); + /* enable interrupt */ + rt_hw_interrupt_enable(lock); + } return RT_EOK; } @@ -484,7 +487,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) thread->stat = RT_THREAD_CLOSE; /* insert to defunct thread list */ - rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); + rt_thread_defunct_enqueue(thread); /* enable interrupt */ rt_hw_interrupt_enable(lock); @@ -847,12 +850,12 @@ rt_err_t rt_thread_resume(rt_thread_t thread) rt_timer_stop(&thread->thread_timer); - /* enable interrupt */ - rt_hw_interrupt_enable(temp); - /* insert to schedule ready list */ rt_schedule_insert_thread(thread); + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + RT_OBJECT_HOOK_CALL(rt_thread_resume_hook, (thread)); return RT_EOK; } @@ -867,6 +870,7 @@ RTM_EXPORT(rt_thread_resume); void rt_thread_timeout(void *parameter) { struct rt_thread *thread; + register rt_base_t temp; thread = (struct rt_thread *)parameter; @@ -875,6 +879,9 @@ void rt_thread_timeout(void *parameter) RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + /* set error number */ thread->error = -RT_ETIMEOUT; @@ -884,6 +891,9 @@ void rt_thread_timeout(void *parameter) /* insert to schedule ready list */ rt_schedule_insert_thread(thread); + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + /* do schedule */ rt_schedule(); } -- cgit v1.3.1 From 0015af02e4f08ab47f2d2fefcb7c1aca1682bfda Mon Sep 17 00:00:00 2001 From: fenghuijie Date: Mon, 5 Jul 2021 18:33:22 +0800 Subject: 调整代码,以支持cpu usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 4 ++++ include/rtthread.h | 1 + libcpu/arm/cortex-a/interrupt.c | 14 ++++++++++++++ libcpu/arm/cortex-a/start_gcc.S | 2 ++ src/irq.c | 2 +- src/scheduler.c | 13 +++++++++++++ src/thread.c | 4 ++++ 7 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/include/rtdef.h b/include/rtdef.h index 2eb2cc1963..e1a64a433a 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -663,6 +663,10 @@ struct rt_thread rt_ubase_t init_tick; /**< thread's initialized tick */ rt_ubase_t remaining_tick; /**< remaining tick */ +#ifdef RT_USING_CPU_USAGE + rt_uint64_t duration_tick; /**< cpu usage tick */ +#endif + struct rt_timer thread_timer; /**< built-in thread timer */ void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */ diff --git a/include/rtthread.h b/include/rtthread.h index f2f4091b8a..cf47a48efe 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -186,6 +186,7 @@ rt_uint16_t rt_critical_level(void); #ifdef RT_USING_HOOK void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to)); +void rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid)); #endif #ifdef RT_USING_SMP diff --git a/libcpu/arm/cortex-a/interrupt.c b/libcpu/arm/cortex-a/interrupt.c index 474a23fee1..f90f1c0094 100644 --- a/libcpu/arm/cortex-a/interrupt.c +++ b/libcpu/arm/cortex-a/interrupt.c @@ -27,6 +27,20 @@ struct rt_irq_desc isr_table[MAX_HANDLERS]; rt_uint32_t rt_interrupt_from_thread = 0; rt_uint32_t rt_interrupt_to_thread = 0; rt_uint32_t rt_thread_switch_interrupt_flag = 0; + +#ifdef RT_USING_HOOK +static void (*rt_interrupt_switch_hook)(void); + +void rt_interrupt_switch_sethook(void (*hook)(void)) +{ + rt_interrupt_switch_hook = hook; +} +#endif + +void rt_interrupt_hook(void) +{ + RT_OBJECT_HOOK_CALL(rt_interrupt_switch_hook, ()); +} #endif const unsigned int VECTOR_BASE = 0x00; diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 6c5dd81785..908468476e 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -341,6 +341,8 @@ rt_hw_context_switch_interrupt_do: ldr r6, [r6] ldr sp, [r6] @ get new task's stack pointer + bl rt_interrupt_hook + #ifdef RT_USING_FPU /* fpu context */ ldmfd sp!, {r6} diff --git a/src/irq.c b/src/irq.c index e89b8504dc..6ddcb3dd4a 100644 --- a/src/irq.c +++ b/src/irq.c @@ -89,8 +89,8 @@ void rt_interrupt_leave(void) rt_interrupt_nest)); level = rt_hw_interrupt_disable(); - rt_interrupt_nest --; RT_OBJECT_HOOK_CALL(rt_interrupt_leave_hook,()); + rt_interrupt_nest --; rt_hw_interrupt_enable(level); } RTM_EXPORT(rt_interrupt_leave); diff --git a/src/scheduler.c b/src/scheduler.c index 956d95d7cc..353fdad5cb 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -49,6 +49,7 @@ rt_uint8_t rt_current_priority; #ifdef RT_USING_HOOK static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); +static void (*rt_scheduler_switch_hook)(struct rt_thread *tid); /** * @addtogroup Hook @@ -68,6 +69,12 @@ rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to)) rt_scheduler_hook = hook; } +void +rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid)) +{ + rt_scheduler_switch_hook = hook; +} + /**@}*/ #endif /* RT_USING_HOOK */ @@ -364,6 +371,8 @@ void rt_schedule(void) _rt_scheduler_stack_check(to_thread); #endif /* RT_USING_OVERFLOW_CHECK */ + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (current_thread)); + rt_hw_context_switch((rt_ubase_t)¤t_thread->sp, (rt_ubase_t)&to_thread->sp, to_thread); } @@ -473,6 +482,8 @@ void rt_schedule(void) { extern void rt_thread_handle_sig(rt_bool_t clean_state); + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (from_thread)); + rt_hw_context_switch((rt_ubase_t)&from_thread->sp, (rt_ubase_t)&to_thread->sp); @@ -609,6 +620,8 @@ void rt_scheduler_do_irq_switch(void *context) current_thread->cpus_lock_nest--; current_thread->scheduler_lock_nest--; + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (current_thread)); + rt_hw_context_switch_interrupt(context, (rt_ubase_t)¤t_thread->sp, (rt_ubase_t)&to_thread->sp, to_thread); } diff --git a/src/thread.c b/src/thread.c index 88cc7b61ba..60e6ab91d1 100644 --- a/src/thread.c +++ b/src/thread.c @@ -228,6 +228,10 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->lwp = RT_NULL; #endif /* RT_USING_LWP */ +#ifdef RT_USING_CPU_USAGE + thread->duration_tick = 0; +#endif + RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread)); return RT_EOK; -- cgit v1.3.1 From edcdd126edf86b9990e15449ab69c8554da9e274 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 7 Jul 2021 03:30:01 +0800 Subject: [kernel][ipc] 移除mutex RT_IPC_FLAG_FIFO 功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 959f0fb522..6a038cd2b6 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -548,6 +548,8 @@ RTM_EXPORT(rt_sem_control); */ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) { + (void)flag; + /* parameter check */ RT_ASSERT(mutex != RT_NULL); @@ -562,8 +564,8 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) mutex->original_priority = 0xFF; mutex->hold = 0; - /* set flag */ - mutex->parent.parent.flag = flag; + /* set flag and it can only be RT_IPC_FLAG_PRIO */ + mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; return RT_EOK; } @@ -609,6 +611,7 @@ RTM_EXPORT(rt_mutex_detach); rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) { struct rt_mutex *mutex; + (void)flag; RT_DEBUG_NOT_IN_INTERRUPT; @@ -625,8 +628,8 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) mutex->original_priority = 0xFF; mutex->hold = 0; - /* set flag */ - mutex->parent.parent.flag = flag; + /* set flag and it can only be RT_IPC_FLAG_PRIO */ + mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; return mutex; } -- cgit v1.3.1 From 6e334416e3c855ef17a2a59eba816408ac296a75 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 7 Jul 2021 10:16:49 +0800 Subject: [ipc][mutex] 补充注释 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 6a038cd2b6..6bc9c079b9 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -564,7 +564,7 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) mutex->original_priority = 0xFF; mutex->hold = 0; - /* set flag and it can only be RT_IPC_FLAG_PRIO */ + /* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */ mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; return RT_EOK; @@ -628,7 +628,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) mutex->original_priority = 0xFF; mutex->hold = 0; - /* set flag and it can only be RT_IPC_FLAG_PRIO */ + /* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */ mutex->parent.parent.flag = RT_IPC_FLAG_PRIO; return mutex; -- cgit v1.3.1 From 9f3e349f69c66fb27496492d0f0c3cefa0bb891b Mon Sep 17 00:00:00 2001 From: chenjh Date: Fri, 9 Jul 2021 10:54:51 +0800 Subject: [comment] Optimize the comment for ipc --- src/ipc.c | 1079 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 848 insertions(+), 231 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 6bc9c079b9..8acfd831d7 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -57,11 +57,16 @@ extern void (*rt_object_put_hook)(struct rt_object *object); /**@{*/ /** - * This function will initialize an IPC object + * @brief This function will initialize an IPC object, such as semaphore, mutex, messagequeue and mailbox. * - * @param ipc the IPC object + * @note Executing this function will complete an initialization of the suspend thread list of the ipc object. * - * @return the operation status, RT_EOK on successful + * @param ipc is a pointer to the IPC object. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * When the return value is any other values, it means the initialization failed. + * + * @warning This function can be called from all IPC initialization and creation. */ rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc) { @@ -71,16 +76,35 @@ rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc) return RT_EOK; } + /** - * This function will suspend a thread to a specified list. IPC object or some - * double-queue object (mailbox etc.) contains this kind of list. + * @brief This function will suspend a thread to a IPC object list. + * + * @param list is a pointer to a suspended thread list of the IPC object. + * + * @param thread is a pointer to the thread object to be suspended. + * + * @param flag is a flag for the thread object to be suspended. It determines how the thread is suspended. + * The flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. + * + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to use + * RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this semaphore will become non-real-time threads. * - * @param list the IPC suspended thread list - * @param thread the thread object to be suspended - * @param flag the IPC object flag, - * which shall be RT_IPC_FLAG_FIFO/RT_IPC_FLAG_PRIO. + * @return Return the operation status. When the return value is RT_EOK, the function is successfully executed. + * When the return value is any other values, it means the initialization failed. * - * @return the operation status, RT_EOK on successful + * @warning This function can ONLY be called in the thread context, you can use RT_DEBUG_IN_THREAD_CONTEXT to + * check the context. + * In addition, this function is generally called by the following functions: + * rt_sem_take(), rt_mutex_take(), rt_event_recv(), rt_mb_send_wait(), + * rt_mb_recv(), rt_mq_recv(), rt_mq_send_wait() */ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, struct rt_thread *thread, @@ -131,14 +155,25 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, return RT_EOK; } + /** - * This function will resume the first thread in the list of a IPC object: - * - remove the thread from suspend queue of IPC object - * - put the thread into system ready queue + * @brief This function will resume a thread. + * + * @note This function will resume the first thread in the list of a IPC object. + * 1. remove the thread from suspend queue of a IPC object. + * 2. put the thread into system ready queue. + * + * By contrast, the rt_ipc_list_resume_all() function will resume all suspended threads + * in the list of a IPC object. + * + * @param list is a pointer to a suspended thread list of the IPC object. * - * @param list the thread list + * @return Return the operation status. When the return value is RT_EOK, the function is successfully executed. + * When the return value is any other values, it means this operation failed. * - * @return the operation status, RT_EOK on successful + * @warning This function is generally called by the following functions: + * rt_sem_release(), rt_mutex_release(), rt_mb_send_wait(), rt_mq_send_wait(), + * rt_mb_urgent(), rt_mb_recv(), rt_mq_urgent(), rt_mq_recv(), */ rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list) { @@ -155,13 +190,19 @@ rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list) return RT_EOK; } + /** - * This function will resume all suspended threads in a list, including - * suspend list of IPC object and private list of mailbox etc. + * @brief This function will resume all suspended threads in the IPC object list, + * including the suspended list of IPC object, and private list of mailbox etc. + * + * @note This function will resume all threads in the IPC object list. + * By contrast, the rt_ipc_list_resume() function will resume a suspended thread in the list of a IPC object. * - * @param list of the threads to resume + * @param list is a pointer to a suspended thread list of the IPC object. + * + * @return Return the operation status. When the return value is RT_EOK, the function is successfully executed. + * When the return value is any other values, it means this operation failed. * - * @return the operation status, RT_EOK on successful */ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) { @@ -193,17 +234,51 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) return RT_EOK; } +/**@}*/ + #ifdef RT_USING_SEMAPHORE /** - * This function will initialize a semaphore and put it under control of - * resource management. + * @addtogroup semaphore + */ + +/**@{*/ +/** + * @brief This function will initialize a static semaphore object. + * + * @note For the static semaphore object, its memory space is allocated by the compiler during compiling, + * and shall placed on the read-write data segment or on the uninitialized data segment. + * By contrast, the rt_sem_create() function will allocate memory space automatically and initialize + * the semaphore. + * + * @see rt_sem_create() + * + * @param sem is a pointer to the semaphore to initialize. It is assumed that storage for the semaphore will be + * allocated in your application. * - * @param sem the semaphore object - * @param name the name of semaphore - * @param value the initial value of semaphore - * @param flag the flag of semaphore + * @param name is a pointer to the name you would like to give the semaphore. * - * @return the operation status, RT_EOK on successful + * @param value is the initial value for the semaphore. + * If used to share resources, you should initialize the value as the number of available resources. + * If used to signal the occurrence of an event, you should initialize the value as 0. + * + * @param flag is the semaphore flag, which determines the queuing way of how multiple threads wait + * when the semaphore is not available. + * The semaphore flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. + * + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this semaphore will become non-real-time threads. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it represents the initialization failed. + * + * @warning This function can ONLY be called from threads. */ rt_err_t rt_sem_init(rt_sem_t sem, const char *name, @@ -229,14 +304,24 @@ rt_err_t rt_sem_init(rt_sem_t sem, } RTM_EXPORT(rt_sem_init); + /** - * This function will detach a semaphore from resource management + * @brief This function will detach a static semaphore object. + * + * @note This function is used to detach a static semaphore object which is initialized by rt_sem_init() function. + * By contrast, the rt_sem_delete() function will delete a semaphore object. + * When the semaphore is successfully detached, it will resume all suspended threads in the semaphore list. * - * @param sem the semaphore object + * @see rt_sem_delete() * - * @return the operation status, RT_EOK on successful + * @param sem is a pointer to a semaphore object to be detached. * - * @see rt_sem_delete + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it means that the semaphore detach failed. + * + * @warning This function can ONLY detach a static semaphore initialized by the rt_sem_init() function. + * If the semaphore is created by the rt_sem_create() function, you MUST NOT USE this function to detach it, + * ONLY USE the rt_sem_delete() function to complete the deletion. */ rt_err_t rt_sem_detach(rt_sem_t sem) { @@ -257,15 +342,36 @@ RTM_EXPORT(rt_sem_detach); #ifdef RT_USING_HEAP /** - * This function will create a semaphore from system resource + * @brief Creating a semaphore object. + * + * @note For the semaphore object, its memory space is allocated automatically. + * By contrast, the rt_sem_init() function will initialize a static semaphore object. + * + * @see rt_sem_init() + * + * @param name is a pointer to the name you would like to give the semaphore. + * + * @param value is the initial value for the semaphore. + * If used to share resources, you should initialize the value as the number of available resources. + * If used to signal the occurrence of an event, you should initialize the value as 0. * - * @param name the name of semaphore - * @param value the initial value of semaphore - * @param flag the flag of semaphore + * @param flag is the semaphore flag, which determines the queuing way of how multiple threads wait + * when the semaphore is not available. + * The semaphore flag can be ONE of the following values: * - * @return the created semaphore, RT_NULL on error happen + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. * - * @see rt_sem_init + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this semaphore will become non-real-time threads. + * + * @return Return a pointer to the semaphore object. When the return value is RT_NULL, it means the creation failed. + * + * @warning This function can NOT be called in interrupt context. You can use macor RT_DEBUG_NOT_IN_INTERRUPT to check it. */ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) { @@ -292,14 +398,24 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) } RTM_EXPORT(rt_sem_create); + /** - * This function will delete a semaphore object and release the memory + * @brief This function will delete a semaphore object and release the memory space. * - * @param sem the semaphore object + * @note This function is used to delete a semaphore object which is created by the rt_sem_create() function. + * By contrast, the rt_sem_detach() function will detach a static semaphore object. + * When the semaphore is successfully deleted, it will resume all suspended threads in the semaphore list. * - * @return the error code + * @see rt_sem_detach() * - * @see rt_sem_detach + * @param sem is a pointer to a semaphore object to be deleted. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the semaphore detach failed. + * + * @warning This function can ONLY delete a semaphore initialized by the rt_sem_create() function. + * If the semaphore is initialized by the rt_sem_init() function, you MUST NOT USE this function to delete it, + * ONLY USE the rt_sem_detach() function to complete the detachment. */ rt_err_t rt_sem_delete(rt_sem_t sem) { @@ -321,14 +437,29 @@ rt_err_t rt_sem_delete(rt_sem_t sem) RTM_EXPORT(rt_sem_delete); #endif /* RT_USING_HEAP */ + /** - * This function will take a semaphore, if the semaphore is unavailable, the - * thread shall wait for a specified time. + * @brief This function will take a semaphore, if the semaphore is unavailable, the thread shall wait for + * the semaphore up to a specified time. + * + * @note When this function is called, the count value of the sem->value will decrease 1 until it is equal to 0. + * When the sem->value is 0, it means that the semaphore is unavailable. At this time, it will suspend the + * thread preparing to take the semaphore. + * On the contrary, the rt_sem_release() function will increase the count value of sem->value by 1 each time. * - * @param sem the semaphore object - * @param time the waiting time + * @see rt_sem_trytake() * - * @return the error code + * @param sem is a pointer to a semaphore object. + * + * @param time is a timeout period (unit: an OS tick). If the semaphore is unavailable, the thread will wait for + * the semaphore up to the amount of time specified by the argument. + * NOTE: Generally, we use the macro RT_WAITING_FOREVER to set this parameter, which means that when the + * semaphore is unavailable, the thread will be waitting forever. + * + * @return Return the operation status. ONLY When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the semaphore take failed. + * + * @warning This function can ONLY be called in the thread context. It MUST NOT BE called in interrupt context. */ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time) { @@ -418,12 +549,20 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time) } RTM_EXPORT(rt_sem_take); + /** - * This function will try to take a semaphore and immediately return + * @brief This function will try to take a semaphore, if the semaphore is unavailable, the thread returns immediately. * - * @param sem the semaphore object + * @note This function is very similar to the rt_sem_take() function, when the semaphore is not available, + * the rt_sem_trytake() function will return immediately without waiting for a timeout. + * In other words, rt_sem_trytake(sem) has the same effect as rt_sem_take(sem, 0). * - * @return the error code + * @see rt_sem_take() + * + * @param sem is a pointer to a semaphore object. + * + * @return Return the operation status. ONLY When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the semaphore take failed. */ rt_err_t rt_sem_trytake(rt_sem_t sem) { @@ -431,13 +570,18 @@ rt_err_t rt_sem_trytake(rt_sem_t sem) } RTM_EXPORT(rt_sem_trytake); + /** - * This function will release a semaphore, if there are threads suspended on - * semaphore, it will be waked up. + * @brief This function will release a semaphore. If there is thread suspended on the semaphore, it will get resumed. + * + * @note If there are threads suspended on this semaphore, the first thread in the list of this semaphore object + * will be resumed, and a thread scheduling (rt_schedule) will be executed. + * If no threads are suspended on this semaphore, the count value sem->value of this semaphore will increase by 1. * - * @param sem the semaphore object + * @param sem is a pointer to a semaphore object. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the semaphore release failed. */ rt_err_t rt_sem_release(rt_sem_t sem) { @@ -490,14 +634,20 @@ rt_err_t rt_sem_release(rt_sem_t sem) } RTM_EXPORT(rt_sem_release); + /** - * This function can get or set some extra attributions of a semaphore object. + * @brief This function will set some extra attributions of a semaphore object. + * + * @note Currently this function only supports the RT_IPC_CMD_RESET command to reset the semaphore. + * + * @param sem is a pointer to a semaphore object. + * + * @param cmd is a command word used to configure some attributions of the semaphore. * - * @param sem the semaphore object - * @param cmd the execution command - * @param arg the execution argument + * @param arg is the argument of the function to execute the command. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that this function failed to execute. */ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg) { @@ -533,18 +683,41 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_sem_control); + +/**@}*/ #endif /* RT_USING_SEMAPHORE */ #ifdef RT_USING_MUTEX /** - * This function will initialize a mutex and put it under control of resource - * management. + * @addtogroup mutex + */ + +/**@{*/ + +/** + * @brief Initialize a static mutex object. + * + * @note For the static mutex object, its memory space is allocated by the compiler during compiling, + * and shall placed on the read-write data segment or on the uninitialized data segment. + * By contrast, the rt_mutex_create() function will automatically allocate memory space + * and initialize the mutex. * - * @param mutex the mutex object - * @param name the name of mutex - * @param flag the flag of mutex + * @see rt_mutex_create() * - * @return the operation status, RT_EOK on successful + * @param mutex is a pointer to the mutex to initialize. It is assumed that storage for the mutex will be + * allocated in your application. + * + * @param name is a pointer to the name that given to the mutex. + * + * @param flag is the mutex flag, which determines the queuing way of how multiple threads wait + * when the mutex is not available. + * NOTE: The mutex flag can ONLY be RT_IPC_FLAG_PRIO. Using RT_IPC_FLAG_FIFO will seriously affect + * the real-time performance of the system. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it represents the initialization failed. + * + * @warning This function can ONLY be called from threads. */ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) { @@ -571,14 +744,24 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) } RTM_EXPORT(rt_mutex_init); + /** - * This function will detach a mutex from resource management + * @brief This function will detach a static mutex object. * - * @param mutex the mutex object + * @note This function is used to detach a static mutex object which is initialized by rt_mutex_init() function. + * By contrast, the rt_mutex_delete() function will delete a mutex object. + * When the mutex is successfully detached, it will resume all suspended threads in the mutex list. * - * @return the operation status, RT_EOK on successful + * @see rt_mutex_delete() * - * @see rt_mutex_delete + * @param mutex is a pointer to a mutex object to be detached. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it means that the mutex detach failed. + * + * @warning This function can ONLY detach a static mutex initialized by the rt_mutex_init() function. + * If the mutex is created by the rt_mutex_create() function, you MUST NOT USE this function to detach it, + * ONLY USE the rt_mutex_delete() function to complete the deletion. */ rt_err_t rt_mutex_detach(rt_mutex_t mutex) { @@ -599,14 +782,23 @@ RTM_EXPORT(rt_mutex_detach); #ifdef RT_USING_HEAP /** - * This function will create a mutex from system resource + * @brief This function will create a mutex object. + * + * @note For the mutex object, its memory space is automatically allocated. + * By contrast, the rt_mutex_init() function will initialize a static mutex object. + * + * @see rt_mutex_init() * - * @param name the name of mutex - * @param flag the flag of mutex + * @param name is a pointer to the name that given to the mutex. * - * @return the created mutex, RT_NULL on error happen + * @param flag is the mutex flag, which determines the queuing way of how multiple threads wait + * when the mutex is not available. + * NOTE: The mutex flag can ONLY be RT_IPC_FLAG_PRIO. Using RT_IPC_FLAG_FIFO will seriously affect + * the real-time performance of the system. * - * @see rt_mutex_init + * @return Return a pointer to the mutex object. When the return value is RT_NULL, it means the creation failed. + * + * @warning This function can ONLY be called from threads. */ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) { @@ -635,14 +827,24 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) } RTM_EXPORT(rt_mutex_create); + /** - * This function will delete a mutex object and release the memory + * @brief This function will delete a mutex object and release this memory space. + * + * @note This function is used to delete a mutex object which is created by the rt_mutex_create() function. + * By contrast, the rt_mutex_detach() function will detach a static mutex object. + * When the mutex is successfully deleted, it will resume all suspended threads in the mutex list. + * + * @see rt_mutex_detach() * - * @param mutex the mutex object + * @param mutex is a pointer to a mutex object to be deleted. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mutex detach failed. * - * @see rt_mutex_detach + * @warning This function can ONLY delete a mutex initialized by the rt_mutex_create() function. + * If the mutex is initialized by the rt_mutex_init() function, you MUST NOT USE this function to delete it, + * ONLY USE the rt_mutex_detach() function to complete the detachment. */ rt_err_t rt_mutex_delete(rt_mutex_t mutex) { @@ -664,14 +866,29 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex) RTM_EXPORT(rt_mutex_delete); #endif /* RT_USING_HEAP */ + /** - * This function will take a mutex, if the mutex is unavailable, the - * thread shall wait for a specified time. + * @brief This function will take a mutex, if the mutex is unavailable, the thread shall wait for + * the mutex up to a specified time. + * + * @note When this function is called, the count value of the sem->value will decrease 1 until it is equal to 0. + * When the sem->value is 0, it means that the mutex is unavailable. At this time, it will suspend the + * thread preparing to take the mutex. + * On the contrary, the rt_sem_release() function will increase the count value of sem->value by 1 each time. + * + * @see rt_mutex_trytake() + * + * @param mutex is a pointer to a mutex object. * - * @param mutex the mutex object - * @param time the waiting time + * @param time is a timeout period (unit: an OS tick). If the mutex is unavailable, the thread will wait for + * the mutex up to the amount of time specified by the argument. + * NOTE: Generally, we set this parameter to RT_WAITING_FOREVER, which means that when the mutex is unavailable, + * the thread will be waitting forever. * - * @return the error code + * @return Return the operation status. ONLY When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mutex take failed. + * + * @warning This function can ONLY be called in the thread context. It MUST NOT BE called in interrupt context. */ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) { @@ -821,12 +1038,21 @@ __again: } RTM_EXPORT(rt_mutex_take); + /** - * This function will try to take a mutex and immediately return + * @brief This function will try to take a mutex, if the mutex is unavailable, the thread returns immediately. + * + * @note This function is very similar to the rt_mutex_take() function, when the mutex is not available, + * except that rt_mutex_trytake() will return immediately without waiting for a timeout + * when the mutex is not available. + * In other words, rt_mutex_trytake(mutex) has the same effect as rt_mutex_take(mutex, 0). + * + * @see rt_mutex_take() * - * @param mutex the mutex object + * @param mutex is a pointer to a mutex object. * - * @return the error code + * @return Return the operation status. ONLY When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mutex take failed. */ rt_err_t rt_mutex_trytake(rt_mutex_t mutex) { @@ -834,13 +1060,18 @@ rt_err_t rt_mutex_trytake(rt_mutex_t mutex) } RTM_EXPORT(rt_mutex_trytake); + /** - * This function will release a mutex, if there are threads suspended on mutex, - * it will be waked up. + * @brief This function will release a mutex. If there is thread suspended on the mutex, the thread will be resumed. + * + * @note If there are threads suspended on this mutex, the first thread in the list of this mutex object + * will be resumed, and a thread scheduling (rt_schedule) will be executed. + * If no threads are suspended on this mutex, the count value mutex->value of this mutex will increase by 1. * - * @param mutex the mutex object + * @param mutex is a pointer to a mutex object. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mutex release failed. */ rt_err_t rt_mutex_release(rt_mutex_t mutex) { @@ -953,14 +1184,20 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } RTM_EXPORT(rt_mutex_release); + /** - * This function can get or set some extra attributions of a mutex object. + * @brief This function will set some extra attributions of a mutex object. + * + * @note Currently this function does not implement the control function. * - * @param mutex the mutex object - * @param cmd the execution command - * @param arg the execution argument + * @param mutex is a pointer to a mutex object. * - * @return the error code + * @param cmd is a command word used to configure some attributions of the mutex. + * + * @param arg is the argument of the function to execute the command. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that this function failed to execute. */ rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg) { @@ -971,18 +1208,54 @@ rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_mutex_control); + +/**@}*/ #endif /* RT_USING_MUTEX */ #ifdef RT_USING_EVENT /** - * This function will initialize an event and put it under control of resource - * management. + * @addtogroup event + */ + +/**@{*/ + +/** + * @brief The function will initialize a static event object. + * + * @note For the static event object, its memory space is allocated by the compiler during compiling, + * and shall placed on the read-write data segment or on the uninitialized data segment. + * By contrast, the rt_event_create() function will allocate memory space automatically + * and initialize the event. + * + * @see rt_event_create() + * + * @param event is a pointer to the event to initialize. It is assumed that storage for the event + * will be allocated in your application. + * + * @param name is a pointer to the name that given to the event. + * + * @param value is the initial value for the event. + * If want to share resources, you should initialize the value as the number of available resources. + * If want to signal the occurrence of an event, you should initialize the value as 0. + * + * @param flag is the event flag, which determines the queuing way of how multiple threads wait + * when the event is not available. + * The event flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. * - * @param event the event object - * @param name the name of event - * @param flag the flag of event + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). * - * @return the operation status, RT_EOK on successful + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this event will become non-real-time threads. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it represents the initialization failed. + * + * @warning This function can ONLY be called from threads. */ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag) { @@ -1005,12 +1278,24 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag) } RTM_EXPORT(rt_event_init); + /** - * This function will detach an event object from resource management + * @brief This function will detach a static event object. + * + * @note This function is used to detach a static event object which is initialized by rt_event_init() function. + * By contrast, the rt_event_delete() function will delete an event object. + * When the event is successfully detached, it will resume all suspended threads in the event list. * - * @param event the event object + * @see rt_event_delete() * - * @return the operation status, RT_EOK on successful + * @param event is a pointer to an event object to be detached. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it means that the event detach failed. + * + * @warning This function can ONLY detach a static event initialized by the rt_event_init() function. + * If the event is created by the rt_event_create() function, you MUST NOT USE this function to detach it, + * ONLY USE the rt_event_delete() function to complete the deletion. */ rt_err_t rt_event_detach(rt_event_t event) { @@ -1031,12 +1316,32 @@ RTM_EXPORT(rt_event_detach); #ifdef RT_USING_HEAP /** - * This function will create an event object from system resource + * @brief Creating an event object. + * + * @note For the event object, its memory space is allocated automatically. + * By contrast, the rt_event_init() function will initialize a static event object. + * + * @see rt_event_init() * - * @param name the name of event - * @param flag the flag of event + * @param name is a pointer to the name that given to the event. * - * @return the created event, RT_NULL on error happen + * @param flag is the event flag, which determines the queuing way of how multiple threads wait when the event + * is not available. + * The event flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. + * + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this event will become non-real-time threads. + * + * @return Return a pointer to the event object. When the return value is RT_NULL, it means the creation failed. + * + * @warning This function can ONLY be called from threads. */ rt_event_t rt_event_create(const char *name, rt_uint8_t flag) { @@ -1062,12 +1367,24 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag) } RTM_EXPORT(rt_event_create); + /** - * This function will delete an event object and release the memory + * @brief This function will delete an event object and release the memory space. + * + * @note This function is used to delete an event object which is created by the rt_event_create() function. + * By contrast, the rt_event_detach() function will detach a static event object. + * When the event is successfully deleted, it will resume all suspended threads in the event list. + * + * @see rt_event_detach() * - * @param event the event object + * @param event is a pointer to an event object to be deleted. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the event detach failed. + * + * @warning This function can ONLY delete an event initialized by the rt_event_create() function. + * If the event is initialized by the rt_event_init() function, you MUST NOT USE this function to delete it, + * ONLY USE the rt_event_detach() function to complete the detachment. */ rt_err_t rt_event_delete(rt_event_t event) { @@ -1089,14 +1406,23 @@ rt_err_t rt_event_delete(rt_event_t event) RTM_EXPORT(rt_event_delete); #endif /* RT_USING_HEAP */ + /** - * This function will send an event to the event object, if there are threads - * suspended on event object, it will be waked up. + * @brief This function will send an event to the event object. + * If there is a thread suspended on the event, the thread will be resumed. + * + * @note When using this function, you need to use the parameter (set) to specify the event flag of the event object, + * then the function will traverse the list of suspended threads waiting on the event object. + * If there is a thread suspended on the event, and the thread's event_info and the event flag of + * the current event object matches, the thread will be resumed. + * + * @param event is a pointer to the event object to be sent. * - * @param event the event object - * @param set the event set + * @param set is a flag that you will set for this event's flag. + * You can set an event flag, or you can set multiple flags through OR logic operation. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the event detach failed. */ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set) { @@ -1190,18 +1516,38 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set) } RTM_EXPORT(rt_event_send); + /** - * This function will receive an event from event object, if the event is - * unavailable, the thread shall wait for a specified time. + * @brief This function will receive an event from event object. if the event is unavailable, the thread shall wait for + * the event up to a specified time. + * + * @note If there are threads suspended on this semaphore, the first thread in the list of this semaphore object + * will be resumed, and a thread scheduling (rt_schedule) will be executed. + * If no threads are suspended on this semaphore, the count value sem->value of this semaphore will increase by 1. + * + * @param event is a pointer to the event object to be received. + * + * @param set is a flag that you will set for this event's flag. + * You can set an event flag, or you can set multiple flags through OR logic operation. * - * @param event the fast event object - * @param set the interested event set - * @param option the receive option, either RT_EVENT_FLAG_AND or - * RT_EVENT_FLAG_OR should be set. - * @param timeout the waiting time - * @param recved the received event, if you don't care, RT_NULL can be set. + * @param option is the option of this receiving event, it indicates how the receiving event is operated. + * The option can be one or more of the following values, When selecting multiple values,use logical OR to operate. + * (NOTE: RT_EVENT_FLAG_OR and RT_EVENT_FLAG_AND can only select one): * - * @return the error code + * + * RT_EVENT_FLAG_OR The thread select to use logical OR to receive the event. + * + * RT_EVENT_FLAG_AND The thread select to use logical OR to receive the event. + * + * RT_EVENT_FLAG_CLEAR When the thread receives the corresponding event, the function + * determines whether to clear the event flag. + * + * @param timeout is a timeout period (unit: an OS tick). + * + * @param recved is a pointer to the received event. If you don't care about this value, you can use RT_NULL to set. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the semaphore release failed. */ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, @@ -1325,14 +1671,20 @@ rt_err_t rt_event_recv(rt_event_t event, } RTM_EXPORT(rt_event_recv); + /** - * This function can get or set some extra attributions of an event object. + * @brief This function will set some extra attributions of an event object. + * + * @note Currently this function only supports the RT_IPC_CMD_RESET command to reset the event. + * + * @param event is a pointer to an event object. * - * @param event the event object - * @param cmd the execution command - * @param arg the execution argument + * @param cmd is a command word used to configure some attributions of the event. * - * @return the error code + * @param arg is the argument of the function to execute the command. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that this function failed to execute. */ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) { @@ -1364,20 +1716,55 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_event_control); + +/**@}*/ #endif /* RT_USING_EVENT */ #ifdef RT_USING_MAILBOX /** - * This function will initialize a mailbox and put it under control of resource - * management. + * @addtogroup mailbox + */ + +/**@{*/ + +/** + * @brief Initialize a static mailbox object. * - * @param mb the mailbox object - * @param name the name of mailbox - * @param msgpool the begin address of buffer to save received mail - * @param size the size of mailbox - * @param flag the flag of mailbox + * @note For the static mailbox object, its memory space is allocated by the compiler during compiling, + * and shall placed on the read-write data segment or on the uninitialized data segment. + * By contrast, the rt_mb_create() function will allocate memory space automatically and initialize the mailbox. * - * @return the operation status, RT_EOK on successful + * @see rt_mb_create() + * + * @param mb is a pointer to the mailbox to initialize. + * It is assumed that storage for the mailbox will be allocated in your application. + * + * @param name is a pointer to the name that given to the mailbox. + * + * @param msgpoll is a pointer to the starting address of the memory space you allocated for the mailbox in advance. + * In other words, msgpoll is a pointer to the mailbox buffer of the starting address. + * + * @param size is the maximum number of mails in the mailbox. + * For example, when the mailbox buffer capacity is N, size is N/4. + * + * @param flag is the mailbox flag, which determines the queuing way of how multiple threads wait + * when the mailbox is not available. + * The mailbox flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. + * + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this mailbox will become non-real-time threads. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it represents the initialization failed. + * + * @warning This function can ONLY be called from threads. */ rt_err_t rt_mb_init(rt_mailbox_t mb, const char *name, @@ -1410,12 +1797,24 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, } RTM_EXPORT(rt_mb_init); + /** - * This function will detach a mailbox from resource management + * @brief This function will detach a static mailbox object. + * + * @note This function is used to detach a static mailbox object which is initialized by rt_mb_init() function. + * By contrast, the rt_mb_delete() function will delete a mailbox object. + * When the mailbox is successfully detached, it will resume all suspended threads in the mailbox list. * - * @param mb the mailbox object + * @see rt_mb_delete() * - * @return the operation status, RT_EOK on successful + * @param mb is a pointer to a mailbox object to be detached. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it means that the mailbox detach failed. + * + * @warning This function can ONLY detach a static mailbox initialized by the rt_mb_init() function. + * If the mailbox is created by the rt_mb_create() function, you MUST NOT USE this function to detach it, + * ONLY USE the rt_mb_delete() function to complete the deletion. */ rt_err_t rt_mb_detach(rt_mailbox_t mb) { @@ -1438,13 +1837,35 @@ RTM_EXPORT(rt_mb_detach); #ifdef RT_USING_HEAP /** - * This function will create a mailbox object from system resource + * @brief Creating a mailbox object. + * + * @note For the mailbox object, its memory space is allocated automatically. + * By contrast, the rt_mb_init() function will initialize a static mailbox object. + * + * @see rt_mb_init() * - * @param name the name of mailbox - * @param size the size of mailbox - * @param flag the flag of mailbox + * @param name is a pointer that given to the mailbox. * - * @return the created mailbox, RT_NULL on error happen + * @param size is the maximum number of mails in the mailbox. + * For example, when mailbox buffer capacity is N, size is N/4. + * + * @param flag is the mailbox flag, which determines the queuing way of how multiple threads wait + * when the mailbox is not available. + * The mailbox flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. + * + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this mailbox will become non-real-time threads. + * + * @return Return a pointer to the mailbox object. When the return value is RT_NULL, it means the creation failed. + * + * @warning This function can ONLY be called from threads. */ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) { @@ -1484,12 +1905,24 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) } RTM_EXPORT(rt_mb_create); + /** - * This function will delete a mailbox object and release the memory + * @brief This function will delete a mailbox object and release the memory space. + * + * @note This function is used to delete a mailbox object which is created by the rt_mb_create() function. + * By contrast, the rt_mb_detach() function will detach a static mailbox object. + * When the mailbox is successfully deleted, it will resume all suspended threads in the mailbox list. * - * @param mb the mailbox object + * @see rt_mb_detach() * - * @return the error code + * @param mb is a pointer to a mailbox object to be deleted. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox detach failed. + * + * @warning This function can only delete mailbox created by the rt_mb_create() function. + * If the mailbox is initialized by the rt_mb_init() function, you MUST NOT USE this function to delete it, + * ONLY USE the rt_mb_detach() function to complete the detachment. */ rt_err_t rt_mb_delete(rt_mailbox_t mb) { @@ -1517,15 +1950,29 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb) RTM_EXPORT(rt_mb_delete); #endif /* RT_USING_HEAP */ + /** - * This function will send a mail to mailbox object. If the mailbox is full, - * current thread will be suspended until timeout. + * @brief This function will send an mail to the mailbox object. If there is a thread suspended on the mailbox, + * the thread will be resumed. + * + * @note When using this function to send a mail, if the mailbox if fully used, the current thread will + * wait for a timeout. If the set timeout time is reached and there is still no space available, + * the sending thread will be resumed and an error code will be returned. + * By contrast, the rt_mb_send() function will return an error code immediately without waiting time + * when the mailbox if fully used. + * + * @see rt_mb_send() + * + * @param mb is a pointer to the mailbox object to be sent. + * + * @param value is a value to the content of the mail you want to send. + * + * @param timeout is a timeout period (unit: an OS tick). * - * @param mb the mailbox object - * @param value the mail - * @param timeout the waiting time + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox detach failed. * - * @return the error code + * @warning This function can be called in interrupt context and thread context. */ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_ubase_t value, @@ -1657,15 +2104,23 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, } RTM_EXPORT(rt_mb_send_wait); + /** - * This function will send a mail to mailbox object, if there are threads - * suspended on mailbox object, it will be waked up. This function will return - * immediately, if you want blocking send, use rt_mb_send_wait instead. + * @brief This function will send an mail to the mailbox object. If there is a thread suspended on the mailbox, + * the thread will be resumed. + * + * @note When using this function to send a mail, if the mailbox is fully used, this function will return an error + * code immediately without waiting time. + * By contrast, the rt_mb_send_wait() function is set a timeout to wait for the mail to be sent. + * + * @see rt_mb_send_wait() + * + * @param mb is a pointer to the mailbox object to be sent. * - * @param mb the mailbox object - * @param value the mail + * @param value is a value to the content of the mail you want to send. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox detach failed. */ rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value) { @@ -1673,15 +2128,22 @@ rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value) } RTM_EXPORT(rt_mb_send); + /** - * This function will send an urgent mail to mailbox object, if there are threads - * suspended on mailbox object, it will be waked up. This function will return - * immediately. + * @brief This function will send an urgent mail to the mailbox object. + * + * @note This function is almost the same as the rt_mb_send() function. The only difference is that + * when sending an urgent mail, the mail will be placed at the head of the mail queue so that + * the recipient can receive the urgent mail first. + * + * @see rt_mb_send() + * + * @param mb is a pointer to the mailbox object to be sent. * - * @param mb the mailbox object - * @param value the mail + * @param value is the content of the mail you want to send. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox detach failed. */ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) { @@ -1738,15 +2200,24 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) } RTM_EXPORT(rt_mb_urgent); + /** - * This function will receive a mail from mailbox object, if there is no mail - * in mailbox object, the thread shall wait for a specified time. + * @brief This function will receive a mail from mailbox object, if there is no mail in mailbox object, + * the thread shall wait for a specified time. + * + * @note Only when there is mail in the mailbox, the receiving thread can get the mail immediately and + * return RT_EOK, otherwise the receiving thread will be suspended until the set timeout. If the mail + * is still not received within the specified time, it will return-RT_ETIMEOUT. + * + * @param mb is a pointer to the mailbox object to be received. + * + * @param value is a flag that you will set for this mailbox's flag. + * You can set an mailbox flag, or you can set multiple flags through OR logic operations. * - * @param mb the mailbox object - * @param value the received mail will be saved in - * @param timeout the waiting time + * @param timeout is a timeout period (unit: an OS tick). * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox release failed. */ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) { @@ -1879,14 +2350,20 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) } RTM_EXPORT(rt_mb_recv); + /** - * This function can get or set some extra attributions of a mailbox object. + * @brief This function will set some extra attributions of a mailbox object. + * + * @note Currently this function only supports the RT_IPC_CMD_RESET command to reset the mailbox. + * + * @param mb is a pointer to a mailbox object. + * + * @param cmd is a command used to configure some attributions of the mailbox. * - * @param mb the mailbox object - * @param cmd the execution command - * @param arg the execution argument + * @param arg is the argument of the function to execute the command. * - * @return the error code + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that this function failed to execute. */ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg) { @@ -1922,26 +2399,64 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_mb_control); + +/**@}*/ #endif /* RT_USING_MAILBOX */ #ifdef RT_USING_MESSAGEQUEUE +/** + * @addtogroup messagequeue + */ + +/**@{*/ + struct rt_mq_message { struct rt_mq_message *next; }; + /** - * This function will initialize a message queue and put it under control of - * resource management. + * @brief Initialize a static messagequeue object. + * + * @note For the static messagequeue object, its memory space is allocated by the compiler during compiling, + * and shall placed on the read-write data segment or on the uninitialized data segment. + * By contrast, the rt_mq_create() function will allocate memory space automatically + * and initialize the messagequeue. + * + * @see rt_mq_create() + * + * @param mq is a pointer to the messagequeue to initialize. It is assumed that storage for + * the messagequeue will be allocated in your application. + * + * @param name is a pointer to the name that given to the messagequeue. + * + * @param msgpool is a pointer to the starting address of the memory space you allocated for + * the messagequeue in advance. + * In other words, msgpool is a pointer to the messagequeue buffer of the starting address. + * + * @param msg_size is the maximum length of a message in the messagequeue (Unit: Byte). + * + * @param pool_size is the size of the memory space allocated for the messagequeue in advance. + * + * @param flag is the messagequeue flag, which determines the queuing way of how multiple threads wait + * when the messagequeue is not available. + * The messagequeue flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. * - * @param mq the message object - * @param name the name of message queue - * @param msgpool the beginning address of buffer to save messages - * @param msg_size the maximum size of message - * @param pool_size the size of buffer to save messages - * @param flag the flag of message queue + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). * - * @return the operation status, RT_EOK on successful + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this messagequeue will become non-real-time threads. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it represents the initialization failed. + * + * @warning This function can ONLY be called from threads. */ rt_err_t rt_mq_init(rt_mq_t mq, const char *name, @@ -1996,12 +2511,24 @@ rt_err_t rt_mq_init(rt_mq_t mq, } RTM_EXPORT(rt_mq_init); + /** - * This function will detach a message queue object from resource management + * @brief This function will detach a static messagequeue object. + * + * @note This function is used to detach a static messagequeue object which is initialized by rt_mq_init() function. + * By contrast, the rt_mq_delete() function will delete a messagequeue object. + * When the messagequeue is successfully detached, it will resume all suspended threads in the messagequeue list. * - * @param mq the message queue object + * @see rt_mq_delete() * - * @return the operation status, RT_EOK on successful + * @param mq is a pointer to a messagequeue object to be detached. + * + * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. + * If the return value is any other values, it means that the messagequeue detach failed. + * + * @warning This function can ONLY detach a static messagequeue initialized by the rt_mq_init() function. + * If the messagequeue is created by the rt_mq_create() function, you MUST NOT USE this function to detach it, + * and ONLY USE the rt_mq_delete() function to complete the deletion. */ rt_err_t rt_mq_detach(rt_mq_t mq) { @@ -2024,14 +2551,36 @@ RTM_EXPORT(rt_mq_detach); #ifdef RT_USING_HEAP /** - * This function will create a message queue object from system resource + * @brief Creating a messagequeue object. + * + * @note For the messagequeue object, its memory space is allocated automatically. + * By contrast, the rt_mq_init() function will initialize a static messagequeue object. + * + * @see rt_mq_init() * - * @param name the name of message queue - * @param msg_size the size of message - * @param max_msgs the maximum number of message in queue - * @param flag the flag of message queue + * @param name is a pointer that given to the messagequeue. * - * @return the created message queue, RT_NULL on error happen + * @param msg_size is the maximum length of a message in the messagequeue (Unit: Byte). + * + * @param max_msgs is the maximum number of messages in the messagequeue. + * + * @param flag is the messagequeue flag, which determines the queuing way of how multiple threads wait + * when the messagequeue is not available. + * The messagequeue flag can be ONE of the following values: + * + * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. + * + * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method + * (also known as first-come-first-served (FCFS) scheduling strategy). + * + * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to + * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about + * the first-in-first-out principle, and you clearly understand that all threads involved in + * this messagequeue will become non-real-time threads. + * + * @return Return a pointer to the messagequeue object. When the return value is RT_NULL, it means the creation failed. + * + * @warning This function can NOT be called in interrupt context. You can use macor RT_DEBUG_NOT_IN_INTERRUPT to check it. */ rt_mq_t rt_mq_create(const char *name, rt_size_t msg_size, @@ -2094,12 +2643,25 @@ rt_mq_t rt_mq_create(const char *name, } RTM_EXPORT(rt_mq_create); + /** - * This function will delete a message queue object and release the memory + * @brief This function will delete a messagequeue object and release the memory. * - * @param mq the message queue object + * @note This function is used to delete a messagequeue object which is created by the rt_mq_create() function. + * By contrast, the rt_mq_detach() function will detach a static messagequeue object. + * When the messagequeue is successfully deleted, it will resume all suspended threads in the messagequeue list. * - * @return the error code + * @see rt_mq_detach() + * + * @param mq is a pointer to a messagequeue object to be deleted. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the messagequeue detach failed. + * + * @warning This function can ONLY delete a messagequeue initialized by the rt_mq_create() function. + * If the messagequeue is initialized by the rt_mq_init() function, you MUST NOT USE this function to delete it, + * ONLY USE the rt_mq_detach() function to complete the detachment. + * for example,the rt_mq_create() function, it cannot be called in interrupt context. */ rt_err_t rt_mq_delete(rt_mq_t mq) { @@ -2126,16 +2688,35 @@ rt_err_t rt_mq_delete(rt_mq_t mq) RTM_EXPORT(rt_mq_delete); #endif /* RT_USING_HEAP */ + /** - * This function will send a message to message queue object. If the message queue is full, - * current thread will be suspended until timeout. + * @brief This function will send a message to the messagequeue object. If + * there is a thread suspended on the messagequeue, the thread will be + * resumed. + * + * @note When using this function to send a message, if the messagequeue is + * fully used, the current thread will wait for a timeout. If reaching + * the timeout and there is still no space available, the sending + * thread will be resumed and an error code will be returned. By + * contrast, the rt_mq_send() function will return an error code + * immediately without waiting when the messagequeue if fully used. + * + * @see rt_mq_send() + * + * @param mq is a pointer to the messagequeue object to be sent. + * + * @param buffer is the content of the message. * - * @param mq the message queue object - * @param buffer the message - * @param size the size of buffer - * @param timeout the waiting time + * @param size is the length of the message(Unit: Byte). * - * @return the error code + * @param timeout is a timeout period (unit: an OS tick). + * + * @return Return the operation status. When the return value is RT_EOK, the + * operation is successful. If the return value is any other values, + * it means that the messagequeue detach failed. + * + * @warning This function can be called in interrupt context and thread + * context. */ rt_err_t rt_mq_send_wait(rt_mq_t mq, const void *buffer, @@ -2298,15 +2879,28 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, } RTM_EXPORT(rt_mq_send_wait) + /** - * This function will send a message to message queue object, if there are - * threads suspended on message queue object, it will be waked up. + * @brief This function will send a message to the messagequeue object. + * If there is a thread suspended on the messagequeue, the thread will be resumed. + * + * @note When using this function to send a message, if the messagequeue is fully used, + * the current thread will wait for a timeout. + * By contrast, when the messagequeue is fully used, the rt_mq_send_wait() function will + * return an error code immediately without waiting. + * + * @see rt_mq_send_wait() + * + * @param mq is a pointer to the messagequeue object to be sent. + * + * @param buffer is the content of the message. + * + * @param size is the length of the message(Unit: Byte). * - * @param mq the message queue object - * @param buffer the message - * @param size the size of buffer + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the messagequeue detach failed. * - * @return the error code + * @warning This function can be called in interrupt context and thread context. */ rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) { @@ -2314,16 +2908,24 @@ rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) } RTM_EXPORT(rt_mq_send); + /** - * This function will send an urgent message to message queue object, which - * means the message will be inserted to the head of message queue. If there - * are threads suspended on message queue object, it will be waked up. + * @brief This function will send an urgent message to the messagequeue object. + * + * @note This function is almost the same as the rt_mq_send() function. The only difference is that + * when sending an urgent message, the message is placed at the head of the messagequeue so that + * the recipient can receive the urgent message first. + * + * @see rt_mq_send() + * + * @param mq is a pointer to the messagequeue object to be sent. * - * @param mq the message queue object - * @param buffer the message - * @param size the size of buffer + * @param buffer is the content of the message. * - * @return the error code + * @param size is the length of the message(Unit: Byte). + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox detach failed. */ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) { @@ -2406,17 +3008,25 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) } RTM_EXPORT(rt_mq_urgent); + /** - * This function will receive a message from message queue object, if there is - * no message in message queue object, the thread shall wait for a specified - * time. + * @brief This function will receive a message from message queue object, + * if there is no message in messagequeue object, the thread shall wait for a specified time. + * + * @note Only when there is mail in the mailbox, the receiving thread can get the mail immediately and return RT_EOK, + * otherwise the receiving thread will be suspended until timeout. + * If the mail is not received within the specified time, it will return -RT_ETIMEOUT. + * + * @param mq is a pointer to the messagequeue object to be received. * - * @param mq the message queue object - * @param buffer the received message will be saved in - * @param size the size of buffer - * @param timeout the waiting time + * @param buffer is the content of the message. * - * @return the error code + * @param size is the length of the message(Unit: Byte). + * + * @param timeout is a timeout period (unit: an OS tick). + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the mailbox release failed. */ rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, @@ -2568,15 +3178,20 @@ rt_err_t rt_mq_recv(rt_mq_t mq, } RTM_EXPORT(rt_mq_recv); + /** - * This function can get or set some extra attributions of a message queue - * object. + * @brief This function will set some extra attributions of a messagequeue object. + * + * @note Currently this function only supports the RT_IPC_CMD_RESET command to reset the messagequeue. * - * @param mq the message queue object - * @param cmd the execution command - * @param arg the execution argument + * @param mq is a pointer to a messagequeue object. * - * @return the error code + * @param cmd is a command used to configure some attributions of the messagequeue. + * + * @param arg is the argument of the function to execute the command. + * + * @return Return the operation status. When the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that this function failed to execute. */ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) { @@ -2628,6 +3243,8 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) return -RT_ERROR; } RTM_EXPORT(rt_mq_control); + +/**@}*/ #endif /* RT_USING_MESSAGEQUEUE */ /**@}*/ -- cgit v1.3.1 From c0e48f0417e21c5300d0ac8b7a696f989145a7e1 Mon Sep 17 00:00:00 2001 From: xukai Date: Fri, 9 Jul 2021 17:37:46 +0800 Subject: [components][kernel] 解决多核下 finsh 不能响应串口输入问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kservice.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 49e1486078..128a9f4f54 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1176,11 +1176,7 @@ void rt_kputs(const char *str) } else { - rt_uint16_t old_flag = _console_device->open_flag; - - _console_device->open_flag |= RT_DEVICE_FLAG_STREAM; rt_device_write(_console_device, 0, str, rt_strlen(str)); - _console_device->open_flag = old_flag; } #else rt_hw_console_output(str); @@ -1214,11 +1210,7 @@ RT_WEAK void rt_kprintf(const char *fmt, ...) } else { - rt_uint16_t old_flag = _console_device->open_flag; - - _console_device->open_flag |= RT_DEVICE_FLAG_STREAM; rt_device_write(_console_device, 0, rt_log_buf, length); - _console_device->open_flag = old_flag; } #else rt_hw_console_output(rt_log_buf); -- cgit v1.3.1 From f33c89ce5aed94bf143f7f4d0bd7e1e743176f06 Mon Sep 17 00:00:00 2001 From: liuduanfei <939763442@qq.com> Date: Wed, 14 Jul 2021 07:02:56 +0000 Subject: 64位模式下 默认支持 RT_PRINTF_LONGLONG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kservice.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index e9972dba97..dfb37dd888 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -30,6 +30,10 @@ /* use precision */ #define RT_PRINTF_PRECISION +#ifdef ARCH_CPU_64BIT + #define RT_PRINTF_LONGLONG +#endif + /** * @addtogroup KernelService */ -- cgit v1.3.1 From 1d276ac4b32f53899a60aff8d0406143177fe17e Mon Sep 17 00:00:00 2001 From: liuduanfei <939763442@qq.com> Date: Thu, 15 Jul 2021 08:28:30 +0000 Subject: 清除 kservice.c 中对 RT_PRINTF_LONGLONG 的支持 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kservice.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index dfb37dd888..e9972dba97 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -30,10 +30,6 @@ /* use precision */ #define RT_PRINTF_PRECISION -#ifdef ARCH_CPU_64BIT - #define RT_PRINTF_LONGLONG -#endif - /** * @addtogroup KernelService */ -- cgit v1.3.1 From 4e40129e57f8c507514fc981fa742820a1a08e8a Mon Sep 17 00:00:00 2001 From: liuduanfei <939763442@qq.com> Date: Thu, 15 Jul 2021 08:30:17 +0000 Subject: Kconfig 中添加 RT_PRINTF_LONGLONG 的选择,默认不选择 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index 6afb719395..a1b0ff9a17 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -347,6 +347,10 @@ menu "Kernel Device Object" config RT_CONSOLE_DEVICE_NAME string "the device name for console" default "uart" + + config RT_PRINTF_LONGLONG + bool "rt_kprintf support long long" + default n endif endmenu -- cgit v1.3.1