初级会员
- 积分
- 143
- 金钱
- 143
- 注册时间
- 2016-11-15
- 在线时间
- 16 小时
|
使用任务删除函数时,当为OSTaskDel((OS_TCB *)&Led0TaskTCB,&err);时,会删除Led0TaskTCB;而把&Led0TaskTCB改为0删除任务本身时,却发现该任务还在运行。很好奇这是为什么?
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "includes.h"
#include "os_app_hooks.h"
#define START_TASK_PRIO 3
#define START_STK_SIZE 512
OS_TCB StartTaskTCB;
CPU_STK START_TASK_STK[START_STK_SIZE];
void start_task(void *p_arg);
#define LED0_TASK_PRIO 4
#define LED0_STK_SIZE 128
OS_TCB Led0TaskTCB;
CPU_STK LED0_TASK_STK[LED0_STK_SIZE];
void led0_task(void *p_arg);
#define LED1_TASK_PRIO 5
#define LED1_STK_SIZE 128
OS_TCB Led1TaskTCB;
CPU_STK LED1_TASK_STK[LED1_STK_SIZE];
void led1_task(void *p_arg);
#define BEEP1_TASK_PRIO 6
#define BEEP1_STK_SIZE 128
OS_TCB Beep1TaskTCB;
__align(8) CPU_STK BEEP1_TASK_STK[BEEP1_STK_SIZE];
void Beep1_task(void *p_arg);
#define BEEP2_TASK_PRIO 7
#define BEEP2_STK_SIZE 128
OS_TCB Beep2TaskTCB;
__align(8) CPU_STK BEEP2_TASK_STK[BEEP2_STK_SIZE];
void Beep2_task(void *p_arg);
int main(void)
{
OS_ERR err;
CPU_SR_ALLOC();
delay_init(168);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
LED_Init();
OSInit(&err);
OS_CRITICAL_ENTER();
OSTaskCreate((OS_TCB * )&StartTaskTCB,
(CPU_CHAR * )"start task",
(OS_TASK_PTR )start_task,
(void * )0,
(OS_PRIO )START_TASK_PRIO,
(CPU_STK * )&START_TASK_STK[0],
(CPU_STK_SIZE)START_STK_SIZE/10,
(CPU_STK_SIZE)START_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
OS_CRITICAL_EXIT();
OSStart(&err);
while(1);
}
void start_task(void *p_arg)
{
OS_ERR err;
CPU_SR_ALLOC();
p_arg = p_arg;
CPU_Init();
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskCPUUsageInit(&err);
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
#if OS_CFG_SCHED_ROUND_ROBIN_EN
OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
#endif
OSTaskCreate((OS_TCB * )&Led0TaskTCB,
(CPU_CHAR * )"led0 task",
(OS_TASK_PTR )led0_task,
(void * )0,
(OS_PRIO )LED0_TASK_PRIO,
(CPU_STK * )&LED0_TASK_STK[0],
(CPU_STK_SIZE)LED0_STK_SIZE/10,
(CPU_STK_SIZE)LED0_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
//′′½¨LED1èÎÎñ
OSTaskCreate((OS_TCB * )&Led1TaskTCB,
(CPU_CHAR * )"led1 task",
(OS_TASK_PTR )led1_task,
(void * )0,
(OS_PRIO )LED1_TASK_PRIO,
(CPU_STK * )&LED1_TASK_STK[0],
(CPU_STK_SIZE)LED1_STK_SIZE/10,
(CPU_STK_SIZE)LED1_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
//′′½¨·äÃùÆ÷1èÎÎñ
OSTaskCreate((OS_TCB * )&Beep1TaskTCB,
(CPU_CHAR * )"Beep1_task",
(OS_TASK_PTR )Beep1_task,
(void * )0,
(OS_PRIO )BEEP1_TASK_PRIO,
(CPU_STK * )&BEEP1_TASK_STK[0],
(CPU_STK_SIZE)BEEP1_STK_SIZE/10,
(CPU_STK_SIZE)BEEP1_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
//′′½¨·äÃùÆ÷2èÎÎñ
OSTaskCreate((OS_TCB * )&Beep2TaskTCB,
(CPU_CHAR * )"Beep2_task",
(OS_TASK_PTR )Beep2_task,
(void * )0,
(OS_PRIO )BEEP2_TASK_PRIO,
(CPU_STK * )&BEEP2_TASK_STK[0],
(CPU_STK_SIZE)BEEP2_STK_SIZE/10,
(CPU_STK_SIZE)BEEP2_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
OS_TaskSuspend((OS_TCB*)&StartTaskTCB,&err); //1òÆe¿aê¼èÎÎñ
OS_CRITICAL_EXIT(); //½øèëáù½çÇø
}
//led0èÎÎñoˉêy
void led0_task(void *p_arg)
{
OS_ERR err;
p_arg = p_arg;
while(1)
{
LED0=!LED0;
OSTimeDlyHMSM(0,0,0,200,OS_OPT_TIME_HMSM_STRICT,&err); //Ñóê±200ms
}
}
//led1èÎÎñoˉêy
void led1_task(void *p_arg)
{
OS_ERR err;
p_arg = p_arg;
while(1)
{
LED1=!LED1;
OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_HMSM_STRICT,&err); //Ñóê±500ms
}
}
void Beep1_task(void *p_arg)
{
OS_ERR err;
p_arg = p_arg;
while(1)
{
BEEP1=!BEEP1;
OSTimeDlyHMSM(0,0,0,300,OS_OPT_TIME_HMSM_STRICT,&err); //Ñóê±100ms
}
}
void Beep2_task(void *p_arg)
{
int t=50;
OS_ERR err;
p_arg = p_arg;
while(1)
{
BEEP2=!BEEP2;
OSTimeDlyHMSM(0,0,0,t,OS_OPT_TIME_HMSM_STRICT,&err); //Ñóê±tms
if (t==100)
{
t=50;
OSTaskDel((OS_TCB *)&Led0TaskTCB,&err);
}
else
t++;
}
}
|
|