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:
@@ -75,9 +75,20 @@ osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *argument)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
|
||||
if (!thread_def->stackbase && !thread_def->task) {
|
||||
k_task_t *task;
|
||||
err = tos_task_create_dyn(&task, thread_def->name, (k_task_entry_t)thread_def->pthread,
|
||||
argument, priority_cmsis2knl(thread_def->tpriority),
|
||||
thread_def->stacksize, thread_def->timeslice);
|
||||
return err == K_ERR_NONE ? task : NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
err = tos_task_create((k_task_t *)thread_def->task, thread_def->name, (k_task_entry_t)thread_def->pthread,
|
||||
argument, priority_cmsis2knl(thread_def->tpriority), thread_def->stackbase,
|
||||
thread_def->stacksize, thread_def->timeslice);
|
||||
|
||||
return err == K_ERR_NONE ? thread_def->task : NULL;
|
||||
}
|
||||
|
||||
|
@@ -398,12 +398,21 @@ uint32_t osKernelSysTick(void);
|
||||
#define osThreadDef(name, priority, instances, stacksz) \
|
||||
extern const osThreadDef_t os_thread_def_##name
|
||||
#else // define the object
|
||||
|
||||
#define osThreadDef(name, priority, instances, stacksz) \
|
||||
k_task_t task_handler_##name; \
|
||||
k_stack_t task_stack_##name[(stacksz)]; \
|
||||
const osThreadDef_t os_thread_def_##name = \
|
||||
{ #name, (os_pthread)(name), (osPriority)(priority), (instances), \
|
||||
(&((task_stack_##name)[0])), (stacksz), ((k_timeslice_t)0u), (&(task_handler_##name)) }
|
||||
|
||||
#if (TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u)
|
||||
#define osThreadDynamicDef(name, priority, instances, stacksz) \
|
||||
const osThreadDef_t os_thread_def_##name = \
|
||||
{ #name, (os_pthread)(name), (osPriority)(priority), (instances), \
|
||||
(K_NULL), (stacksz), ((k_timeslice_t)0u), (K_NULL) }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/// Access a Thread definition.
|
||||
|
Reference in New Issue
Block a user