标题:
uCOS-II任务建立示例
[打印本页]
作者:
yuyang911220
时间:
2014-11-26 09:37
标题:
uCOS-II任务建立示例
#include "config.h"
#include "stdlib.h"
#define LED1 (1<<18) // P1.18控制LED1
#define LED2 (1<<19) // P1.19控制LED2
#define TaskStkLengh64 //定义用户任务的堆栈长度
OS_STKTaskStartStk[TaskStkLengh]; //定义用户任务0的堆栈
OS_STK TaskLED1Stk[TaskStkLengh];
OS_STK TaskLED2Stk[TaskStkLengh];
void TaskStart(void*pdata); //Task0 任务0
void TaskLED1(void*pdata);
void TaskLED2(void*pdata);
int main (void)
{
OSInit();
OSTaskCreate (TaskStart,(void *)0,&TaskStartStk[TaskStkLengh - 1],0);
OSStart ();
return0;
}
void TaskStart(void *pdata)
{
pdata = pdata;
TargetInit ();
OSTaskCreate(TaskLED1,(void *)0,&TaskLED1Stk[TaskStkLengh - 1], 1);
OSTaskCreate(TaskLED2,(void *)0,&TaskLED2Stk[TaskStkLengh - 1], 2);
while(1)
{
OSTimeDlyHMSM(0,0,10,0);
}
}
void TaskLED1(void *pdata)
{
pdata = pdata;
PINSEL2 = PINSEL2 &(~0x08); // P1[25:16]选择GPIO
IO1DIR |=LED1; // 设置LED1控制口输出
IO1SET =LED1;
while(1)
{
IO1CLR = LED1;
OSTimeDly(OS_TICKS_PER_SEC /2);
IO1SET = LED1;
OSTimeDly(OS_TICKS_PER_SEC / 2);
}
}
void TaskLED2(void *pdata)
{
pdata = pdata;
PINSEL2 = PINSEL2 &(~0x08); // P1[25:16]选择GPIO
IO1DIR |=LED2; // 设置LED1控制口输出
IO1SET =LED2;
while(1)
{
IO1CLR = LED2;
OSTimeDly(OS_TICKS_PER_SEC);
IO1SET = LED2;
OSTimeDly(OS_TICKS_PER_SEC);
}
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0