uCOS-III单任务的创建

实现功能:在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); //启动任务,开调度
	
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值