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:
@@ -8,18 +8,31 @@ osThreadDef(task1, osPriorityNormal, 1, TASK1_STK_SIZE);
|
||||
void task2(void *arg);
|
||||
osThreadDef(task2, osPriorityNormal, 1, TASK2_STK_SIZE);
|
||||
|
||||
#define TASK3_STK_SIZE 512
|
||||
void task3(void *arg);
|
||||
|
||||
void task1(void *arg)
|
||||
{
|
||||
int count = 1;
|
||||
osThreadId task_dyn_created;
|
||||
|
||||
osThreadDynamicDef(task3, osPriorityNormal, 1, TASK3_STK_SIZE);
|
||||
task_dyn_created = osThreadCreate(osThread(task3), NULL);
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (1) {
|
||||
printf("###This is task1, %d\r\n", count++);
|
||||
printf("###I am task1\r\n");
|
||||
osDelay(2000);
|
||||
|
||||
if (count++ == 3) {
|
||||
printf("###I am task1, kill the dynamic created task\r\n");
|
||||
osThreadTerminate(task_dyn_created);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void task2(void *arg)
|
||||
{
|
||||
int count = 1;
|
||||
while (1) {
|
||||
#if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0u
|
||||
k_err_t rc;
|
||||
@@ -29,13 +42,22 @@ void task2(void *arg)
|
||||
printf("%d %d\n", rc, depth);
|
||||
#endif
|
||||
|
||||
printf("***This is task2, %d\r\n", count++);
|
||||
printf("***I am task2\r\n");
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void task3(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
printf("$$$I am task3(dynamic created)\r\n");
|
||||
osDelay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
void application_entry(void *arg)
|
||||
{
|
||||
osThreadCreate(osThread(task1), NULL); // Create task1
|
||||
osThreadCreate(osThread(task2), NULL); // Create task2
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user