support dynamic task create in cmsis
1. enable TOS_CFG_TASK_DYNAMIC_CREATE_EN 2. use osThreadDynamicDef to define a dynamic created cmsis task 3. use osThreadCreate/osThreadTerminate to create/destroy this cmsis task 4. see sample hello_world
This commit is contained in:
@@ -176,7 +176,6 @@ __API__ k_err_t tos_task_destroy(k_task_t *task);
|
||||
* @brief Create a task with a dynamic allocated task handler and stack.
|
||||
* create a task with a dynamic allocated task handler and stack.
|
||||
*
|
||||
* @attention a task created by tos_task_create_dyn, should be destroyed by tos_task_destroy_dyn.
|
||||
* @param[out] task dynamic allocated task handler.
|
||||
* @param[in] name name of the task.
|
||||
* @param[in] entry running entry of the task.
|
||||
@@ -199,20 +198,6 @@ __API__ k_err_t tos_task_create_dyn(k_task_t **task,
|
||||
size_t stk_size,
|
||||
k_timeslice_t timeslice);
|
||||
|
||||
/**
|
||||
* @brief Destroy a dynamic created task.
|
||||
* delete a dynamic created task.
|
||||
*
|
||||
* @attention the API to destroy a dynamic created task.
|
||||
*
|
||||
* @param[in] task pointer to the handler of the task to be deleted.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_TASK_DESTROY_IDLE attempt to destroy idle task.
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_task_destroy_dyn(k_task_t *task);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@@ -184,7 +184,7 @@ __STATIC__ k_err_t task_do_destroy(k_task_t *task)
|
||||
return K_ERR_NONE;
|
||||
}
|
||||
|
||||
__API__ k_err_t tos_task_destroy(k_task_t *task)
|
||||
__STATIC__ k_err_t task_destroy_static(k_task_t *task)
|
||||
{
|
||||
TOS_IN_IRQ_CHECK();
|
||||
|
||||
@@ -198,7 +198,7 @@ __API__ k_err_t tos_task_destroy(k_task_t *task)
|
||||
return K_ERR_SCHED_LOCKED;
|
||||
}
|
||||
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
|
||||
if (!knl_object_alloc_is_static(&task->knl_obj)) {
|
||||
return K_ERR_OBJ_INVALID_ALLOC_TYPE;
|
||||
}
|
||||
@@ -284,26 +284,10 @@ __API__ k_err_t tos_task_create_dyn(k_task_t **task,
|
||||
return K_ERR_NONE;
|
||||
}
|
||||
|
||||
__API__ k_err_t tos_task_destroy_dyn(k_task_t *task)
|
||||
__STATIC__ k_err_t task_destroy_dyn(k_task_t *task)
|
||||
{
|
||||
k_err_t err;
|
||||
|
||||
TOS_IN_IRQ_CHECK();
|
||||
|
||||
if (unlikely(!task)) {
|
||||
task = k_curr_task;
|
||||
}
|
||||
|
||||
TOS_OBJ_VERIFY(task, KNL_OBJ_TYPE_TASK);
|
||||
|
||||
if (knl_is_self(task) && knl_is_sched_locked()) {
|
||||
return K_ERR_SCHED_LOCKED;
|
||||
}
|
||||
|
||||
if (!knl_object_alloc_is_dynamic(&task->knl_obj)) {
|
||||
return K_ERR_OBJ_INVALID_ALLOC_TYPE;
|
||||
}
|
||||
|
||||
tos_knl_sched_lock();
|
||||
|
||||
err = task_do_destroy(task);
|
||||
@@ -327,6 +311,29 @@ __API__ k_err_t tos_task_destroy_dyn(k_task_t *task)
|
||||
|
||||
#endif
|
||||
|
||||
__API__ k_err_t tos_task_destroy(k_task_t *task)
|
||||
{
|
||||
TOS_IN_IRQ_CHECK();
|
||||
|
||||
if (unlikely(!task)) {
|
||||
task = k_curr_task;
|
||||
}
|
||||
|
||||
TOS_OBJ_VERIFY(task, KNL_OBJ_TYPE_TASK);
|
||||
|
||||
if (knl_is_self(task) && knl_is_sched_locked()) {
|
||||
return K_ERR_SCHED_LOCKED;
|
||||
}
|
||||
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
|
||||
if (knl_object_alloc_is_dynamic(&task->knl_obj)) {
|
||||
return task_destroy_dyn(task);
|
||||
}
|
||||
#endif
|
||||
|
||||
return task_destroy_static(task);
|
||||
}
|
||||
|
||||
__API__ void tos_task_yield(void)
|
||||
{
|
||||
TOS_CPU_CPSR_ALLOC();
|
||||
|
Reference in New Issue
Block a user