From 62137eec9ab5c689686bb705304964d7451bbcdf Mon Sep 17 00:00:00 2001 From: 张世争 Date: Fri, 26 Feb 2021 10:38:31 +0800 Subject: [update][kernel]规范rt_object_detach的使用 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index d882711151..747c28c8bd 100644 --- a/src/timer.c +++ b/src/timer.c @@ -233,7 +233,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer) /* enable interrupt */ rt_hw_interrupt_enable(level); - rt_object_detach((rt_object_t)timer); + rt_object_detach(&(timer->parent)); return RT_EOK; } -- cgit v1.3.1 From 72d7f6c0adf6ef251e7662f09c9dd32579041a19 Mon Sep 17 00:00:00 2001 From: 张世争 Date: Sun, 28 Feb 2021 12:00:44 +0800 Subject: [update][kernel]规范rt_object_t强制转换的使用,消除上次提交的编译警告 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 2 -- src/timer.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/timer.c') diff --git a/src/thread.c b/src/thread.c index 18b5227f5a..beef93f46a 100644 --- a/src/thread.c +++ b/src/thread.c @@ -358,8 +358,6 @@ RTM_EXPORT(rt_thread_startup); */ rt_err_t rt_thread_detach(rt_thread_t thread) { - rt_base_t lock; - /* thread check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); diff --git a/src/timer.c b/src/timer.c index 747c28c8bd..2eaca225bc 100644 --- a/src/timer.c +++ b/src/timer.c @@ -201,7 +201,7 @@ void rt_timer_init(rt_timer_t timer, RT_ASSERT(timer != RT_NULL); /* timer object initialization */ - rt_object_init((rt_object_t)timer, RT_Object_Class_Timer, name); + rt_object_init(&(timer->parent), RT_Object_Class_Timer, name); _rt_timer_init(timer, timeout, parameter, time, flag); } @@ -298,7 +298,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer) /* enable interrupt */ rt_hw_interrupt_enable(level); - rt_object_delete((rt_object_t)timer); + rt_object_delete(&(timer->parent)); return RT_EOK; } -- cgit v1.3.1 From 678306d300faa44b6cd099464bd978afb2c5c9a6 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Mar 2021 11:25:38 +0800 Subject: [kernel]auto formatted --- src/clock.c | 4 ++-- src/components.c | 2 +- src/cpu.c | 2 +- src/device.c | 2 +- src/idle.c | 4 ++-- src/ipc.c | 20 ++++++++++---------- src/irq.c | 6 +++--- src/kservice.c | 8 ++++---- src/mem.c | 4 ++-- src/memheap.c | 6 +++--- src/mempool.c | 2 +- src/object.c | 10 +++++----- src/scheduler.c | 8 ++++---- src/signal.c | 2 +- src/slab.c | 2 +- src/thread.c | 2 +- src/timer.c | 2 +- 17 files changed, 43 insertions(+), 43 deletions(-) (limited to 'src/timer.c') diff --git a/src/clock.c b/src/clock.c index 66923e5c00..0880d8d241 100644 --- a/src/clock.c +++ b/src/clock.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -111,7 +111,7 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) tick = RT_TICK_PER_SECOND * (ms / 1000); tick += (RT_TICK_PER_SECOND * (ms % 1000) + 999) / 1000; } - + /* return the calculated tick */ return tick; } diff --git a/src/components.c b/src/components.c index 8ea5654d0c..9709d0aae2 100644 --- a/src/components.c +++ b/src/components.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/cpu.c b/src/cpu.c index 96e585713b..48ddb12c46 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/device.c b/src/device.c index a4f004fb69..388c2ecf12 100644 --- a/src/device.c +++ b/src/device.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/idle.c b/src/idle.c index aa14552a49..24dfffbc6d 100644 --- a/src/idle.c +++ b/src/idle.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -211,7 +211,7 @@ static void rt_thread_idle_entry(void *parameter) #endif rt_thread_idle_excute(); -#ifdef RT_USING_PM +#ifdef RT_USING_PM rt_system_power_manager(); #endif } diff --git a/src/ipc.c b/src/ipc.c index 37b05b9ae3..111d724c23 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -34,7 +34,7 @@ * 2013-09-14 Grissiom add an option check in rt_event_recv * 2018-10-02 Bernard add 64bit support for mailbox * 2019-09-16 tyx add send wait support for message queue - * 2020-07-29 Meco Man fix thread->event_set/event_info when received an + * 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() @@ -124,7 +124,7 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, break; default: - break; + break; } return RT_EOK; @@ -959,7 +959,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) rt_hw_interrupt_enable(temp); /* enable interrupt */ return -RT_EFULL; /* value overflowed */ } - + /* clear owner */ mutex->owner = RT_NULL; mutex->original_priority = 0xff; @@ -1280,11 +1280,11 @@ rt_err_t rt_event_recv(rt_event_t event, /* set received event */ if (recved) *recved = (event->set & set); - - /* fill thread event info */ + + /* fill thread event info */ thread->event_set = (event->set & set); thread->event_info = option; - + /* received event */ if (option & RT_EVENT_FLAG_CLEAR) event->set &= ~set; @@ -1649,7 +1649,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, ++ mb->in_offset; if (mb->in_offset >= mb->size) mb->in_offset = 0; - + if(mb->entry < RT_MB_ENTRY_MAX) { /* increase message entry */ @@ -1660,7 +1660,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_hw_interrupt_enable(temp); /* enable interrupt */ return -RT_EFULL; /* value overflowed */ } - + /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { @@ -2409,7 +2409,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) rt_hw_interrupt_enable(temp); /* enable interrupt */ return -RT_EFULL; /* value overflowed */ } - + /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { diff --git a/src/irq.c b/src/irq.c index 311d297bfe..177c1a9ff5 100644 --- a/src/irq.c +++ b/src/irq.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -21,7 +21,7 @@ static void (*rt_interrupt_leave_hook)(void); /** * @ingroup Hook - * This function set a hook function when the system enter a interrupt + * This function set a hook function when the system enter a interrupt * * @note the hook function must be simple and never be blocked or suspend. */ @@ -31,7 +31,7 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) } /** * @ingroup Hook - * This function set a hook function when the system exit a interrupt. + * This function set a hook function when the system exit a interrupt. * * @note the hook function must be simple and never be blocked or suspend. */ diff --git a/src/kservice.c b/src/kservice.c index 9fc3971c7e..79ee4c2b9d 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -456,7 +456,7 @@ RTM_EXPORT(rt_strncmp); rt_int32_t rt_strcmp(const char *cs, const char *ct) { while (*cs && *cs == *ct) - { + { cs++; ct++; } @@ -1127,10 +1127,10 @@ rt_device_t rt_console_set_device(const char *name) /* find new console device */ new_device = rt_device_find(name); - + /* check whether it's a same device */ if (new_device == old_device) return RT_NULL; - + if (new_device != RT_NULL) { if (_console_device != RT_NULL) diff --git a/src/mem.c b/src/mem.c index c03c8b3452..ac0d27f2c3 100644 --- a/src/mem.c +++ b/src/mem.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -489,7 +489,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize) { ((struct heap_mem *)&heap_ptr[mem2->next])->prev = ptr2; } - + if (mem2 < lfree) { /* the splited struct is now the lowest */ diff --git a/src/memheap.c b/src/memheap.c index 449e66e975..a5d86f6347 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ @@ -130,7 +130,7 @@ rt_err_t rt_memheap_detach(struct rt_memheap *heap) RT_ASSERT(heap); RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); RT_ASSERT(rt_object_is_systemobject(&heap->parent)); - + rt_sem_detach(&heap->lock); rt_object_detach(&(heap->parent)); @@ -765,7 +765,7 @@ void dump_used_memheap(struct rt_memheap *mh) rt_kprintf("\nmemory heap address:\n"); rt_kprintf("heap_ptr: 0x%08x\n", mh->start_addr); - rt_kprintf("free : 0x%08x\n", mh->available_size); + rt_kprintf("free : 0x%08x\n", mh->available_size); rt_kprintf("max_used: 0x%08x\n", mh->max_used_size); rt_kprintf("size : 0x%08x\n", mh->pool_size); diff --git a/src/mempool.c b/src/mempool.c index db614032aa..1de48940d7 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/object.c b/src/object.c index 56263618b3..013e2d1e33 100644 --- a/src/object.c +++ b/src/object.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -200,7 +200,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object)) /** * This function will return the specified type of object information. * - * @param type the type of object, which can be + * @param type the type of object, which can be * RT_Object_Class_Thread/Semaphore/Mutex... etc * * @return the object type information or RT_NULL @@ -220,7 +220,7 @@ RTM_EXPORT(rt_object_get_information); /** * This function will return the length of object list in object container. * - * @param type the type of object, which can be + * @param type the type of object, which can be * RT_Object_Class_Thread/Semaphore/Mutex... etc * @return the length of object list */ @@ -247,10 +247,10 @@ int rt_object_get_length(enum rt_object_class_type type) RTM_EXPORT(rt_object_get_length); /** - * This function will copy the object pointer of the specified type, + * This function will copy the object pointer of the specified type, * with the maximum size specified by maxlen. * - * @param type the type of object, which can be + * @param type the type of object, which can be * RT_Object_Class_Thread/Semaphore/Mutex... etc * @param pointers the pointers will be saved to * @param maxlen the maximum number of pointers can be saved diff --git a/src/scheduler.c b/src/scheduler.c index 06f305ea0b..c03c20d030 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -270,10 +270,10 @@ void rt_system_scheduler_start(void) #ifdef RT_USING_SMP /** * This function will handle IPI interrupt and do a scheduling in system; - * + * * @param vector, the number of IPI interrupt for system scheduling * @param param, use RT_NULL - * + * * NOTE: this function should be invoke or register as ISR in BSP. */ void rt_scheduler_ipi_handler(int vector, void *param) @@ -283,7 +283,7 @@ void rt_scheduler_ipi_handler(int vector, void *param) /** * This function will perform one scheduling. It will select one thread - * with the highest priority level in global ready queue or local ready queue, + * with the highest priority level in global ready queue or local ready queue, * then switch to it. */ void rt_schedule(void) diff --git a/src/signal.c b/src/signal.c index bb9339ab6c..c2c3e975cb 100644 --- a/src/signal.c +++ b/src/signal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/slab.c b/src/slab.c index 0872ecf092..12ca1a938c 100644 --- a/src/slab.c +++ b/src/slab.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/src/thread.c b/src/thread.c index beef93f46a..402ed66acb 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/timer.c b/src/timer.c index 2eaca225bc..836df51e06 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * -- cgit v1.3.1 From cd326d849a745c824c3ff2f0a22b25be4ba04d60 Mon Sep 17 00:00:00 2001 From: yangjie Date: Tue, 25 May 2021 18:28:30 +0800 Subject: [src]移除 C99 依赖 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 836df51e06..9b0db6c6a5 100644 --- a/src/timer.c +++ b/src/timer.c @@ -531,7 +531,9 @@ void rt_timer_check(void) struct rt_timer *t; rt_tick_t current_tick; register rt_base_t level; - rt_list_t list = RT_LIST_OBJECT_INIT(list); + rt_list_t list; + + rt_list_init(&list); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n")); @@ -613,7 +615,9 @@ void rt_soft_timer_check(void) rt_tick_t current_tick; struct rt_timer *t; register rt_base_t level; - rt_list_t list = RT_LIST_OBJECT_INIT(list); + rt_list_t list; + + rt_list_init(&list); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n")); -- 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/timer.c') 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 30fd28a89a1a73428f9cd8086add95c4066d2857 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sun, 15 Aug 2021 23:04:35 +0800 Subject: add the comment of timer.c --- src/timer.c | 98 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 30 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 1c8e70fccc..18b7ac4d58 100644 --- a/src/timer.c +++ b/src/timer.c @@ -16,6 +16,7 @@ * 2012-12-15 Bernard fix the next timeout issue in soft timer * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer * timeout function. + * 2021-08-15 supperthomas add the comment */ #include @@ -59,10 +60,10 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); /**@{*/ /** - * This function will set a hook function, which will be invoked when enter - * timer timeout callback function. - * - * @param hook the hook function + * @brief This function will set a hook function on timer, + * which will be invoked when enter timer timeout callback function. + * + * @param hook the function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { @@ -70,10 +71,10 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) } /** - * This function will set a hook function, which will be invoked when exit - * timer timeout callback function. - * - * @param hook the hook function + * @brief This function will set a hook function, which will be + * invoked when exit * timer timeout callback function. + * + * @param hook the function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) { @@ -83,6 +84,20 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) /**@}*/ #endif /* RT_USING_HOOK */ + +/** + * @brief [internal] the init funtion of timer + * + * the internal called function of rt_timer_init + * + * @see rt_timer_init + * + * @param timer the static timer object + * @param timeout the timeout function + * @param parameter the parameter of timeout function + * @param time the tick of timer + * @param flag the flag of timer + */ static void _rt_timer_init(rt_timer_t timer, void (*timeout)(void *parameter), void *parameter, @@ -110,7 +125,13 @@ static void _rt_timer_init(rt_timer_t timer, } } -/* the fist timer always in the last row */ +/** + * @brief find the next emtpy timer + * + * @param timer_list the timer of the next timeout + * + * @return rt_tick_t the point of timer + */ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) { struct rt_timer *timer; @@ -133,6 +154,11 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) return timeout_tick; } +/** + * @brief remove the timer + * + * @param timer the point of timer + */ rt_inline void _rt_timer_remove(rt_timer_t timer) { int i; @@ -144,6 +170,12 @@ rt_inline void _rt_timer_remove(rt_timer_t timer) } #if RT_DEBUG_TIMER +/** + * @brief the number of timer + * + * @param timer + * @return int the count + */ static int rt_timer_count_height(struct rt_timer *timer) { int i, cnt = 0; @@ -155,7 +187,11 @@ static int rt_timer_count_height(struct rt_timer *timer) } return cnt; } - +/** + * @brief dump the all timer information + * + * @param timer_heads the head of timer + */ void rt_timer_dump(rt_list_t timer_heads[]) { rt_list_t *list; @@ -180,9 +216,8 @@ void rt_timer_dump(rt_list_t timer_heads[]) /**@{*/ /** - * This function will initialize a timer, normally this function is used to - * initialize a static timer object. - * + * @brief This function will initialize a timer + * normally this function is used to initialize a static timer object. * @param timer the static timer object * @param name the name of timer * @param timeout the timeout function @@ -208,11 +243,10 @@ void rt_timer_init(rt_timer_t timer, RTM_EXPORT(rt_timer_init); /** - * This function will detach a timer from timer management. - * - * @param timer the static timer object - * - * @return the operation status, RT_EOK on OK; RT_ERROR on error + * @brief This function will detach a timer from timer management. + * + * @param timer the timer to be detached + * @return rt_err_t RT_EOK */ rt_err_t rt_timer_detach(rt_timer_t timer) { @@ -241,7 +275,7 @@ RTM_EXPORT(rt_timer_detach); #ifdef RT_USING_HEAP /** - * This function will create a timer + * @brief This function will create a timer * * @param name the name of timer * @param timeout the timeout function @@ -273,7 +307,7 @@ rt_timer_t rt_timer_create(const char *name, RTM_EXPORT(rt_timer_create); /** - * This function will delete a timer and release timer memory + * @brief This function will delete a timer and release timer memory * * @param timer the timer to be deleted * @@ -306,7 +340,7 @@ RTM_EXPORT(rt_timer_delete); #endif /* RT_USING_HEAP */ /** - * This function will start the timer + * @brief This function will start the timer * * @param timer the timer to be started * @@ -429,7 +463,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) RTM_EXPORT(rt_timer_start); /** - * This function will stop the timer + * @brief This function will stop the timer * * @param timer the timer to be stopped * @@ -463,7 +497,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer) RTM_EXPORT(rt_timer_stop); /** - * This function will get or set some options of the timer + * @brief This function will get or set some options of the timer * * @param timer the timer to be get or set * @param cmd the control command @@ -521,8 +555,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) RTM_EXPORT(rt_timer_control); /** - * This function will check timer list, if a timeout event happens, the - * corresponding timeout function will be invoked. + * @brief This function will check timer list, if a timeout event happens, + * the corresponding timeout function will be invoked. * * @note this function shall be invoked in operating system timer interrupt. */ @@ -596,7 +630,7 @@ void rt_timer_check(void) } /** - * This function will return the next timeout tick in the system. + * @brief This function will return the next timeout tick in the system. * * @return the next timeout tick in the system */ @@ -607,7 +641,7 @@ rt_tick_t rt_timer_next_timeout_tick(void) #ifdef RT_USING_TIMER_SOFT /** - * This function will check software-timer list, if a timeout event happens, the + * @brief This function will check software-timer list, if a timeout event happens, the * corresponding timeout function will be invoked. */ void rt_soft_timer_check(void) @@ -684,7 +718,11 @@ void rt_soft_timer_check(void) RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n")); } -/* system timer thread entry */ +/** + * @brief system timer thread entry + * + * @param parameter + */ static void rt_thread_timer_entry(void *parameter) { rt_tick_t next_timeout; @@ -723,7 +761,7 @@ static void rt_thread_timer_entry(void *parameter) /** * @ingroup SystemInit * - * This function will initialize system timer + * @brief This function will initialize system timer */ void rt_system_timer_init(void) { @@ -738,7 +776,7 @@ void rt_system_timer_init(void) /** * @ingroup SystemInit * - * This function will initialize system timer thread + * @brief This function will initialize system timer thread */ void rt_system_timer_thread_init(void) { -- cgit v1.3.1 From 19bcf9ae32682697dc2beac7cc605f7338d44c2f Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Mon, 16 Aug 2021 22:07:46 +0800 Subject: add the formatted file --- src/irq.c | 24 ++++++++++++------------ src/timer.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/timer.c') diff --git a/src/irq.c b/src/irq.c index ac43c45573..40c2aa5305 100644 --- a/src/irq.c +++ b/src/irq.c @@ -22,11 +22,11 @@ static void (*rt_interrupt_leave_hook)(void); /** * @ingroup Hook - * + * * @brief This function set a hook function when the system enter a interrupt - * + * * @note the hook function must be simple and never be blocked or suspend. - * + * * @param hook The function point to be called */ void rt_interrupt_enter_sethook(void (*hook)(void)) @@ -36,11 +36,11 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) /** * @ingroup Hook - * + * * @brief This function set a hook function when the system exit a interrupt. - * + * * @note the hook function must be simple and never be blocked or suspend. - * + * * @param hook The function point to be called */ void rt_interrupt_leave_sethook(void (*hook)(void)) @@ -64,9 +64,9 @@ volatile rt_uint8_t rt_interrupt_nest = 0; /** * @brief This function will be invoked by BSP, when enter interrupt service routine - * + * * @note please don't invoke this routine in application - * + * * @see rt_interrupt_leave */ void rt_interrupt_enter(void) @@ -86,9 +86,9 @@ RTM_EXPORT(rt_interrupt_enter); /** * @brief This function will be invoked by BSP, when leave interrupt service routine - * + * * @note please don't invoke this routine in application - * + * * @see rt_interrupt_enter */ void rt_interrupt_leave(void) @@ -108,10 +108,10 @@ RTM_EXPORT(rt_interrupt_leave); /** * @brief This function will return the nest of interrupt. - * + * * User application can invoke this function to get whether current * context is interrupt context. - * + * * @return rt_uint8_t the number of nested interrupts. */ RT_WEAK rt_uint8_t rt_interrupt_get_nest(void) diff --git a/src/timer.c b/src/timer.c index 18b7ac4d58..44d0d4a7cc 100644 --- a/src/timer.c +++ b/src/timer.c @@ -16,7 +16,7 @@ * 2012-12-15 Bernard fix the next timeout issue in soft timer * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer * timeout function. - * 2021-08-15 supperthomas add the comment + * 2021-08-15 supperthomas add the comment */ #include @@ -60,9 +60,9 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); /**@{*/ /** - * @brief This function will set a hook function on timer, + * @brief This function will set a hook function on timer, * which will be invoked when enter timer timeout callback function. - * + * * @param hook the function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) @@ -71,9 +71,9 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) } /** - * @brief This function will set a hook function, which will be + * @brief This function will set a hook function, which will be * invoked when exit * timer timeout callback function. - * + * * @param hook the function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) @@ -87,11 +87,11 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) /** * @brief [internal] the init funtion of timer - * + * * the internal called function of rt_timer_init - * + * * @see rt_timer_init - * + * * @param timer the static timer object * @param timeout the timeout function * @param parameter the parameter of timeout function @@ -127,9 +127,9 @@ static void _rt_timer_init(rt_timer_t timer, /** * @brief find the next emtpy timer - * + * * @param timer_list the timer of the next timeout - * + * * @return rt_tick_t the point of timer */ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) @@ -155,8 +155,8 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) } /** - * @brief remove the timer - * + * @brief remove the timer + * * @param timer the point of timer */ rt_inline void _rt_timer_remove(rt_timer_t timer) @@ -172,8 +172,8 @@ rt_inline void _rt_timer_remove(rt_timer_t timer) #if RT_DEBUG_TIMER /** * @brief the number of timer - * - * @param timer + * + * @param timer * @return int the count */ static int rt_timer_count_height(struct rt_timer *timer) @@ -189,7 +189,7 @@ static int rt_timer_count_height(struct rt_timer *timer) } /** * @brief dump the all timer information - * + * * @param timer_heads the head of timer */ void rt_timer_dump(rt_list_t timer_heads[]) @@ -244,7 +244,7 @@ RTM_EXPORT(rt_timer_init); /** * @brief This function will detach a timer from timer management. - * + * * @param timer the timer to be detached * @return rt_err_t RT_EOK */ @@ -555,7 +555,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) RTM_EXPORT(rt_timer_control); /** - * @brief This function will check timer list, if a timeout event happens, + * @brief This function will check timer list, if a timeout event happens, * the corresponding timeout function will be invoked. * * @note this function shall be invoked in operating system timer interrupt. @@ -719,9 +719,9 @@ void rt_soft_timer_check(void) } /** - * @brief system timer thread entry - * - * @param parameter + * @brief system timer thread entry + * + * @param parameter */ static void rt_thread_timer_entry(void *parameter) { -- cgit v1.3.1 From 247f21f998ccb61f3bdebfa3239c1714c81905f3 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 17 Aug 2021 05:56:39 -0400 Subject: [kernel][timer] 规范内部函数和变量命名 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 82 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 44d0d4a7cc..07647a55f9 100644 --- a/src/timer.c +++ b/src/timer.c @@ -23,7 +23,7 @@ #include /* hard timer list */ -static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; +static rt_list_t _timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #ifdef RT_USING_TIMER_SOFT @@ -39,12 +39,12 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #endif /* RT_TIMER_THREAD_PRIO */ /* soft timer status */ -static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE; +static rt_uint8_t _soft_timer_status = RT_SOFT_TIMER_IDLE; /* soft timer list */ -static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; -static struct rt_thread timer_thread; +static rt_list_t _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]; +static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #endif /* RT_USING_TIMER_SOFT */ #ifdef RT_USING_HOOK @@ -98,7 +98,7 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) * @param time the tick of timer * @param flag the flag of timer */ -static void _rt_timer_init(rt_timer_t timer, +static void _timer_init(rt_timer_t timer, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, @@ -132,7 +132,7 @@ static void _rt_timer_init(rt_timer_t timer, * * @return rt_tick_t the point of timer */ -static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) +static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) { struct rt_timer *timer; register rt_base_t level; @@ -159,7 +159,7 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) * * @param timer the point of timer */ -rt_inline void _rt_timer_remove(rt_timer_t timer) +rt_inline void _timer_remove(rt_timer_t timer) { int i; @@ -176,7 +176,7 @@ rt_inline void _rt_timer_remove(rt_timer_t timer) * @param timer * @return int the count */ -static int rt_timer_count_height(struct rt_timer *timer) +static int _timer_count_height(struct rt_timer *timer) { int i, cnt = 0; @@ -203,7 +203,7 @@ void rt_timer_dump(rt_list_t timer_heads[]) struct rt_timer *timer = rt_list_entry(list, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); - rt_kprintf("%d", rt_timer_count_height(timer)); + rt_kprintf("%d", _timer_count_height(timer)); } rt_kprintf("\n"); } @@ -238,7 +238,7 @@ void rt_timer_init(rt_timer_t timer, /* timer object initialization */ rt_object_init(&(timer->parent), RT_Object_Class_Timer, name); - _rt_timer_init(timer, timeout, parameter, time, flag); + _timer_init(timer, timeout, parameter, time, flag); } RTM_EXPORT(rt_timer_init); @@ -260,7 +260,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _rt_timer_remove(timer); + _timer_remove(timer); /* stop timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -300,7 +300,7 @@ rt_timer_t rt_timer_create(const char *name, return RT_NULL; } - _rt_timer_init(timer, timeout, parameter, time, flag); + _timer_init(timer, timeout, parameter, time, flag); return timer; } @@ -325,7 +325,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _rt_timer_remove(timer); + _timer_remove(timer); /* stop timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -362,7 +362,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) /* stop timer firstly */ level = rt_hw_interrupt_disable(); /* remove timer from list */ - _rt_timer_remove(timer); + _timer_remove(timer); /* change status of timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -379,13 +379,13 @@ rt_err_t rt_timer_start(rt_timer_t timer) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { /* insert timer to soft timer list */ - timer_list = rt_soft_timer_list; + timer_list = _soft_timer_list; } else #endif /* RT_USING_TIMER_SOFT */ { /* insert timer to system timer list */ - timer_list = rt_timer_list; + timer_list = _timer_list; } row_head[0] = &timer_list[0]; @@ -448,11 +448,11 @@ rt_err_t rt_timer_start(rt_timer_t timer) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { /* check whether timer thread is ready */ - if ((soft_timer_status == RT_SOFT_TIMER_IDLE) && - ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) + if ((_soft_timer_status == RT_SOFT_TIMER_IDLE) && + ((_timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume timer thread to check soft timer */ - rt_thread_resume(&timer_thread); + rt_thread_resume(&_timer_thread); rt_schedule(); } } @@ -485,7 +485,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _rt_timer_remove(timer); + _timer_remove(timer); /* change status */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -576,9 +576,9 @@ void rt_timer_check(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - while (!rt_list_isempty(&rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) + while (!rt_list_isempty(&_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { - t = rt_list_entry(rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + t = rt_list_entry(_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); /* @@ -590,7 +590,7 @@ void rt_timer_check(void) RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ - _rt_timer_remove(t); + _timer_remove(t); if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) { t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -636,7 +636,7 @@ void rt_timer_check(void) */ rt_tick_t rt_timer_next_timeout_tick(void) { - return rt_timer_list_next_timeout(rt_timer_list); + return _timer_list_next_timeout(_timer_list); } #ifdef RT_USING_TIMER_SOFT @@ -658,9 +658,9 @@ void rt_soft_timer_check(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) + while (!rt_list_isempty(&_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { - t = rt_list_entry(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + t = rt_list_entry(_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); current_tick = rt_tick_get(); @@ -674,7 +674,7 @@ void rt_soft_timer_check(void) RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ - _rt_timer_remove(t); + _timer_remove(t); if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) { t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -682,7 +682,7 @@ void rt_soft_timer_check(void) /* add timer to temporary list */ rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); - soft_timer_status = RT_SOFT_TIMER_BUSY; + _soft_timer_status = RT_SOFT_TIMER_BUSY; /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -695,7 +695,7 @@ void rt_soft_timer_check(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - soft_timer_status = RT_SOFT_TIMER_IDLE; + _soft_timer_status = RT_SOFT_TIMER_IDLE; /* Check whether the timer object is detached or started again */ if (rt_list_isempty(&list)) { @@ -723,14 +723,14 @@ void rt_soft_timer_check(void) * * @param parameter */ -static void rt_thread_timer_entry(void *parameter) +static void _timer_thread_entry(void *parameter) { rt_tick_t next_timeout; while (1) { /* get the next timeout tick */ - next_timeout = rt_timer_list_next_timeout(rt_soft_timer_list); + next_timeout = _timer_list_next_timeout(_soft_timer_list); if (next_timeout == RT_TICK_MAX) { /* no software timer exist, suspend self. */ @@ -767,9 +767,9 @@ void rt_system_timer_init(void) { int i; - for (i = 0; i < sizeof(rt_timer_list) / sizeof(rt_timer_list[0]); i++) + for (i = 0; i < sizeof(_timer_list) / sizeof(_timer_list[0]); i++) { - rt_list_init(rt_timer_list + i); + rt_list_init(_timer_list + i); } } @@ -784,24 +784,24 @@ void rt_system_timer_thread_init(void) int i; for (i = 0; - i < sizeof(rt_soft_timer_list) / sizeof(rt_soft_timer_list[0]); + i < sizeof(_soft_timer_list) / sizeof(_soft_timer_list[0]); i++) { - rt_list_init(rt_soft_timer_list + i); + rt_list_init(_soft_timer_list + i); } /* start software timer thread */ - rt_thread_init(&timer_thread, + rt_thread_init(&_timer_thread, "timer", - rt_thread_timer_entry, + _timer_thread_entry, RT_NULL, - &timer_thread_stack[0], - sizeof(timer_thread_stack), + &_timer_thread_stack[0], + sizeof(_timer_thread_stack), RT_TIMER_THREAD_PRIO, 10); /* startup */ - rt_thread_startup(&timer_thread); + rt_thread_startup(&_timer_thread); #endif /* RT_USING_TIMER_SOFT */ } -- cgit v1.3.1 From 320c44adf81c7405a6b791fc890d7c21a7dbd756 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sat, 28 Aug 2021 23:31:35 +0800 Subject: add the fixed comment --- src/irq.c | 8 ++--- src/timer.c | 112 ++++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 68 insertions(+), 52 deletions(-) (limited to 'src/timer.c') diff --git a/src/irq.c b/src/irq.c index 40c2aa5305..81c972c955 100644 --- a/src/irq.c +++ b/src/irq.c @@ -25,7 +25,7 @@ static void (*rt_interrupt_leave_hook)(void); * * @brief This function set a hook function when the system enter a interrupt * - * @note the hook function must be simple and never be blocked or suspend. + * @note The hook function must be simple and never be blocked or suspend. * * @param hook The function point to be called */ @@ -39,7 +39,7 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) * * @brief This function set a hook function when the system exit a interrupt. * - * @note the hook function must be simple and never be blocked or suspend. + * @note The hook function must be simple and never be blocked or suspend. * * @param hook The function point to be called */ @@ -65,7 +65,7 @@ volatile rt_uint8_t rt_interrupt_nest = 0; /** * @brief This function will be invoked by BSP, when enter interrupt service routine * - * @note please don't invoke this routine in application + * @note Please don't invoke this routine in application * * @see rt_interrupt_leave */ @@ -87,7 +87,7 @@ RTM_EXPORT(rt_interrupt_enter); /** * @brief This function will be invoked by BSP, when leave interrupt service routine * - * @note please don't invoke this routine in application + * @note Please don't invoke this routine in application * * @see rt_interrupt_enter */ diff --git a/src/timer.c b/src/timer.c index 07647a55f9..5c90d34675 100644 --- a/src/timer.c +++ b/src/timer.c @@ -61,9 +61,9 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); /** * @brief This function will set a hook function on timer, - * which will be invoked when enter timer timeout callback function. + * which will be invoked when enter timer timeout callback function. * - * @param hook the function point of timer + * @param hook The function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { @@ -72,9 +72,9 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) /** * @brief This function will set a hook function, which will be - * invoked when exit * timer timeout callback function. + * invoked when exit timer timeout callback function. * - * @param hook the function point of timer + * @param hook The function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) { @@ -86,17 +86,21 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) /** - * @brief [internal] the init funtion of timer + * @brief [internal] The init funtion of timer * - * the internal called function of rt_timer_init + * The internal called function of rt_timer_init * * @see rt_timer_init * - * @param timer the static timer object - * @param timeout the timeout function - * @param parameter the parameter of timeout function - * @param time the tick of timer - * @param flag the flag of timer + * @param timer The static timer object + * + * @param timeout The timeout function + * + * @param parameter The parameter of timeout function + * + * @param time The tick of timer + * + * @param flag The flag of timer */ static void _timer_init(rt_timer_t timer, void (*timeout)(void *parameter), @@ -126,11 +130,11 @@ static void _timer_init(rt_timer_t timer, } /** - * @brief find the next emtpy timer + * @brief Find the next emtpy timer ticks * - * @param timer_list the timer of the next timeout + * @param timer_list The timer of the next timeout * - * @return rt_tick_t the point of timer + * @return rt_tick_t The next timer's ticks */ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) { @@ -155,9 +159,9 @@ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) } /** - * @brief remove the timer + * @brief Remove the timer * - * @param timer the point of timer + * @param timer The point of the timer */ rt_inline void _timer_remove(rt_timer_t timer) { @@ -171,10 +175,11 @@ rt_inline void _timer_remove(rt_timer_t timer) #if RT_DEBUG_TIMER /** - * @brief the number of timer + * @brief The number of timer * - * @param timer - * @return int the count + * @param timer the head of timer + * + * @return int the count of timer */ static int _timer_count_height(struct rt_timer *timer) { @@ -218,12 +223,18 @@ void rt_timer_dump(rt_list_t timer_heads[]) /** * @brief This function will initialize a timer * normally this function is used to initialize a static timer object. - * @param timer the static timer object - * @param name the name of timer - * @param timeout the timeout function - * @param parameter the parameter of timeout function - * @param time the tick of timer - * @param flag the flag of timer + * + * @param timer The static timer object + * + * @param name The name of timer + * + * @param timeout The timeout function + * + * @param parameter The parameter of timeout function + * + * @param time The tick of timer + * + * @param flag The flag of timer */ void rt_timer_init(rt_timer_t timer, const char *name, @@ -245,8 +256,9 @@ RTM_EXPORT(rt_timer_init); /** * @brief This function will detach a timer from timer management. * - * @param timer the timer to be detached - * @return rt_err_t RT_EOK + * @param timer The timer to be detached + * + * @return rt_err_t The status of detach */ rt_err_t rt_timer_detach(rt_timer_t timer) { @@ -277,13 +289,17 @@ RTM_EXPORT(rt_timer_detach); /** * @brief This function will create a timer * - * @param name the name of timer - * @param timeout the timeout function - * @param parameter the parameter of timeout function - * @param time the tick of timer - * @param flag the flag of timer + * @param name The name of timer + * + * @param timeout The timeout function + * + * @param parameter The parameter of timeout function + * + * @param time The tick of timer + * + * @param flag The flag of timer * - * @return the created timer object + * @return The created timer object */ rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), @@ -309,9 +325,9 @@ RTM_EXPORT(rt_timer_create); /** * @brief This function will delete a timer and release timer memory * - * @param timer the timer to be deleted + * @param timer The timer to be deleted * - * @return the operation status, RT_EOK on OK; RT_ERROR on error + * @return rt_err_t The operation status, RT_EOK on OK; RT_ERROR on error */ rt_err_t rt_timer_delete(rt_timer_t timer) { @@ -342,9 +358,9 @@ RTM_EXPORT(rt_timer_delete); /** * @brief This function will start the timer * - * @param timer the timer to be started + * @param timer The timer to be started * - * @return the operation status, RT_EOK on OK, -RT_ERROR on error + * @return The operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_start(rt_timer_t timer) { @@ -465,9 +481,9 @@ RTM_EXPORT(rt_timer_start); /** * @brief This function will stop the timer * - * @param timer the timer to be stopped + * @param timer The timer to be stopped * - * @return the operation status, RT_EOK on OK, -RT_ERROR on error + * @return The operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_stop(rt_timer_t timer) { @@ -499,11 +515,11 @@ RTM_EXPORT(rt_timer_stop); /** * @brief This function will get or set some options of the timer * - * @param timer the timer to be get or set - * @param cmd the control command - * @param arg the argument + * @param timer The timer to be get or set + * @param cmd The control command + * @param arg The argument * - * @return RT_EOK + * @return rt_err_t the statu of control */ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { @@ -558,7 +574,7 @@ RTM_EXPORT(rt_timer_control); * @brief This function will check timer list, if a timeout event happens, * the corresponding timeout function will be invoked. * - * @note this function shall be invoked in operating system timer interrupt. + * @note This function shall be invoked in operating system timer interrupt. */ void rt_timer_check(void) { @@ -632,7 +648,7 @@ void rt_timer_check(void) /** * @brief This function will return the next timeout tick in the system. * - * @return the next timeout tick in the system + * @return The next timeout tick in the system */ rt_tick_t rt_timer_next_timeout_tick(void) { @@ -642,7 +658,7 @@ rt_tick_t rt_timer_next_timeout_tick(void) #ifdef RT_USING_TIMER_SOFT /** * @brief This function will check software-timer list, if a timeout event happens, the - * corresponding timeout function will be invoked. + * corresponding timeout function will be invoked. */ void rt_soft_timer_check(void) { @@ -719,9 +735,9 @@ void rt_soft_timer_check(void) } /** - * @brief system timer thread entry + * @brief System timer thread entry * - * @param parameter + * @param parameter The arg of the thread */ static void _timer_thread_entry(void *parameter) { -- cgit v1.3.1 From a35520f841ebb7fb2152e7f9a7893d3a95f8615f Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Mon, 30 Aug 2021 07:28:36 +0800 Subject: fix the return --- src/irq.c | 6 ++--- src/timer.c | 74 ++++++++++++++++++++++++++++++------------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src/timer.c') diff --git a/src/irq.c b/src/irq.c index 81c972c955..3889a2a2c8 100644 --- a/src/irq.c +++ b/src/irq.c @@ -27,7 +27,7 @@ static void (*rt_interrupt_leave_hook)(void); * * @note The hook function must be simple and never be blocked or suspend. * - * @param hook The function point to be called + * @param hook the function point to be called */ void rt_interrupt_enter_sethook(void (*hook)(void)) { @@ -41,7 +41,7 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) * * @note The hook function must be simple and never be blocked or suspend. * - * @param hook The function point to be called + * @param hook the function point to be called */ void rt_interrupt_leave_sethook(void (*hook)(void)) { @@ -112,7 +112,7 @@ RTM_EXPORT(rt_interrupt_leave); * User application can invoke this function to get whether current * context is interrupt context. * - * @return rt_uint8_t the number of nested interrupts. + * @return the number of nested interrupts. */ RT_WEAK rt_uint8_t rt_interrupt_get_nest(void) { diff --git a/src/timer.c b/src/timer.c index 5c90d34675..da52a02fc8 100644 --- a/src/timer.c +++ b/src/timer.c @@ -63,7 +63,7 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); * @brief This function will set a hook function on timer, * which will be invoked when enter timer timeout callback function. * - * @param hook The function point of timer + * @param hook is the function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { @@ -74,7 +74,7 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) * @brief This function will set a hook function, which will be * invoked when exit timer timeout callback function. * - * @param hook The function point of timer + * @param hook is the function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) { @@ -92,15 +92,15 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) * * @see rt_timer_init * - * @param timer The static timer object + * @param timer is timer object * - * @param timeout The timeout function + * @param timeout is the timeout function * - * @param parameter The parameter of timeout function + * @param parameter is the parameter of timeout function * - * @param time The tick of timer + * @param time is the tick of timer * - * @param flag The flag of timer + * @param flag the flag of timer */ static void _timer_init(rt_timer_t timer, void (*timeout)(void *parameter), @@ -132,9 +132,9 @@ static void _timer_init(rt_timer_t timer, /** * @brief Find the next emtpy timer ticks * - * @param timer_list The timer of the next timeout + * @param timer_list is the array of time list * - * @return rt_tick_t The next timer's ticks + * @return the next timer's ticks */ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) { @@ -161,7 +161,7 @@ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) /** * @brief Remove the timer * - * @param timer The point of the timer + * @param timer the point of the timer */ rt_inline void _timer_remove(rt_timer_t timer) { @@ -179,7 +179,7 @@ rt_inline void _timer_remove(rt_timer_t timer) * * @param timer the head of timer * - * @return int the count of timer + * @return count of timer */ static int _timer_count_height(struct rt_timer *timer) { @@ -224,17 +224,17 @@ void rt_timer_dump(rt_list_t timer_heads[]) * @brief This function will initialize a timer * normally this function is used to initialize a static timer object. * - * @param timer The static timer object + * @param timer is the point of timer * - * @param name The name of timer + * @param name is a pointer to the name of the timer * - * @param timeout The timeout function + * @param timeout is the callback of timer * - * @param parameter The parameter of timeout function + * @param parameter is the param of the callback * - * @param time The tick of timer + * @param time is the ticks of timer * - * @param flag The flag of timer + * @param flag is the flag of timer */ void rt_timer_init(rt_timer_t timer, const char *name, @@ -256,9 +256,9 @@ RTM_EXPORT(rt_timer_init); /** * @brief This function will detach a timer from timer management. * - * @param timer The timer to be detached + * @param timer is the timer to be detached * - * @return rt_err_t The status of detach + * @return the status of detach */ rt_err_t rt_timer_detach(rt_timer_t timer) { @@ -289,17 +289,17 @@ RTM_EXPORT(rt_timer_detach); /** * @brief This function will create a timer * - * @param name The name of timer + * @param name the name of timer * - * @param timeout The timeout function + * @param timeout the timeout function * - * @param parameter The parameter of timeout function + * @param parameter the parameter of timeout function * - * @param time The tick of timer + * @param time the tick of timer * - * @param flag The flag of timer + * @param flag the flag of timer * - * @return The created timer object + * @return the created timer object */ rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), @@ -325,9 +325,9 @@ RTM_EXPORT(rt_timer_create); /** * @brief This function will delete a timer and release timer memory * - * @param timer The timer to be deleted + * @param timer the timer to be deleted * - * @return rt_err_t The operation status, RT_EOK on OK; RT_ERROR on error + * @return the operation status, RT_EOK on OK; RT_ERROR on error */ rt_err_t rt_timer_delete(rt_timer_t timer) { @@ -358,9 +358,9 @@ RTM_EXPORT(rt_timer_delete); /** * @brief This function will start the timer * - * @param timer The timer to be started + * @param timer the timer to be started * - * @return The operation status, RT_EOK on OK, -RT_ERROR on error + * @return the operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_start(rt_timer_t timer) { @@ -481,9 +481,9 @@ RTM_EXPORT(rt_timer_start); /** * @brief This function will stop the timer * - * @param timer The timer to be stopped + * @param timer the timer to be stopped * - * @return The operation status, RT_EOK on OK, -RT_ERROR on error + * @return the operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_stop(rt_timer_t timer) { @@ -515,11 +515,11 @@ RTM_EXPORT(rt_timer_stop); /** * @brief This function will get or set some options of the timer * - * @param timer The timer to be get or set - * @param cmd The control command - * @param arg The argument + * @param timer the timer to be get or set + * @param cmd the control command + * @param arg the argument * - * @return rt_err_t the statu of control + * @return the statu of control */ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { @@ -648,7 +648,7 @@ void rt_timer_check(void) /** * @brief This function will return the next timeout tick in the system. * - * @return The next timeout tick in the system + * @return the next timeout tick in the system */ rt_tick_t rt_timer_next_timeout_tick(void) { @@ -737,7 +737,7 @@ void rt_soft_timer_check(void) /** * @brief System timer thread entry * - * @param parameter The arg of the thread + * @param parameter is the arg of the thread */ static void _timer_thread_entry(void *parameter) { -- cgit v1.3.1 From 75b65ebcf2d2261bcd5cf762cc8aa8452e78b8d1 Mon Sep 17 00:00:00 2001 From: WillianChan Date: Tue, 31 Aug 2021 10:39:44 +0800 Subject: [fix][kernel][timer]fixed timer ASSERT exception due to multithreaded scheduling Signed-off-by: WillianChan --- src/timer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index da52a02fc8..25ba175306 100644 --- a/src/timer.c +++ b/src/timer.c @@ -367,6 +367,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) unsigned int row_lvl; rt_list_t *timer_list; register rt_base_t level; + register rt_bool_t need_schedule; rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL]; unsigned int tst_nr; static unsigned int random_nr; @@ -375,6 +376,8 @@ rt_err_t rt_timer_start(rt_timer_t timer) RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); + need_schedule = RT_FALSE; + /* stop timer firstly */ level = rt_hw_interrupt_disable(); /* remove timer from list */ @@ -457,9 +460,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED; - /* enable interrupt */ - rt_hw_interrupt_enable(level); - #ifdef RT_USING_TIMER_SOFT if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { @@ -469,11 +469,19 @@ rt_err_t rt_timer_start(rt_timer_t timer) { /* resume timer thread to check soft timer */ rt_thread_resume(&_timer_thread); - rt_schedule(); + need_schedule = RT_TRUE; } } #endif /* RT_USING_TIMER_SOFT */ + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + if (need_schedule) + { + rt_schedule(); + } + return RT_EOK; } RTM_EXPORT(rt_timer_start); -- cgit v1.3.1 From 75063a1b5e519d27485dac77590d46f626354ea2 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 25 Nov 2021 15:31:43 +0800 Subject: [timer] update the RT_TIMER_CTRL_GET_STATE code in rt_timer_control --- src/timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 25ba175306..846c33263b 100644 --- a/src/timer.c +++ b/src/timer.c @@ -560,12 +560,12 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) { /*timer is start and run*/ - *(rt_tick_t *)arg = RT_TIMER_FLAG_ACTIVATED; + *(rt_uint32_t *)arg = RT_TIMER_FLAG_ACTIVATED; } else { /*timer is stop*/ - *(rt_tick_t *)arg = RT_TIMER_FLAG_DEACTIVATED; + *(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED; } break; -- cgit v1.3.1 From d7b8cf81e6285f3cbb0817cbe79c527f10ff56b7 Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Fri, 7 Jan 2022 23:35:44 +0000 Subject: move some __on_rt_xxxxx_hook from rtdef.h to dedicated c soure files --- include/rtdef.h | 50 ++------------------------------------------------ src/ipc.c | 14 +++++++++++++- src/irq.c | 10 +++++++++- src/kservice.c | 7 +++++++ src/mempool.c | 10 +++++++++- src/object.c | 21 ++++++++++++++++++++- src/scheduler.c | 10 +++++++++- src/thread.c | 13 ++++++++++++- src/timer.c | 16 +++++++++++++++- 9 files changed, 96 insertions(+), 55 deletions(-) (limited to 'src/timer.c') diff --git a/include/rtdef.h b/include/rtdef.h index a018ceb21d..d1f7eae91f 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -39,6 +39,7 @@ * 2021-11-19 Meco Man change version number to v4.1.0 * 2021-12-21 Meco Man re-implement RT_UNUSED * 2022-01-01 Gabriel improve hooking method + * 2022-01-07 Gabriel move some __on_rt_xxxxx_hook to dedicated c soure files */ #ifndef __RT_DEF_H__ @@ -450,12 +451,6 @@ struct rt_object_information #endif #endif -#ifndef __on_rt_interrupt_enter_hook - #define __on_rt_interrupt_enter_hook() __ON_HOOK_ARGS(rt_interrupt_enter_hook, ()) -#endif -#ifndef __on_rt_interrupt_leave_hook - #define __on_rt_interrupt_leave_hook() __ON_HOOK_ARGS(rt_interrupt_leave_hook, ()) -#endif #ifndef __on_rt_interrupt_switch_hook #define __on_rt_interrupt_switch_hook() __ON_HOOK_ARGS(rt_interrupt_switch_hook, ()) #endif @@ -465,48 +460,7 @@ struct rt_object_information #ifndef __on_rt_free_hook #define __on_rt_free_hook(rmem) __ON_HOOK_ARGS(rt_free_hook, (rmem)) #endif -#ifndef __on_rt_mp_alloc_hook - #define __on_rt_mp_alloc_hook(mp, block) __ON_HOOK_ARGS(rt_mp_alloc_hook, (mp, block)) -#endif -#ifndef __on_rt_mp_free_hook - #define __on_rt_mp_free_hook(mp, block) __ON_HOOK_ARGS(rt_mp_free_hook, (mp, block)) -#endif -#ifndef __on_rt_object_trytake_hook - #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent)) -#endif -#ifndef __on_rt_object_take_hook - #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) -#endif -#ifndef __on_rt_object_put_hook - #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) -#endif -#ifndef __on_rt_scheduler_hook - #define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to)) -#endif -#ifndef __on_rt_scheduler_switch_hook - #define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid)) -#endif -#ifndef __on_rt_object_attach_hook - #define __on_rt_object_attach_hook(obj) __ON_HOOK_ARGS(rt_object_attach_hook, (obj)) -#endif -#ifndef __on_rt_object_detach_hook - #define __on_rt_object_detach_hook(obj) __ON_HOOK_ARGS(rt_object_detach_hook, (obj)) -#endif -#ifndef __on_rt_thread_inited_hook - #define __on_rt_thread_inited_hook(thread) __ON_HOOK_ARGS(rt_thread_inited_hook, (thread)) -#endif -#ifndef __on_rt_thread_suspend_hook - #define __on_rt_thread_suspend_hook(thread) __ON_HOOK_ARGS(rt_thread_suspend_hook, (thread)) -#endif -#ifndef __on_rt_thread_resume_hook - #define __on_rt_thread_resume_hook(thread) __ON_HOOK_ARGS(rt_thread_resume_hook, (thread)) -#endif -#ifndef __on_rt_timer_enter_hook - #define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t)) -#endif -#ifndef __on_rt_timer_exit_hook - #define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t)) -#endif + /**@}*/ diff --git a/src/ipc.c b/src/ipc.c index 2853590501..ebcc2780b9 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -39,12 +39,24 @@ * 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() + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to ipc.c */ #include #include -#ifdef RT_USING_HOOK + +#ifndef __on_rt_object_trytake_hook + #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent)) +#endif +#ifndef __on_rt_object_take_hook + #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) +#endif +#ifndef __on_rt_object_put_hook + #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) +#endif + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) 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); diff --git a/src/irq.c b/src/irq.c index 3889a2a2c8..bc604718b2 100644 --- a/src/irq.c +++ b/src/irq.c @@ -10,12 +10,20 @@ * 2016-08-09 ArdaFu add interrupt enter and leave hook. * 2018-11-22 Jesven rt_interrupt_get_nest function add disable irq * 2021-08-15 Supperthomas fix the comment + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to irq.c */ #include #include -#ifdef RT_USING_HOOK +#ifndef __on_rt_interrupt_enter_hook + #define __on_rt_interrupt_enter_hook() __ON_HOOK_ARGS(rt_interrupt_enter_hook, ()) +#endif +#ifndef __on_rt_interrupt_leave_hook + #define __on_rt_interrupt_leave_hook() __ON_HOOK_ARGS(rt_interrupt_leave_hook, ()) +#endif + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_interrupt_enter_hook)(void); static void (*rt_interrupt_leave_hook)(void); diff --git a/src/kservice.c b/src/kservice.c index fa0da4c7c4..f49823c2d8 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -19,6 +19,7 @@ * 2015-07-06 Bernard Add rt_assert_handler routine. * 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB * 2021-12-20 Meco Man implement rt_strcpy() + * 2022-01-07 Gabriel add __on_rt_assert_hook */ #include @@ -1741,6 +1742,12 @@ int __rt_ffs(int value) #endif /* RT_USING_TINY_FFS */ #endif /* RT_USING_CPU_FFS */ + +#ifndef __on_rt_assert_hook + #define __on_rt_assert_hook(ex, func, line) __ON_HOOK_ARGS(rt_assert_hook, (ex, func, line)) +#endif + + #ifdef RT_DEBUG /* RT_ASSERT(EX)'s hook */ diff --git a/src/mempool.c b/src/mempool.c index 09a4955eee..ea0ea94cfa 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -14,6 +14,7 @@ * 2010-10-26 yi.qiu add module support in rt_mp_delete * 2011-01-24 Bernard add object allocation check. * 2012-03-22 Bernard fix align issue in rt_mp_init and rt_mp_create. + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to mempool.c */ #include @@ -21,7 +22,14 @@ #ifdef RT_USING_MEMPOOL -#ifdef RT_USING_HOOK +#ifndef __on_rt_mp_alloc_hook + #define __on_rt_mp_alloc_hook(mp, block) __ON_HOOK_ARGS(rt_mp_alloc_hook, (mp, block)) +#endif +#ifndef __on_rt_mp_free_hook + #define __on_rt_mp_free_hook(mp, block) __ON_HOOK_ARGS(rt_mp_free_hook, (mp, block)) +#endif + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_mp_alloc_hook)(struct rt_mempool *mp, void *block); static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block); diff --git a/src/object.c b/src/object.c index 76534f4566..46e53a7f99 100644 --- a/src/object.c +++ b/src/object.c @@ -13,6 +13,7 @@ * 2010-10-26 yi.qiu add module support in rt_object_allocate and rt_object_free * 2017-12-10 Bernard Add object_info enum. * 2018-01-25 Bernard Fix the object find issue when enable MODULE. + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to object.c */ #include @@ -113,7 +114,25 @@ static struct rt_object_information _object_container[RT_Object_Info_Unknown] = #endif }; -#ifdef RT_USING_HOOK + +#ifndef __on_rt_object_attach_hook + #define __on_rt_object_attach_hook(obj) __ON_HOOK_ARGS(rt_object_attach_hook, (obj)) +#endif +#ifndef __on_rt_object_detach_hook + #define __on_rt_object_detach_hook(obj) __ON_HOOK_ARGS(rt_object_detach_hook, (obj)) +#endif +#ifndef __on_rt_object_trytake_hook + #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent)) +#endif +#ifndef __on_rt_object_take_hook + #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) +#endif +#ifndef __on_rt_object_put_hook + #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) +#endif + + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_object_attach_hook)(struct rt_object *object); static void (*rt_object_detach_hook)(struct rt_object *object); void (*rt_object_trytake_hook)(struct rt_object *object); diff --git a/src/scheduler.c b/src/scheduler.c index 6ef02f3d3c..bcc74a2604 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -27,6 +27,7 @@ * rt_schedule_insert_thread won't insert current task to ready queue * in smp version, rt_hw_context_switch_interrupt maybe switch to * new task directly + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to scheduler.c * */ @@ -47,7 +48,14 @@ struct rt_thread *rt_current_thread = RT_NULL; rt_uint8_t rt_current_priority; #endif /* RT_USING_SMP */ -#ifdef RT_USING_HOOK +#ifndef __on_rt_scheduler_hook + #define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to)) +#endif +#ifndef __on_rt_scheduler_switch_hook + #define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid)) +#endif + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); static void (*rt_scheduler_switch_hook)(struct rt_thread *tid); diff --git a/src/thread.c b/src/thread.c index 090f5f1ef7..a024a3b7dc 100644 --- a/src/thread.c +++ b/src/thread.c @@ -28,13 +28,24 @@ * add support for tasks bound to cpu * 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it * 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to thread.c */ #include #include #include -#ifdef RT_USING_HOOK +#ifndef __on_rt_thread_inited_hook + #define __on_rt_thread_inited_hook(thread) __ON_HOOK_ARGS(rt_thread_inited_hook, (thread)) +#endif +#ifndef __on_rt_thread_suspend_hook + #define __on_rt_thread_suspend_hook(thread) __ON_HOOK_ARGS(rt_thread_suspend_hook, (thread)) +#endif +#ifndef __on_rt_thread_resume_hook + #define __on_rt_thread_resume_hook(thread) __ON_HOOK_ARGS(rt_thread_resume_hook, (thread)) +#endif + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_thread_suspend_hook)(rt_thread_t thread); static void (*rt_thread_resume_hook) (rt_thread_t thread); static void (*rt_thread_inited_hook) (rt_thread_t thread); diff --git a/src/timer.c b/src/timer.c index 846c33263b..da113298da 100644 --- a/src/timer.c +++ b/src/timer.c @@ -17,6 +17,7 @@ * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer * timeout function. * 2021-08-15 supperthomas add the comment + * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to timer.c */ #include @@ -47,7 +48,20 @@ ALIGN(RT_ALIGN_SIZE) static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #endif /* RT_USING_TIMER_SOFT */ -#ifdef RT_USING_HOOK +#ifndef __on_rt_object_take_hook + #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) +#endif +#ifndef __on_rt_object_put_hook + #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) +#endif +#ifndef __on_rt_timer_enter_hook + #define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t)) +#endif +#ifndef __on_rt_timer_exit_hook + #define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t)) +#endif + +#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) extern void (*rt_object_take_hook)(struct rt_object *object); extern void (*rt_object_put_hook)(struct rt_object *object); static void (*rt_timer_enter_hook)(struct rt_timer *timer); -- cgit v1.3.1 From 075e04e344f0cea8d62504c244861f473921c495 Mon Sep 17 00:00:00 2001 From: xiangxistu <52819708+xiangxistu@users.noreply.github.com> Date: Thu, 20 Jan 2022 20:53:47 +0800 Subject: the support for PSE51 (#5534) * [add] the function realization of signal for posix. * [update] the posix support for armclang. * [add] the new macro "RT_USING_POSIX_TIMER". * [modify] select "RT_USING_SOFT_TIMER" when use posix'timer. * [bug] optimize the logic for the "time_xxx" functions. * [modify] use "RT_USING_POSIX_TIMER" to protect the macro definition. * [modify] error code when except happened. * [delete] the "environ" is useless at this time. --- .../libc/compilers/common/extension/sys/types.h | 2 + .../libc/compilers/common/extension/sys/unistd.h | 3 + components/libc/compilers/common/sys/signal.h | 38 +++ components/libc/compilers/common/sys/time.h | 29 +- components/libc/compilers/common/time.c | 263 +++++++++++++++++ components/libc/posix-info.txt | 327 +++++++++++++++++++++ components/libc/posix/Kconfig | 5 + components/libc/posix/delay/delay.h | 1 + components/libc/posix/pthreads/pthread.h | 4 + components/libc/posix/signal/posix_signal.c | 40 ++- include/rtdef.h | 1 + src/timer.c | 2 + 12 files changed, 711 insertions(+), 4 deletions(-) create mode 100644 components/libc/posix-info.txt (limited to 'src/timer.c') diff --git a/components/libc/compilers/common/extension/sys/types.h b/components/libc/compilers/common/extension/sys/types.h index 32b2493c95..85cd4fea21 100644 --- a/components/libc/compilers/common/extension/sys/types.h +++ b/components/libc/compilers/common/extension/sys/types.h @@ -28,6 +28,8 @@ typedef signed int ssize_t; /* Used for a count of bytes or an error #else typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ #endif +typedef unsigned long __timer_t; +typedef __timer_t timer_t; typedef long suseconds_t; /* microseconds. */ typedef unsigned long useconds_t; /* microseconds (unsigned) */ diff --git a/components/libc/compilers/common/extension/sys/unistd.h b/components/libc/compilers/common/extension/sys/unistd.h index 650c87dc18..29ec3f70c4 100644 --- a/components/libc/compilers/common/extension/sys/unistd.h +++ b/components/libc/compilers/common/extension/sys/unistd.h @@ -19,10 +19,13 @@ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ +unsigned alarm(unsigned __secs); ssize_t read(int fd, void *buf, size_t len); ssize_t write(int fd, const void *buf, size_t len); off_t lseek(int fd, off_t offset, int whence); +int pause(void); int fsync(int fildes); +long sysconf(int __name); int unlink(const char *pathname); int close(int d); int ftruncate(int fd, off_t length); diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h index 9787958a37..041dd765b7 100644 --- a/components/libc/compilers/common/sys/signal.h +++ b/components/libc/compilers/common/sys/signal.h @@ -17,6 +17,19 @@ extern "C" { #endif #include +#include + + +/* sigev_notify values + NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ + +#define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */ + /* when the event of interest occurs. */ +#define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */ + /* value, shall be delivered when the event of */ + /* interest occurs. */ +#define SIGEV_THREAD 3 /* A notification function shall be called to */ + /* perform notification. */ /* Signal Generation and Delivery, P1003.1b-1993, p. 63 NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and @@ -62,6 +75,16 @@ struct sigaction int sa_flags; }; +/* + * Structure used in sigaltstack call. + */ +typedef struct sigaltstack +{ + void *ss_sp; /* Stack base or pointer. */ + int ss_flags; /* Flags. */ + size_t ss_size; /* Stack size. */ +} stack_t; + #define SIG_SETMASK 0 /* set mask with sigprocmask() */ #define SIG_BLOCK 1 /* set of signals to block */ #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ @@ -73,6 +96,15 @@ struct sigaction #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) int sigprocmask (int how, const sigset_t *set, sigset_t *oset); +int sigpending (sigset_t *set); +int sigsuspend (const sigset_t *set); + +#include "time.h" +int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout); +int sigwait(const sigset_t *set, int *sig); +int sigwaitinfo(const sigset_t *set, siginfo_t *info); +int raise(int sig); +int sigqueue(pid_t pid, int signo, const union sigval value); int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); #ifdef __ARMCC_VERSION @@ -100,6 +132,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #define SIGTTOU 22 #define SIGPOLL 23 #define SIGWINCH 24 +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ /* #define SIGUSR1 25 */ /* #define SIGUSR2 26 */ #define SIGRTMIN 27 @@ -133,6 +168,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #define SIGTTOU 22 #define SIGPOLL 23 #define SIGWINCH 24 +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ #define SIGUSR1 25 #define SIGUSR2 26 #define SIGRTMIN 27 diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 758333796d..a3af31b20b 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -60,6 +60,16 @@ struct timespec time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; + +/* + * Structure defined by POSIX.1b to be like a itimerval, but with + * timespecs. Used in the timer_*() system calls. + */ +struct itimerspec +{ + struct timespec it_interval; + struct timespec it_value; +}; #endif int stime(const time_t *t); @@ -68,6 +78,9 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); int settimeofday(const struct timeval *tv, const struct timezone *tz); #if defined(__ARMCC_VERSION) || defined (__ICCARM__) struct tm *gmtime_r(const time_t *timep, struct tm *r); +struct tm* localtime_r(const time_t* t, struct tm* r); +char* asctime_r(const struct tm *t, char *buf); +char *ctime_r(const time_t * tim_p, char * result); #elif defined(_WIN32) struct tm* gmtime_r(const time_t* timep, struct tm* r); struct tm* gmtime(const time_t* t); @@ -84,7 +97,7 @@ time_t time(time_t* t); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #endif /* RT_USING_POSIX_DELAY */ -#ifdef RT_USING_POSIX_CLOCK +#if defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) /* POSIX clock and timer */ #define MILLISECOND_PER_SECOND 1000UL #define MICROSECOND_PER_SECOND 1000000UL @@ -110,7 +123,9 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 4 #endif +#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */ +#ifdef RT_USING_POSIX_CLOCK int clock_getres (clockid_t clockid, struct timespec *res); int clock_gettime (clockid_t clockid, struct timespec *tp); int clock_settime (clockid_t clockid, const struct timespec *tp); @@ -118,6 +133,16 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s int rt_timespec_to_tick(const struct timespec *time); #endif /* RT_USING_POSIX_CLOCK */ +#ifdef RT_USING_POSIX_TIMER +#include "signal.h" +int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid); +int timer_delete(timer_t timerid); +int timer_getoverrun(timer_t timerid); +int timer_gettime(timer_t timerid, struct itimerspec *its); +int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue); +#endif /* RT_USING_POSIX_TIMER */ + /* timezone */ void tz_set(int8_t tz); int8_t tz_get(void); diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 0b34236952..a963b25f1a 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -718,6 +718,269 @@ RTM_EXPORT(rt_timespec_to_tick); #endif /* RT_USING_POSIX_CLOCK */ +#ifdef RT_USING_POSIX_TIMER + +#define ACTIVE 1 +#define NOT_ACTIVE 0 + +struct timer_obj +{ + struct rt_timer timer; + void (*sigev_notify_function)(union sigval val); + union sigval val; + struct timespec interval; /* Reload value */ + rt_uint32_t reload; /* Reload value in ms */ + rt_uint32_t status; +}; + +static void rtthread_timer_wrapper(void *timerobj) +{ + struct timer_obj *timer; + + timer = (struct timer_obj *)timerobj; + + if (timer->reload == 0U) + { + timer->status = NOT_ACTIVE; + } + + if(timer->sigev_notify_function != RT_NULL) + { + (timer->sigev_notify_function)(timer->val); + } +} + +/** + * @brief Create a per-process timer. + * + * This API does not accept SIGEV_THREAD as valid signal event notification + * type. + * + * See IEEE 1003.1 + */ +int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) +{ + static int num = 0; + struct timer_obj *timer; + char timername[RT_NAME_MAX] = {0}; + + if (clockid != CLOCK_MONOTONIC || evp == NULL || + (evp->sigev_notify != SIGEV_NONE && + evp->sigev_notify != SIGEV_SIGNAL)) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + timer = rt_malloc(sizeof(struct timer_obj)); + if(timer == RT_NULL) + { + rt_set_errno(ENOMEM); + return -RT_ENOMEM; + } + + RT_ASSERT(evp->sigev_notify_function != RT_NULL); + rt_snprintf(timername, RT_NAME_MAX, "psx_tm%02d", num++); + num %= 100; + timer->sigev_notify_function = evp->sigev_notify_function; + timer->val = evp->sigev_value; + timer->interval.tv_sec = 0; + timer->interval.tv_nsec = 0; + timer->reload = 0U; + timer->status = NOT_ACTIVE; + + if (evp->sigev_notify == SIGEV_NONE) + { + rt_timer_init(&timer->timer, timername, RT_NULL, RT_NULL, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); + } + else + { + rt_timer_init(&timer->timer, timername, rtthread_timer_wrapper, timer, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); + } + + *timerid = (timer_t)timer; + + return RT_EOK; +} +RTM_EXPORT(timer_create); + +/** + * @brief Delete a per-process timer. + * + * See IEEE 1003.1 + */ +int timer_delete(timer_t timerid) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + + if (timer == RT_NULL) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (timer->status == ACTIVE) + { + timer->status = NOT_ACTIVE; + rt_timer_stop(&timer->timer); + } + + rt_free(timer); + + return RT_EOK; +} +RTM_EXPORT(timer_delete); + +/** + * + * Return the overrun count for the last timer expiration. + * It is subefficient to create a new structure to get overrun count. + **/ +int timer_getoverrun(timer_t timerid) +{ + rt_set_errno(ENOSYS); + return -RT_ERROR; +} + +/** + * @brief Get amount of time left for expiration on a per-process timer. + * + * See IEEE 1003.1 + */ +int timer_gettime(timer_t timerid, struct itimerspec *its) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + rt_tick_t remaining; + rt_uint32_t seconds, nanoseconds; + rt_int64_t nsecs, secs; + + if (timer == NULL) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (its == NULL) + { + rt_set_errno(EFAULT); + return -RT_ERROR; + } + + if (timer->status == ACTIVE) + { + rt_tick_t remain_tick; + + rt_timer_control(&timer->timer, RT_TIMER_CTRL_GET_REMAIN_TIME, &remain_tick); + + /* 'remain_tick' is minimum-unit in the RT-Thread' timer, + * so the seconds, nanoseconds will be calculated by 'remain_tick'. + */ + remaining = remain_tick - rt_tick_get(); + + /* calculate 'second' */ + seconds = remaining / RT_TICK_PER_SECOND; + + /* calculate 'nanosecond'; To avoid lost of accuracy, because "RT_TICK_PER_SECOND" maybe 100, 1000, 1024 and so on. + * + * remain_tick millisecond remain_tick * MILLISECOND_PER_SECOND + * ------------------------- = -------------------------- ---> millisecond = ------------------------------------------- + * RT_TICK_PER_SECOND MILLISECOND_PER_SECOND RT_TICK_PER_SECOND + * + * remain_tick * MILLISECOND_PER_SECOND remain_tick * MILLISECOND_PER_SECOND * MICROSECOND_PER_SECOND + * millisecond = ---------------------------------------- ---> nanosecond = ------------------------------------------------------------------- + * RT_TICK_PER_SECOND RT_TICK_PER_SECOND + * + */ + nanoseconds = (((remaining % RT_TICK_PER_SECOND) * MILLISECOND_PER_SECOND) * MICROSECOND_PER_SECOND) / RT_TICK_PER_SECOND ; + + its->it_value.tv_sec = (rt_int32_t)seconds; + its->it_value.tv_nsec = (rt_int32_t)nanoseconds; + } + else + { + /* Timer is disarmed */ + its->it_value.tv_sec = 0; + its->it_value.tv_nsec = 0; + } + + /* The interval last set by timer_settime() */ + its->it_interval = timer->interval; + return RT_EOK; +} +RTM_EXPORT(timer_gettime); + +/** + * @brief Sets expiration time of per-process timer. + * + * See IEEE 1003.1 + */ +int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + rt_uint32_t duration, current; + + if (timer == NULL || + value->it_interval.tv_nsec < 0 || + value->it_interval.tv_nsec >= NANOSECOND_PER_SECOND || + value->it_value.tv_nsec < 0 || + value->it_value.tv_nsec >= NANOSECOND_PER_SECOND) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (value == NULL || ovalue == NULL) + { + rt_set_errno(EFAULT); + return -RT_ERROR; + } + + /* Save time to expire and old reload value. */ + if (ovalue != NULL) + { + timer_gettime(timerid, ovalue); + } + + /* Stop the timer if the value is 0 */ + if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) + { + if (timer->status == ACTIVE) + { + rt_timer_stop(&timer->timer); + } + + timer->status = NOT_ACTIVE; + return RT_EOK; + } + + /* calculate timer period(tick); To avoid lost of accuracy, because "RT_TICK_PER_SECOND" maybe 100, 1000, 1024 and so on. + * + * tick nanosecond nanosecond * RT_TICK_PER_SECOND + * ------------------------- = -------------------------- ---> tick = ------------------------------------- + * RT_TICK_PER_SECOND NANOSECOND_PER_SECOND NANOSECOND_PER_SECOND + * + */ + timer->reload = (value->it_interval.tv_sec * RT_TICK_PER_SECOND) + (value->it_interval.tv_nsec * RT_TICK_PER_SECOND) / NANOSECOND_PER_SECOND; + timer->interval.tv_sec = value->it_interval.tv_sec; + timer->interval.tv_nsec = value->it_interval.tv_nsec; + + if (timer->status == ACTIVE) + { + rt_timer_stop(&timer->timer); + } + + timer->status = ACTIVE; + rt_timer_control(&timer->timer, RT_TIMER_CTRL_SET_TIME, (void *)timer->reload); + rt_timer_control(&timer->timer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL); + rt_timer_start(&timer->timer); + + return RT_EOK; +} +RTM_EXPORT(timer_settime); +#endif /* RT_USING_POSIX_TIMER */ + + /* timezone */ #ifndef RT_LIBC_DEFAULT_TIMEZONE #define RT_LIBC_DEFAULT_TIMEZONE 8 diff --git a/components/libc/posix-info.txt b/components/libc/posix-info.txt new file mode 100644 index 0000000000..e5cccbc89b --- /dev/null +++ b/components/libc/posix-info.txt @@ -0,0 +1,327 @@ +### The list of function support for POSIX 51 standard in the RT-Thread + + ++ isalnum() ++ isalpha() ++ isblank() ++ iscntrl() ++ isdigit() ++ isgraph() ++ islower() ++ isprint() ++ ispunct() ++ isspace() ++ isupper() ++ isxdigit() ++ tolower() ++ toupper() + + -> for gcc, keil, iar platform at the same time; + Suggest to choose ++ errno + + ++ open() + + ;the 'env' should combined with non-volatile devices ++ feclearexcept() ++ fegetenv() ++ fegetexceptflag() ++ fegetround() ++ feholdexcept() ++ feraiseexcept() ++ fesetenv() ++ fesetexceptflag() ++ fesetround() ++ fetestexcept() ++ feupdateenv() + + ++ imaxabs() ++ imaxdiv() ++ strtoimax() ++ strtoumax() + + ++ localeconv() ++ setlocale() + + ++ pthread_atfork() ++ pthread_attr_destroy() ++ pthread_attr_getdetachstate() ++ pthread_attr_getguardsize() ++ pthread_attr_getinheritsched() ++ pthread_attr_getschedparam() ++ pthread_attr_getschedpolicy() ++ pthread_attr_getscope() ++ pthread_attr_getstack() ++ pthread_attr_getstackaddr() ++ pthread_attr_getstacksize() ++ pthread_attr_init() ++ pthread_attr_setdetachstate() ++ pthread_attr_setguardsize() ++ pthread_attr_setinheritsched() ++ pthread_attr_setschedparam() ++ pthread_attr_setschedpolicy() ++ pthread_attr_setscope() ++ pthread_attr_setstack() ++ pthread_attr_setstackaddr() ++ pthread_attr_setstacksize() ++ pthread_cancel() ++ pthread_cleanup_pop() ++ pthread_cleanup_push() ++ pthread_cond_broadcast() ++ pthread_cond_destroy() ++ pthread_cond_init() ++ pthread_cond_signal() ++ pthread_cond_timedwait() ++ pthread_cond_wait() ++ pthread_condattr_destroy() ++ pthread_condattr_getclock() ++ pthread_condattr_init() ++ pthread_condattr_setclock() ++ pthread_create() ++ pthread_detach() ++ pthread_equal() ++ pthread_exit() ++ pthread_getcpuclockid() ++ pthread_getconcurrency() ++ pthread_getschedparam() ++ pthread_getspecific() ++ pthread_join() ++ pthread_key_create() ++ pthread_key_delete() ++ pthread_mutex_destroy() ++ pthread_mutex_getprioceiling() ++ pthread_mutex_init() ++ pthread_mutex_lock() ++ pthread_mutex_setprioceiling() ++ pthread_mutex_trylock() ++ pthread_mutex_unlock() ++ pthread_mutexattr_destroy() ++ pthread_mutexattr_getprioceiling() ++ pthread_mutexattr_getprotocol() ++ pthread_mutexattr_gettype() ++ pthread_mutexattr_init() ++ pthread_mutexattr_setprioceiling() ++ pthread_mutexattr_setprotocol() ++ pthread_mutexattr_settype() ++ pthread_once() ++ pthread_self() ++ pthread_setcancelstate() ++ pthread_setcanceltype() ++ pthread_setconcurrency() ++ pthread_setschedparam() ++ pthread_setschedprio() ++ pthread_setspecific() ++ pthread_testcancel() + + ++ sched_get_priority_max() ++ sched_get_priority_min() ++ sched_rr_get_interval() + + ++ sem_close() ++ sem_destroy() ++ sem_getvalue() ++ sem_init() ++ sem_open() ++ sem_post() ++ sem_timedwait() ++ sem_trywait() ++ sem_unlink() ++ sem_wait() + + ++ longjmp() ++ setjmp() + + -> for gcc, keil, iar platform at the same time; + Suggest to choose ++ kill() ++ pthread_kill() ++ pthread_sigmask() ++ raise() ++ sigaction() ++ sigaddset() ++ sigdelset() ++ sigemptyset() ++ sigfillset() ++ sigismember() ++ signal() ++ sigpending() ++ sigprocmask() +- sigqueue() ++ sigsuspend() ++ sigtimedwait() ++ sigwait() ++ sigwaitinfo() + + ++ va_arg() ++ va_copy() ++ va_end() ++ va_start() + + ++ clearerr() ++ fclose() +- fdopen() ++ feof() ++ ferror() ++ fflush() ++ fgetc() ++ fgets() +- fileno() +- flockfile() ++ fopen() ++ fprintf() ++ fputc() ++ fputs() ++ fread() ++ freopen() ++ fscanf() +- ftrylockfile() +- funlockfile() ++ fwrite() ++ getc() +% getc_unlocked() ; thread safe in the default ++ getchar() ++ getchar_unlocked() ++ gets() ++ perror() ++ printf() ++ putc() +% putc_unlocked() ; thread safe in the default ++ putchar() +% putchar_unlocked() ; thread safe in the default ++ puts() ++ scanf() ++ setbuf() ++ setvbuf() ++ snprintf() ++ sprintf() ++ sscanf() ++ stderr ++ stdin ++ stdout ++ ungetc() ++ vfprintf() ++ vfscanf() ++ vprintf() ++ vscanf() ++ vsnprintf() ++ vsprintf() ++ vsscanf() + + ++ abort() ++ abs() ++ atof() ++ atoi() ++ atol() ++ atoll() ++ bsearch() ++ calloc() ++ div() ++ free() ++ getenv() ++ labs() ++ ldiv() ++ llabs() ++ lldiv() ++ malloc() ++ qsort() ++ rand() +% rand_r() ; thread safe in the default ++ realloc() +- setenv() ;the 'env' should combined with non-volatile devices ++ srand() ++ strtod() ++ strtof() ++ strtol() ++ strtold() ++ strtoll() ++ strtoul() ++ strtoull() +- unsetenv() ;the 'env' should combined with non-volatile devices + + ++ memchr() ++ memcmp() ++ memcpy() ++ memmove() ++ memset() ++ strcat() ++ strchr() ++ strcmp() ++ strcoll() ++ strcpy() ++ strcspn() ++ strerror() +% strerror_r() ; thread safe in the default ++ strlen() ++ strncat() ++ strncmp() ++ strncpy() ++ strpbrk() ++ strrchr() ++ strspn() ++ strstr() ++ strtok() +% strtok_r() ; thread safe in the default ++ strxfrm() + + +- mlockall() ++ mmap() +- munlock() ++ munmap() +- shm_open() +- shm_unlink() + + ++ uname() + + -> for gcc, keil, iar platform at the same time; + Suggest to choose ++ asctime() ++ asctime_r() ++ clock_getres() ++ clock_gettime() ++ clock_nanosleep() ++ clock_settime() ++ ctime() ++ ctime_r() ++ difftime() ++ gmtime() ++ gmtime_r() ++ localtime() ++ localtime_r() ++ mktime() ++ nanosleep() ++ strftime() ++ time() ++ timer_create() ++ timer_delete() ++ timer_getoverrun() ++ timer_gettime() ++ timer_settime() +% tzname ; you should better use 'tz_xxx' in the rt-thread. +% tzset() ; you should better use 'tz_xxx' in the rt-thread. + + ++ alarm() ++ close() ++ environ +% fdatasync() ;smaller ranther than , in the rt-thread, it is universal ++ fsync() ++ pause() ++ read() ++ sysconf() ++ write() +- confstr() + + diff --git a/components/libc/posix/Kconfig b/components/libc/posix/Kconfig index 76dabc2734..8f527fa46d 100644 --- a/components/libc/posix/Kconfig +++ b/components/libc/posix/Kconfig @@ -49,6 +49,11 @@ config RT_USING_POSIX_CLOCK select RT_USING_POSIX_DELAY default n +config RT_USING_POSIX_TIMER + select RT_USING_TIMER_SOFT + bool "Enable posix time functions, timer_create()/timer_gettime()/timer_settime() etc" + default n + config RT_USING_PTHREADS bool "Enable pthreads APIs" select RT_USING_POSIX_CLOCK diff --git a/components/libc/posix/delay/delay.h b/components/libc/posix/delay/delay.h index 19492bdb45..eb0332e0cd 100644 --- a/components/libc/posix/delay/delay.h +++ b/components/libc/posix/delay/delay.h @@ -11,6 +11,7 @@ #ifndef __DELAY_H__ #define __DELAY_H__ +unsigned int sleep(unsigned int seconds); void msleep(unsigned int msecs); void ssleep(unsigned int seconds); void mdelay(unsigned long msecs); diff --git a/components/libc/posix/pthreads/pthread.h b/components/libc/posix/pthreads/pthread.h index ad3259d2dc..c170ec49fd 100644 --- a/components/libc/posix/pthreads/pthread.h +++ b/components/libc/posix/pthreads/pthread.h @@ -185,6 +185,10 @@ int pthread_setschedprio(pthread_t thread, int prio); void pthread_exit (void *value_ptr); int pthread_once(pthread_once_t * once_control, void (*init_routine) (void)); +#ifdef RT_USING_SIGNALS +int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset); +#endif + /* pthread cleanup */ void pthread_cleanup_pop(int execute); void pthread_cleanup_push(void (*routine)(void*), void *arg); diff --git a/components/libc/posix/signal/posix_signal.c b/components/libc/posix/signal/posix_signal.c index ac8d2b1eef..c87bc6104f 100644 --- a/components/libc/posix/signal/posix_signal.c +++ b/components/libc/posix/signal/posix_signal.c @@ -55,6 +55,35 @@ int sigprocmask (int how, const sigset_t *set, sigset_t *oset) return 0; } +int sigpending (sigset_t *set) +{ + sigprocmask(SIG_SETMASK, RT_NULL, set); + return 0; +} + +int sigsuspend (const sigset_t *set) +{ + int ret = 0; + sigset_t origin_set; + sigset_t suspend_set; + siginfo_t info; /* unless paremeter */ + + /* get the origin signal information */ + sigpending(&origin_set); + + /* set the new signal information */ + sigprocmask(SIG_BLOCK, set, RT_NULL); + sigpending(&suspend_set); + + ret = rt_signal_wait(&suspend_set, &info, RT_WAITING_FOREVER); + + /* restore the original sigprocmask */ + sigprocmask(SIG_UNBLOCK, (sigset_t *)0xffffUL, RT_NULL); + sigprocmask(SIG_BLOCK, &origin_set, RT_NULL); + + return ret; +} + int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { rt_sighandler_t old = RT_NULL; @@ -75,8 +104,7 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) return 0; } -int sigtimedwait(const sigset_t *set, siginfo_t *info, - const struct timespec *timeout) +int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout) { int ret = 0; int tick = RT_WAITING_FOREVER; @@ -114,3 +142,11 @@ int raise(int sig) return 0; } +#include +int sigqueue (pid_t pid, int signo, const union sigval value) +{ + /* no support, signal queue */ + + return -1; +} + diff --git a/include/rtdef.h b/include/rtdef.h index e9f8cb8068..66d30001a0 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -487,6 +487,7 @@ struct rt_object_information #define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */ #define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */ #define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/ +#define RT_TIMER_CTRL_GET_REMAIN_TIME 0x5 /**< get the remaining hang time */ #ifndef RT_TIMER_SKIP_LIST_LEVEL #define RT_TIMER_SKIP_LIST_LEVEL 1 diff --git a/src/timer.c b/src/timer.c index da113298da..6ef9a4ed3f 100644 --- a/src/timer.c +++ b/src/timer.c @@ -581,6 +581,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) /*timer is stop*/ *(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED; } + case RT_TIMER_CTRL_GET_REMAIN_TIME: + *(rt_tick_t *)arg = timer->timeout_tick; break; default: -- cgit v1.3.1 From 65ecca80ee7b3e63998d2207f28fdc8847169eb3 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 14 Jan 2022 12:24:12 -0500 Subject: [kernel] improve comments --- src/device.c | 21 +++++++++++++++------ src/ipc.c | 13 +++++++------ src/thread.c | 16 ++++++++-------- src/timer.c | 12 ++++++------ 4 files changed, 36 insertions(+), 26 deletions(-) (limited to 'src/timer.c') diff --git a/src/device.c b/src/device.c index ebb8f26854..9bfaf776d6 100644 --- a/src/device.c +++ b/src/device.c @@ -82,6 +82,7 @@ RTM_EXPORT(rt_device_register); */ rt_err_t rt_device_unregister(rt_device_t dev) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); RT_ASSERT(rt_object_is_systemobject(&dev->parent)); @@ -143,6 +144,7 @@ RTM_EXPORT(rt_device_create); */ void rt_device_destroy(rt_device_t dev) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); RT_ASSERT(rt_object_is_systemobject(&dev->parent) == RT_FALSE); @@ -202,6 +204,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) { rt_err_t result = RT_EOK; + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -267,6 +270,7 @@ rt_err_t rt_device_close(rt_device_t dev) { rt_err_t result = RT_EOK; + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -312,6 +316,7 @@ rt_size_t rt_device_read(rt_device_t dev, void *buffer, rt_size_t size) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -354,6 +359,7 @@ rt_size_t rt_device_write(rt_device_t dev, const void *buffer, rt_size_t size) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -389,6 +395,7 @@ RTM_EXPORT(rt_device_write); */ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -412,10 +419,11 @@ RTM_EXPORT(rt_device_control); * * @return RT_EOK */ -rt_err_t -rt_device_set_rx_indicate(rt_device_t dev, - rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size)) +rt_err_t rt_device_set_rx_indicate(rt_device_t dev, + rt_err_t (*rx_ind)(rt_device_t dev, + rt_size_t size)) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); @@ -435,10 +443,11 @@ RTM_EXPORT(rt_device_set_rx_indicate); * * @return RT_EOK */ -rt_err_t -rt_device_set_tx_complete(rt_device_t dev, - rt_err_t (*tx_done)(rt_device_t dev, void *buffer)) +rt_err_t rt_device_set_tx_complete(rt_device_t dev, + rt_err_t (*tx_done)(rt_device_t dev, + void *buffer)) { + /* parameter check */ RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); diff --git a/src/ipc.c b/src/ipc.c index 09cc74e103..aea149a67a 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -725,8 +725,7 @@ RTM_EXPORT(rt_sem_control); * * @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. + * NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL. * * @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. @@ -735,7 +734,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; + /* flag parameter has been obsoleted */ + RT_UNUSED(flag); /* parameter check */ RT_ASSERT(mutex != RT_NULL); @@ -807,8 +807,7 @@ RTM_EXPORT(rt_mutex_detach); * * @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. + * NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL. * * @return Return a pointer to the mutex object. When the return value is RT_NULL, it means the creation failed. * @@ -817,7 +816,9 @@ RTM_EXPORT(rt_mutex_detach); rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) { struct rt_mutex *mutex; - (void)flag; + + /* flag parameter has been obsoleted */ + RT_UNUSED(flag); RT_DEBUG_NOT_IN_INTERRUPT; diff --git a/src/thread.c b/src/thread.c index 6c221c1f29..bf1f2482a9 100644 --- a/src/thread.c +++ b/src/thread.c @@ -130,7 +130,7 @@ static void _thread_timeout(void *parameter) thread = (struct rt_thread *)parameter; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); 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); @@ -289,7 +289,7 @@ rt_err_t rt_thread_init(struct rt_thread *thread, rt_uint8_t priority, rt_uint32_t tick) { - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(stack_start != RT_NULL); @@ -340,7 +340,7 @@ RTM_EXPORT(rt_thread_self); */ rt_err_t rt_thread_startup(rt_thread_t thread) { - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); @@ -383,7 +383,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread) { rt_base_t lock; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); @@ -486,7 +486,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) { rt_base_t lock; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); @@ -703,7 +703,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) { register rt_base_t temp; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); @@ -821,7 +821,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread) register rt_base_t stat; register rt_base_t temp; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(thread == rt_thread_self()); @@ -867,7 +867,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread) { register rt_base_t temp; - /* thread check */ + /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); diff --git a/src/timer.c b/src/timer.c index 6ef9a4ed3f..577dd5ae47 100644 --- a/src/timer.c +++ b/src/timer.c @@ -257,7 +257,7 @@ void rt_timer_init(rt_timer_t timer, rt_tick_t time, rt_uint8_t flag) { - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); /* timer object initialization */ @@ -278,7 +278,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); RT_ASSERT(rt_object_is_systemobject(&timer->parent)); @@ -347,7 +347,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); RT_ASSERT(rt_object_is_systemobject(&timer->parent) == RT_FALSE); @@ -386,7 +386,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) unsigned int tst_nr; static unsigned int random_nr; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); @@ -511,7 +511,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); @@ -547,7 +547,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { register rt_base_t level; - /* timer check */ + /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); -- cgit v1.3.1 From 1874bd25aae647d116dac36a17d3bc79850e200b Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 16 Jan 2022 14:33:41 -0500 Subject: [timer] improve parameter checking --- components/drivers/src/workqueue.c | 3 ++- src/timer.c | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src/timer.c') diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 6dbb0da627..9ee333cedd 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -98,7 +98,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, /* remove list */ rt_list_remove(&(work->list)); work->flags &= ~RT_WORK_STATE_PENDING; - /* */ + if (ticks == 0) { if (queue->work_current != work) @@ -288,6 +288,7 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) * @param queue A pointer to the workqueue object. * @param work A pointer to the work item object. * @param time The delay time (unit: OS ticks) for the work item to be submitted to the work queue. + * The max timeout tick should be no more than (RT_TICK_MAX/2 - 1) * * @return RT_EOK Success. * @return -RT_EBUSY This work item is executing. diff --git a/src/timer.c b/src/timer.c index 577dd5ae47..63cbcf9e07 100644 --- a/src/timer.c +++ b/src/timer.c @@ -246,9 +246,12 @@ void rt_timer_dump(rt_list_t timer_heads[]) * * @param parameter is the param of the callback * - * @param time is the ticks of timer + * @param time is timeout ticks of timer + * + * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1). * * @param flag is the flag of timer + * */ void rt_timer_init(rt_timer_t timer, const char *name, @@ -259,6 +262,8 @@ void rt_timer_init(rt_timer_t timer, { /* parameter check */ RT_ASSERT(timer != RT_NULL); + RT_ASSERT(timeout != RT_NULL); + RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); /* timer object initialization */ rt_object_init(&(timer->parent), RT_Object_Class_Timer, name); @@ -303,15 +308,17 @@ RTM_EXPORT(rt_timer_detach); /** * @brief This function will create a timer * - * @param name the name of timer + * @param name is the name of timer * - * @param timeout the timeout function + * @param timeout is the timeout function * - * @param parameter the parameter of timeout function + * @param parameter is the parameter of timeout function * - * @param time the tick of timer + * @param time is timeout ticks of the timer * - * @param flag the flag of timer + * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1). + * + * @param flag is the flag of timer * * @return the created timer object */ @@ -323,6 +330,10 @@ rt_timer_t rt_timer_create(const char *name, { struct rt_timer *timer; + /* parameter check */ + RT_ASSERT(timeout != RT_NULL); + RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); + /* allocate a object */ timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name); if (timer == RT_NULL) @@ -401,11 +412,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent))); - /* - * get timeout tick, - * the max timeout tick shall not great than RT_TICK_MAX/2 - */ - RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); timer->timeout_tick = rt_tick_get() + timer->init_tick; #ifdef RT_USING_TIMER_SOFT -- cgit v1.3.1 From 36cbc1fd2f811f00280fe32cec8ff228d6142788 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 16 Jan 2022 15:15:08 -0500 Subject: [workqueue] time参数改为ticks,防止误解单位为ms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/workqueue.h | 25 ++++------------- components/drivers/src/workqueue.c | 44 ++++++++++++++++++++++++------ src/timer.c | 4 +-- 3 files changed, 42 insertions(+), 31 deletions(-) (limited to 'src/timer.c') diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index edefb0933e..4403969e67 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -54,37 +54,22 @@ struct rt_work /** * WorkQueue for DeviceDriver */ +void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data); struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority); rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue); rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work); -rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time); +rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks); rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work); rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work); rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue); rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work); #ifdef RT_USING_SYSTEM_WORKQUEUE -rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time); +rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks); rt_err_t rt_work_cancel(struct rt_work *work); #endif /* RT_USING_SYSTEM_WORKQUEUE */ -/** - * @brief Initialize a work item, binding with a callback function. - * - * @param work A pointer to the work item object. - * @param work_func A callback function that will be called when this work item is executed. - * @param work_data A user data passed to the callback function as the second parameter. - */ -rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), - void *work_data) -{ - rt_list_init(&(work->list)); - work->work_func = work_func; - work->work_data = work_data; - work->workqueue = RT_NULL; - work->flags = 0; - work->type = 0; -} + #endif /* RT_USING_HEAP */ diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 97e0a573bd..fe42ede0f6 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -210,6 +210,30 @@ static void _delayed_work_timeout_handler(void *parameter) } } +/** + * @brief Initialize a work item, binding with a callback function. + * + * @param work is a pointer to the work item object. + * + * @param work_func is a callback function that will be called when this work item is executed. + * + * @param work_data is a user data passed to the callback function as the second parameter. + */ +void rt_work_init(struct rt_work *work, + void (*work_func)(struct rt_work *work, void *work_data), + void *work_data) +{ + RT_ASSERT(work != RT_NULL); + RT_ASSERT(work_func != RT_NULL); + + rt_list_init(&(work->list)); + work->work_func = work_func; + work->work_data = work_data; + work->workqueue = RT_NULL; + work->flags = 0; + work->type = 0; +} + /** * @brief Create a work queue with a thread inside. * @@ -292,20 +316,21 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) * * @param work is a pointer to the work item object. * - * @param time is the delay time (unit: OS ticks) for the work item to be submitted to the work queue. + * @param ticks is the delay ticks for the work item to be submitted to the work queue. * * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1) * * @return RT_EOK Success. * -RT_EBUSY This work item is executing. - * -RT_ERROR The time parameter is invalid. + * -RT_ERROR The ticks parameter is invalid. */ -rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time) +rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks) { RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); + RT_ASSERT(ticks < RT_TICK_MAX / 2); - return _workqueue_submit_work(queue, work, time); + return _workqueue_submit_work(queue, work, ticks); } /** @@ -422,24 +447,25 @@ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) } #ifdef RT_USING_SYSTEM_WORKQUEUE -static struct rt_workqueue *sys_workq; + +static struct rt_workqueue *sys_workq; /* system work queue */ /** * @brief Submit a work item to the system work queue with a delay. * * @param work is a pointer to the work item object. * - * @param time is the delay time (unit: OS ticks) for the work item to be submitted to the work queue. + * @param ticks is the delay OS ticks for the work item to be submitted to the work queue. * * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1) * * @return RT_EOK Success. * -RT_EBUSY This work item is executing. - * -RT_ERROR The time parameter is invalid. + * -RT_ERROR The ticks parameter is invalid. */ -rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) +rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks) { - return rt_workqueue_submit_work(sys_workq, work, time); + return rt_workqueue_submit_work(sys_workq, work, ticks); } /** diff --git a/src/timer.c b/src/timer.c index 63cbcf9e07..5d54f85dbd 100644 --- a/src/timer.c +++ b/src/timer.c @@ -263,7 +263,7 @@ void rt_timer_init(rt_timer_t timer, /* parameter check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(timeout != RT_NULL); - RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); + RT_ASSERT(time < RT_TICK_MAX / 2); /* timer object initialization */ rt_object_init(&(timer->parent), RT_Object_Class_Timer, name); @@ -332,7 +332,7 @@ rt_timer_t rt_timer_create(const char *name, /* parameter check */ RT_ASSERT(timeout != RT_NULL); - RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); + RT_ASSERT(time < RT_TICK_MAX / 2); /* allocate a object */ timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name); -- cgit v1.3.1