高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-7-15
|
请教下 为何UCOSIII调试时一直运行空任务? 程序下载到开发板没有任何动静,下面是程序,很简单,就是让两个LED反转
#include <includes.h>
#define START_TASK_PRIO 3u
#define START_STK_SIZE 128u
OS_TCB StarTaskTCB;
CPU_STK START_TASK_STK[START_STK_SIZE];
static void start_task(void * p_arg);
#define TASK1_TASK_PRIO 4u
#define TASK1_STK_SIZE 512u
OS_TCB Task1_TaskTCB;
CPU_STK TASK1_TASK_STK[TASK1_STK_SIZE];
static void task1_task(void* p_arg);
#define TASK2_TASK_PRIO 5u
#define TASK2_STK_SIZE 512
OS_TCB Task2_TaskTCB;
CPU_STK TASK2_TASK_STK[TASK2_STK_SIZE];
static void task2_task(void* p_arg);
int main (void)
{
OS_ERR err;
CPU_SR_ALLOC();
LED_Init();
USART_Config();
OSInit(&err); //初始化UCOSIII /* Init uC/OS-III. */
OS_CRITICAL_ENTER(); //进入临界区
OSTaskCreate((OS_TCB *)&StarTaskTCB, /* Create the start task */
(CPU_CHAR *)"Task Start",
(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 ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OS_CRITICAL_EXIT(); //退出临界区
OSStart(&err); //开启UCOSIII
while(1);
}
//开始任务任务函数
static void start_task(void *p_arg)
{
OS_ERR err;
CPU_SR_ALLOC();
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
OS_CRITICAL_ENTER(); //进入临界区
//创建TASK1任务
OSTaskCreate((OS_TCB * )&Task1_TaskTCB,
(CPU_CHAR * )"Task1 task",
(OS_TASK_PTR )task1_task,
(void * )0,
(OS_PRIO )TASK1_TASK_PRIO,
(CPU_STK * )&TASK1_TASK_STK[0],
(CPU_STK_SIZE)TASK1_STK_SIZE/10,
(CPU_STK_SIZE)TASK1_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);
//创建TASK2任务
OSTaskCreate((OS_TCB * )&Task2_TaskTCB,
(CPU_CHAR * )"task2 task",
(OS_TASK_PTR )task2_task,
(void * )0,
(OS_PRIO )TASK2_TASK_PRIO,
(CPU_STK * )&TASK2_TASK_STK[0],
(CPU_STK_SIZE)TASK2_STK_SIZE/10,
(CPU_STK_SIZE)TASK2_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(); //退出临界区
OSTaskDel((OS_TCB*)0,&err); //删除start_task任务自身
}
static void task1_task(void* p_arg)
{
OS_ERR err;
while(1)
{
macLED1_TOGGLE();
OSTimeDly ( 1000, OS_OPT_TIME_DLY, & err );
}
}
static void task2_task(void* p_arg)
{
OS_ERR err;
while(1)
{
macLED2_TOGGLE();
OSTimeDly ( 1000, OS_OPT_TIME_DLY, & err );
}
}
|
|