昨天移植完了ucos-v2.85到2407平台上,现在写了一个两个任务的应用程序,希望对和我一样的初学者有帮助。代码如下:
#include "lf2407.h" #include "ucos_ii.h"
OS_STK Main_TaskStk[64]; OS_STK Sub_TaskStk[64];
void Main_Task(void *data); void Sub_Task(void *data);
void InitCPU(void) { SCSR1 = 0x00fd; SCSR2 = (SCSR2|0x000b) & 0x000f; WDCR = 0x00e8; WSGR = 0x0040; MCRA = 0x0FFF; PBDATDIR = PBDATDIR|0x0F000; T2CON = 0x0000; GPTCONA = 0x0000; T2CNT = 0x0000; T2PR = 50000; T2CON = 0xd340; IMR = 0x0000; IFR = 0x003f; IMR = 0x0004; EVAIFRA = 0xFFFF; EVAIFRB = 0xFFFF; EVAIFRC = 0xFFFF; EVAIMRA = 0x0000; EVAIMRB = 0x0000; EVAIMRC = 0x0000;
EVBIFRA = 0xFFFF; EVBIFRB = 0xFFFF; EVBIFRC = 0xFFFF; EVBIMRA = 0x0000; EVBIMRB = 0x0000; EVBIMRC = 0x0000;
asm(" CLRC INTM"); }
int main(void) { InitCPU(); OSInit(); OSTaskCreate(Main_Task, (void *)0, &Main_TaskStk[63], 0); OSStart(); return 0; }
void Main_Task(void *p_arg) { EnableTick(); OSTaskCreate(Sub_Task, (void *)0, &Sub_TaskStk[63],10); while(1) { PBDATDIR |= 0x0010; OSTimeDlyHMSM(0, 0, 0, 500); PBDATDIR &= 0x0ffef; OSTimeDlyHMSM(0, 0, 0, 500); } }
void Sub_Task(void *p_arg) { while(1) { PBDATDIR |= 0x0020; OSTimeDlyHMSM(0, 0, 2, 0); PBDATDIR &= 0x0ffdf; OSTimeDlyHMSM(0, 0, 2, 0); } }
|
两个任务分别控制一个led,位于PB4和PB5. PB4上的led每秒闪一次,PB5上的led每四秒闪一次。代码比较简单,就不多说了。
如果希望移植ucos-v2.85,可以参考:
http://blog.chinaunix.net/u1/57747/showart_1072239.html
阅读(4082) | 评论(0) | 转发(0) |