高级会员
- 积分
- 591
- 金钱
- 591
- 注册时间
- 2013-3-1
- 在线时间
- 153 小时
|
楼主 |
发表于 2017-7-13 21:24:07
|
显示全部楼层
主函数内容如下
[mw_shl_code=c,true]#include <includes.h>
#define red LPC_GPIO0->FIOPIN^=(1<<0)
#define blue LPC_GPIO1->FIOPIN^=(1<<19)
static OS_TCB App_TaskStartTCB;
static CPU_STK_SIZE App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];
static void App_TaskStart (void *p_arg);
//任务优先级
#define TASK1_TASK_PRIO 4u
//任务堆栈大小
#define TASK1_STK_SIZE 128
//任务控制块
OS_TCB Task1_TaskTCB;
//任务堆栈
CPU_STK TASK1_TASK_STK[TASK1_STK_SIZE];
void task1_task(void *p_arg);
//任务优先级
#define TASK2_TASK_PRIO 5
//任务堆栈大小
#define TASK2_STK_SIZE 128
//任务控制块
OS_TCB Task2_TaskTCB;
//任务堆栈
CPU_STK TASK2_TASK_STK[TASK2_STK_SIZE];
//任务函数
void task2_task(void *p_arg);
int main (void)
{
OS_ERR err;
CPU_Init();
BSP_Init(); /* Initialize BSP functions */
Mem_Init();
OSInit(&err); /* Initialize "uC/OS-III, The Real-Time Kernel" */
OSTaskCreate((OS_TCB *)&App_TaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) App_TaskStart,
(void *) 0,
(OS_PRIO ) APP_CFG_TASK_START_PRIO,
(CPU_STK *)&App_TaskStartStk[0],
(CPU_STK )(APP_CFG_TASK_START_STK_SIZE / 10u),
(CPU_STK_SIZE) APP_CFG_TASK_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);
#if (OS_TASK_NAME_EN > 0u)
OSTaskNameSet(APP_CFG_TASK_START_PRIO, "Start", &err);
#endif
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while(DEF_ON){ /* Should Never Get Here */
};
}
/*
*********************************************************************************************************
* App_TaskStart()
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Argument(s) : p_arg is the argument passed to 'App_TaskStart()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Caller(s) : This is a task.
*
* Notes : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void App_TaskStart (void *p_arg)
{
OS_ERR os_err;
(void)p_arg; /* See Note #1 */
BSP_Start(); /* Start BSP and tick initialization */
//创建串口消息队列
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity */
#endif
//OS_TickTask();
// 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 *)&os_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 * )&os_err);
// OS_CRITICAL_EXIT(); //退出临界区
OSTaskDel((OS_TCB*)0,&os_err); //删除start_task任务自身""
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
}
}
//task1任务函数
void task1_task(void *p_arg)
{
CPU_INT08U task1_num=0;
OS_ERR os_err;
CPU_SR_ALLOC();
p_arg = p_arg;
OS_CRITICAL_ENTER();
OS_CRITICAL_EXIT();
while(1)
{
task1_num++; //任务执1行次数加1 注意task1_num1加到255的时候会清零!!
// if(task1_num==6)
// {
// OSTaskDel((OS_TCB*)&Task2_TaskTCB,&os_err); //任务1执行5此后删除掉任务2
// }
red;
_DBG_("\nred");
//OSTimeDlyHMSM可以发起任务调度
OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_HMSM_STRICT,&os_err); //延时1s
}
}
//task2任务函数
void task2_task(void *p_arg)
{
OS_ERR os_err;
CPU_SR_ALLOC();
p_arg = p_arg;
OS_CRITICAL_EXIT();
while(1)
{
blue ;
_DBG_("\nblue\r");
OSTimeDlyHMSM(0,0,2,0,OS_OPT_TIME_HMSM_STRICT,&os_err); //延时1s
}
}
[/mw_shl_code]
串口调试只显示任务1和任务2输出的内容,并不进中断,不输出的内容
|
|