diff --git a/TODO.md b/TODO.md index be8b3e52bde38ba3c51bf8088b5ab1e9e9fafcf5..d233422a55183f0d1f75c93d27c426fc525e9af4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,14 +1,10 @@ # EventOS开发规划 --------- + 【已完成,尚未全面测试】实现时间事件。 -+ 实现任务删除功能和任务退出功能 ++ 测试任务自动退出功能 + 继续对代码各个子功能进行测试。 + 整理各个函数的命名。 -+ 去掉各个control,参考FreeRTOS拟定API + 仔细考虑重复publish或者send时间事件的操作 -+ 事件队列的阻塞操作 -+ 流事件的阻塞操作 -+ 考虑删除对象管理功能 + 向M0 - M7各个芯片上的移植 + 主要的功能例程 + 简要文档 \ No newline at end of file diff --git a/eventos/eos.c b/eventos/eos.c index 2367943a9488a4a5d3fffd7d516b6fd02a2273d1..5db5461ce7849643421daa07eeed5c563e0a47a6 100644 --- a/eventos/eos.c +++ b/eventos/eos.c @@ -27,8 +27,8 @@ * * Change Logs: * Date Author Notes - * 2021-11-23 DogMing V0.0.2 - * 2021-03-20 DogMing V0.2.0 + * 2021-11-23 DogMing V0.0.2 The hsm framework. + * 2022-03-20 DogMing V0.2.0 Add the complete eventos kernel. */ /* include ------------------------------------------------------------------ */ diff --git a/eventos/eos.h b/eventos/eos.h index 950144df39b6be4243e6b254fb0366a0e472e342..910782a34a0c810620c8aac5f7a8a36699676e2f 100644 --- a/eventos/eos.h +++ b/eventos/eos.h @@ -114,13 +114,6 @@ Task #define EOS_TIMER_FLAG_HARD_TIMER 0x0 /**< hard timer,the timer's callback function will be called in tick isr. */ #define EOS_TIMER_FLAG_SOFT_TIMER 0x4 /**< soft timer,the timer's callback function will be called in timer task. */ -#define EOS_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */ -#define EOS_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */ -#define EOS_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */ -#define EOS_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */ -#define EOS_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/ -#define EOS_TIMER_CTRL_GET_REMAIN_TIME 0x5 /**< get the remaining hang time */ - /* 1 or 3 */ #ifndef EOS_TIMER_SKIP_LIST_MASK #define EOS_TIMER_SKIP_LIST_MASK 0x3 @@ -197,6 +190,7 @@ eos_err_t eos_task_init(eos_task_t *task, eos_u32_t stack_size, eos_u8_t priority); eos_err_t eos_task_detach(eos_task_handle_t task); +eos_err_t eos_task_exit(void); eos_task_handle_t eos_task_self(void); eos_err_t eos_task_startup(eos_task_handle_t task); eos_err_t eos_task_close(eos_task_handle_t task); @@ -204,7 +198,6 @@ eos_err_t eos_task_yield(void); eos_err_t eos_task_delay(eos_u32_t tick); eos_err_t eos_task_delay_until(eos_u32_t *tick, eos_u32_t inc_tick); eos_err_t eos_task_delay_ms(eos_s32_t ms); -eos_err_t eos_task_control(eos_task_handle_t task, int cmd, void *arg); eos_err_t eos_task_suspend(eos_task_handle_t task); eos_err_t eos_task_resume(eos_task_handle_t task); eos_task_state_t eos_task_get_state(eos_task_handle_t task); @@ -233,7 +226,6 @@ eos_u32_t eos_timer_remaining_time(eos_timer_handle_t timer); eos_err_t eos_timer_set_time(eos_timer_handle_t timer, eos_u32_t time); eos_u32_t eos_timer_get_time(eos_timer_handle_t timer); eos_err_t eos_timer_reset(eos_timer_handle_t timer); -eos_err_t eos_timer_control(eos_timer_handle_t timer, int cmd, void *arg); eos_u32_t eos_timer_next_timeout_tick(void); void eos_timer_check(void); diff --git a/eventos/eos_kernel.c b/eventos/eos_kernel.c index 78d6d3be830c7e779307ca3b1107b430c3869be6..770695f8b7e1f043cecffa50e4786d415b74ca9a 100644 --- a/eventos/eos_kernel.c +++ b/eventos/eos_kernel.c @@ -30,7 +30,7 @@ EOS_TAG("EosKernel") enum ek_obj_type { EOS_Object_Null = 0x00, /**< The object is not used. */ - EOS_Object_Thread = 0x01, /**< The object is a task. */ + EOS_Object_Task = 0x01, /**< The object is a task. */ EOS_Object_Semaphore = 0x02, /**< The object is a semaphore. */ EOS_Object_Mutex = 0x03, /**< The object is a mutex. */ EOS_Object_Timer = 0x04, /**< The object is a timer. */ @@ -40,11 +40,19 @@ enum ek_obj_type #define EOS_TASK_STAT_YIELD 0x08 /**< indicate whether remaining_tick has been reloaded since last schedule */ #define EOS_TASK_STAT_YIELD_MASK EOS_TASK_STAT_YIELD +#define EOS_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */ +#define EOS_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */ +#define EOS_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */ +#define EOS_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */ +#define EOS_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/ +#define EOS_TIMER_CTRL_GET_REMAIN_TIME 0x5 /**< get the remaining hang time */ + void eos_schedule(void); void eos_schedule_insert_task(ek_task_t *task); void eos_schedule_remove_task(ek_task_t *task); static eos_u32_t eos_tick_from_millisecond(eos_s32_t ms); +static eos_err_t eos_timer_control(eos_timer_handle_t timer_, int cmd, void *arg); eos_u8_t *eos_hw_stack_init(void *entry, void *parameter, @@ -159,7 +167,7 @@ static struct ek_obj_info _object_container[EosObjInfo_Max] = { /* initialize object container - task */ { - EOS_Object_Thread, + EOS_Object_Task, _OBJ_CONTAINER_LIST_INIT(EosObjInfo_Thread), sizeof(ek_task_t) }, @@ -190,7 +198,7 @@ static struct ek_obj_info _object_container[EosObjInfo_Max] = /** * @brief This function will return the specified type of object information. * @param type is the type of object, which can be - * EOS_Object_Thread/Semaphore/Mutex... etc + * EOS_Object_Task/Semaphore/Mutex... etc * @return the object type information or EOS_NULL */ struct ek_obj_info *eos_object_get_info(enum ek_obj_type type) @@ -803,7 +811,7 @@ static void _task_timeout(void *parameter) /* parameter check */ EOS_ASSERT(task != EOS_NULL); EOS_ASSERT((task->status & EOS_TASK_STAT_MASK) == EOS_TASK_SUSPEND); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); /* disable interrupt */ temp = eos_hw_interrupt_disable(); @@ -912,7 +920,7 @@ eos_err_t ek_task_init(ek_task_handle_t task, EOS_ASSERT(stack_start != EOS_NULL); /* initialize task object */ - eos_object_init((ek_obj_handle_t)task, EOS_Object_Thread); + eos_object_init((ek_obj_handle_t)task, EOS_Object_Task); return _task_init(task, entry, parameter, stack_start, stack_size, priority, @@ -943,7 +951,7 @@ eos_err_t eos_task_startup(eos_task_handle_t task) /* parameter check */ EOS_ASSERT(task_ != EOS_NULL); EOS_ASSERT((task_->status & EOS_TASK_STAT_MASK) == EOS_TASK_INIT); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task_) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task_) == EOS_Object_Task); /* calculate priority attribute */ task_->number_mask = 1L << task_->current_priority; @@ -976,7 +984,7 @@ eos_err_t eos_task_detach(eos_task_handle_t task_) /* parameter check */ EOS_ASSERT(task != EOS_NULL); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); EOS_ASSERT(eos_object_is_systemobject((ek_obj_handle_t)task)); if ((task->status & EOS_TASK_STAT_MASK) == EOS_TASK_CLOSE) @@ -1045,7 +1053,7 @@ eos_err_t eos_task_sleep(eos_u32_t tick) /* set to current task */ task = (ek_task_handle_t)eos_task_self(); EOS_ASSERT(task != EOS_NULL); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); /* disable interrupt */ temp = eos_hw_interrupt_disable(); @@ -1103,7 +1111,7 @@ eos_err_t eos_task_delay_until(eos_u32_t *tick, eos_u32_t inc_tick) /* set to current task */ task = (ek_task_handle_t)eos_task_self(); EOS_ASSERT(task != EOS_NULL); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); /* disable interrupt */ level = eos_hw_interrupt_disable(); @@ -1182,7 +1190,7 @@ eos_err_t eos_task_control(eos_task_handle_t task_, int cmd, void *arg) /* parameter check */ EOS_ASSERT(task != EOS_NULL); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); switch (cmd) { @@ -1262,7 +1270,7 @@ eos_err_t eos_task_suspend(eos_task_handle_t task_) /* parameter check */ EOS_ASSERT(task != EOS_NULL); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); EOS_ASSERT(task == (ek_task_handle_t)eos_task_self()); stat = task->status & EOS_TASK_STAT_MASK; @@ -1301,7 +1309,7 @@ eos_err_t eos_task_resume(eos_task_handle_t task_) /* parameter check */ EOS_ASSERT(task != EOS_NULL); - EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Thread); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); if ((task->status & EOS_TASK_STAT_MASK) != EOS_TASK_SUSPEND) { @@ -2591,7 +2599,7 @@ eos_err_t eos_timer_stop(eos_timer_handle_t timer_) * @param arg the argument * @return the statu of control */ -eos_err_t eos_timer_control(eos_timer_handle_t timer_, int cmd, void *arg) +static eos_err_t eos_timer_control(eos_timer_handle_t timer_, int cmd, void *arg) { register eos_base_t level; ek_timer_handle_t timer = (ek_timer_handle_t)timer_; @@ -2623,14 +2631,16 @@ eos_err_t eos_timer_control(eos_timer_handle_t timer_, int cmd, void *arg) case EOS_TIMER_CTRL_GET_STATE: if (timer->super.flag & EOS_TIMER_FLAG_ACTIVATED) { - /*timer is start and run*/ + /* timer is start and run */ *(eos_u32_t *)arg = EOS_TIMER_FLAG_ACTIVATED; } else { - /*timer is stop*/ + /* timer is stop */ *(eos_u32_t *)arg = EOS_TIMER_FLAG_DEACTIVATED; } + break; + case EOS_TIMER_CTRL_GET_REMAIN_TIME: *(eos_u32_t *)arg = timer->timeout_tick; break; @@ -2643,6 +2653,82 @@ eos_err_t eos_timer_control(eos_timer_handle_t timer_, int cmd, void *arg) return EOS_EOK; } +eos_bool_t eos_timer_active(eos_timer_handle_t timer_) +{ + register eos_base_t level; + ek_timer_handle_t timer = (ek_timer_handle_t)timer_; + eos_bool_t ret = false; + + level = eos_hw_interrupt_disable(); + + if (timer->super.flag & EOS_TIMER_FLAG_ACTIVATED) + { + ret = true; + } + + eos_hw_interrupt_enable(level); + + return ret; +} + +eos_u32_t eos_timer_remaining_time(eos_timer_handle_t timer_) +{ + register eos_base_t level; + ek_timer_handle_t timer = (ek_timer_handle_t)timer_; + + level = eos_hw_interrupt_disable(); + + eos_u32_t remaining_time = timer->timeout_tick; + + eos_hw_interrupt_enable(level); + + return remaining_time; +} + +eos_err_t eos_timer_set_time(eos_timer_handle_t timer_, eos_u32_t time) +{ + EOS_ASSERT(time < (EOS_TICK_MAX / 2)); + + register eos_base_t level; + ek_timer_handle_t timer = (ek_timer_handle_t)timer_; + + level = eos_hw_interrupt_disable(); + + timer->init_tick = time; + + eos_hw_interrupt_enable(level); + + return EOS_EOK; +} + +eos_u32_t eos_timer_get_time(eos_timer_handle_t timer_) +{ + register eos_base_t level; + ek_timer_handle_t timer = (ek_timer_handle_t)timer_; + + level = eos_hw_interrupt_disable(); + + eos_u32_t time = timer->init_tick; + + eos_hw_interrupt_enable(level); + + return time; +} + +eos_err_t eos_timer_reset(eos_timer_handle_t timer_) +{ + register eos_base_t level; + ek_timer_handle_t timer = (ek_timer_handle_t)timer_; + + level = eos_hw_interrupt_disable(); + + timer->timeout_tick = timer->init_tick; + + eos_hw_interrupt_enable(level); + + return EOS_EOK; +} + /** * @brief This function will check timer list, if a timeout event happens, * the corresponding timeout function will be invoked. @@ -2986,3 +3072,67 @@ eos_u8_t eos_task_get_priority(eos_task_handle_t task) { return ((ek_task_handle_t)task)->current_priority; } + +eos_err_t eos_task_set_priority(eos_task_handle_t task_, eos_u8_t priority) +{ + ek_task_handle_t task = (ek_task_handle_t)task_; + register eos_base_t temp; + + /* parameter check */ + EOS_ASSERT(task != EOS_NULL); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); + + /* disable interrupt */ + temp = eos_hw_interrupt_disable(); + + /* for ready task, change queue */ + if ((task->status & EOS_TASK_STAT_MASK) == EOS_TASK_READY) + { + /* remove task from schedule queue first */ + eos_schedule_remove_task(task); + + /* change task priority */ + task->current_priority = priority; + + /* recalculate priority attribute */ + task->number_mask = 1 << task->current_priority; + + /* insert task to schedule queue again */ + eos_schedule_insert_task(task); + } + else + { + task->current_priority = priority; + + /* recalculate priority attribute */ + task->number_mask = 1 << task->current_priority; + } + + /* enable interrupt */ + eos_hw_interrupt_enable(temp); + + return EOS_EOK; +} + +eos_err_t eos_task_close(eos_task_handle_t task_) +{ + ek_task_handle_t task = (ek_task_handle_t)task_; + + /* parameter check */ + EOS_ASSERT(task != EOS_NULL); + EOS_ASSERT(eos_object_get_type((ek_obj_handle_t)task) == EOS_Object_Task); + + eos_err_t eos_err; + + if (eos_object_is_systemobject((ek_obj_handle_t)task) == true) + { + eos_err = eos_task_detach(task_); + } + eos_schedule(); + return eos_err; +} + +eos_err_t eos_task_exit(void) +{ + return EOS_EOK; +} diff --git a/eventos/eos_kernel.h b/eventos/eos_kernel.h index 96ed4271792c4556ef61d24cf94e3063ff303549..c0ba7be2a0c93a9c29acfb363db9e1c71052958c 100644 --- a/eventos/eos_kernel.h +++ b/eventos/eos_kernel.h @@ -71,7 +71,7 @@ typedef struct ek_task /* eos object */ eos_u8_t type; /**< type of object */ eos_u8_t flags; /**< task's flags */ - + ek_list_t list; /**< the object list */ ek_list_t tlist; /**< the task list */