版权声明:本文为博主原创文章,遵循 CC 4.0 BY 版权协议,转载请附上原文出处链接和本声明。
实现功能:在uCOS-III创建任务点亮LED1
下面是App.c中的代码,需要配合各个头文件中的代码来执行
#include "os.h" //OS_TCB
#include "app_cfg.h" // APP_TASK_START_STK_SIZE
#include "bsp.h"
#include "cpu.h" //CPU_STK
static OS_TCB AppTaskStartTCB; //定义任务控制块
static CPU_STK AppTaskStartSTK[APP_TASK_START_STK_SIZE];//定义任务堆栈
//创建函数主体
static void LED_Task(void * parm)
{
OS_ERR err;
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
(void)parm;
/* Initialize BSP functions */
BSP_Init();
CPU_Init();
/* Determine SysTick reference freq. */
cpu_clk_freq = BSP_CPU_ClkFreq();
/* Determine nbr SysTick increments */
cnts = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz;
/* Init uC/OS periodic time src (SysTick). */
OS_CPU_SysTickInit(cnts);
/* Initialize Memory Management Module */
Mem_Init();
#if OS_CFG_STAT_TASK_EN > 0u
/* Compute CPU capacity with no task running */
OSStatTaskCPUUsageInit(&err);
#endif
CPU_IntDisMeasMaxCurReset();
while(1)
{
LED1_ON;//点亮LED
OSTimeDly(500,OS_OPT_TIME_DLY,&err);//延时500毫秒
LED1_OFF;//关闭LED
OSTimeDly(500,OS_OPT_TIME_DLY,&err);
}
}
int main(void)
{
OS_ERR err;
BSP_Init ();
OSInit(&err); //初始化
//创建任务
OSTaskCreate (
&AppTaskStartTCB,
"LED_Task",
LED_Task,
0,
1,
&AppTaskStartSTK[0],
APP_TASK_START_STK_SIZE/10,
APP_TASK_START_STK_SIZE,
5,
0,
0,
OS_OPT_TASK_STK_CHK ,
&err);
OSStart(&err); //启动任务,开调度
}