uCOS-II任务建立示例

 

#include "config.h"
#include "stdlib.h"


#define          LED1        (1<<18)                    // P1.18控制LED1
#define          LED2        (1<<19)                    // P1.19控制LED2

#define TaskStkLengh 64    // 定义用户任务的堆栈长度

OS_STK TaskStartStk[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 ();
return 0;               
}

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);   
}
}

你可能感兴趣的:(IO,OS,include,任务)