#include "includes.h" /* allocate memory for tasks' stacks */ #ifdef SEMIHOSTED #define STACKSIZE (SEMIHOSTED_STACK_NEEDS+64) #else #define STACKSIZE 32 #endif #define LEDSET (0xFF<<18) #define LED0 0x01<<18 #define LED1 0x01<<19 #define LED2 0x01<<20 unsigned int Stack1[STACKSIZE]; unsigned int Stack2[STACKSIZE]; unsigned int Stack3[STACKSIZE]; void StartTimer(void) { uHALr_InitTimers(); } /* semaphores event control blocks */ OS_EVENT *Sem1; OS_EVENT *Sem2; OS_EVENT *Sem3; /* * Task running at the highest priority. */ void PortInit(void) { PINSEL2=PINSEL2&(~0x08); IODIR1=LEDSET; IOSET1=LEDSET; } void LED(u32 port,u32 status) { if (port==0) { if (status==0) IOSET1=LED0; else IOCLR1=LED0; } else if (port==1) { if (status==0) IOSET1=LED1; else IOCLR1=LED1; } else { if (status==0) IOSET1=LED2; else IOCLR1=LED2; } } void Task1(void *i) { INT8U Reply, n; // static INT8U first=FALSE; StartTimer(); for (;;) { /* wait for the semaphore */ OSSemPend(Sem1, 0, &Reply); uHALr_printf("Task1 running\r\n"); /* wait a short while */ for (n=0;n<1;n++) { LED(0,1); OSTimeDly(50); LED(0,0); OSTimeDly(50); } uHALr_printf("Task1 exit\r\n"); /* signal the semaphore */ OSSemPost(Sem1); /* if(first==FALSE) { first=TRUE; OSSemPost(Sem2); }*/ } } void Task2(void *i) { INT8U Reply, n; for (;;) { /* wait for the semaphore */ OSSemPend(Sem2, 0, &Reply); uHALr_printf("Task2 running\r\n"); /* wait a short while */ for (n=0;n<1;n++) { LED(1,1); OSTimeDly(40); LED(1,0); OSTimeDly(40); } uHALr_printf("Task2 exit\r\n"); OSSemPost(Sem2); } } void Task3(void *i) { INT8U Reply, n; for (;;) { /* wait for the semaphore */ OSSemPend(Sem3, 0, &Reply); uHALr_printf("Task3 running\r\n"); /* wait a short while */ for (n=0;n<1;n++) { LED(2,1); OSTimeDly(36); LED(2,0); OSTimeDly(36); } uHALr_printf("Task3 exit\r\n"); OSSemPost(Sem3); } } int main(void) { char Id1 = '1'; char Id2 = '2'; char Id3 = '3'; // char Id4 = '4'; //Port_Init(); // beep(1); uart_init(); PortInit(); // Delay(1000); // Uart_Select(0); //Select UART0 uHALr_printf("\r\nUc-OS ii will run at once!\r\n"); /* do target (uHAL based ARM system) initialisation */ ARMTargetInit(); /* needed by uC/OS */ OSInit(); // OSTimeSet(0); /* * create the semaphores */ Sem1 = OSSemCreate(1); Sem2 = OSSemCreate(1); Sem3 = OSSemCreate(1); /* * create the tasks in uC/OS and assign decreasing * priority to them */ OSTaskCreate(Task1, (void *)&Id1, (void *)&Stack1[STACKSIZE - 1], 2); OSTaskCreate(Task2, (void *)&Id2, (void *)&Stack2[STACKSIZE - 1], 3); OSTaskCreate(Task3, (void *)&Id3, (void *)&Stack3[STACKSIZE - 1], 4); // OSTaskCreate(Task4, (void *)&Id4, (void *)&Stack4[STACKSIZE - 1], 14); // OSTaskCreate(T_LwIPEntry, (void*)NULL, (void*)&T_LWIPENTRY_STK[T_LWIPENTRY_STKSIZE-1], T_LWIPENTRY_PRIOR); /* Start the (uHAL based ARM system) system running */ ARMTargetStart(); /* start the game */ OSStart(); /* ARMEnableInt(); uHALr_InitTimers(); while(1);*/ /* never reached */ return 0; } /* main */