#include "config.h" #include "stdlib.h"
#define TaskStkLengh 512 //Define the Task0 stack length 定义用户任务0的堆栈长度
OS_STK Main_Stack[TaskStkLengh]; //主任务堆栈
//任务1 OS_STK Task1_Stack[TaskStkLengh];//任务1堆栈
//任务2 OS_STK Task2_Stack[TaskStkLengh];//任务2堆栈
///任务3 OS_STK Task3_Stack[TaskStkLengh];//任务3堆栈
#define LED2 (1 << 19) // P1.18控制LED2 #define LED3 (1 << 20) // P1.18控制LED3 #define LED4 (1 << 21) // P1.18控制LED4
//任务1函数定义 void Task1_Task(void *pdata) { uint32 i; pdata=pdata; while (1) { i++; OS_ENTER_CRITICAL(); IO1CLR = LED2; //点亮LED2 OSTimeDly(OS_TICKS_PER_SEC / 2); OS_EXIT_CRITICAL(); OSTimeDly(1000); //延时挂起 } }
//任务2函数定义 void Task2_Task(void *pdata) { uint32 i; pdata=pdata; while (1) { i++; OS_ENTER_CRITICAL(); IO1CLR = LED3; //点亮LED3 OSTimeDly(OS_TICKS_PER_SEC / 2); OS_EXIT_CRITICAL(); OSTimeDly(1000); //延时挂起 } }
//任务3函数定义 void Task3_Task(void *pdata) { uint32 i; pdata=pdata; while (1) { i++; OS_ENTER_CRITICAL(); IO1CLR = LED4; //点亮LED4 OSTimeDly(OS_TICKS_PER_SEC / 2); OS_EXIT_CRITICAL(); OSTimeDly(1000); //延时挂起 } }
//主任务的定义 void Main_Task(void *pdata) { pdata=pdata; TargetInit (); //在此处开放定时中断 IO1SET = 0xffffffff; OSTimeDly(100); IO1CLR = 0x00040000; OSTimeDly(OS_TICKS_PER_SEC/2); OSTaskCreate(Task1_Task,(void *)0,&Task1_Stack[TaskStkLengh-1],12); OSTaskCreate(Task2_Task,(void *)0,&Task2_Stack[TaskStkLengh-1],14); OSTaskCreate(Task3_Task,(void *)0,&Task3_Stack[TaskStkLengh-1],16); while(1) { OSTimeDly(1000); } }
//主函数开始 int main() { //这里写对目标初始化函数 OSInit(); //千万不要在此处开放定时中断,即调用TargetInit(); PINSEL1=0X00000000; //引脚设为GPIO功能 IO1DIR =0XFFFFFFFF; //引脚设为输出模式 IO1SET =0Xffffffff; //引脚全部设为灭状态 OSTaskCreate(Main_Task,(void *)0,&Main_Stack[TaskStkLengh-1],10); OSStart(); //此函数永远不会返回 return 0; }