/* * File: main.c * * uC/OS Real-time multitasking kernel for the ARM processor. * * This program is an example of using semaphore to * implement task rendevous. * * Created by Marco Graziano (marcog@crl.com). * */
#include "includes.h" /* uC/OS interface */
/* allocate memory for tasks' stacks */ #ifdef SEMIHOSTED #define STACKSIZE (SEMIHOSTED_STACK_NEEDS+64) #else #define STACKSIZE 128 #endif unsigned int Stack1[STACKSIZE]; unsigned int Stack2[STACKSIZE]; unsigned int Stack3[STACKSIZE];
/* semaphores event control blocks */ //OS_EVENT *Sem1; //OS_EVENT *Sem2; //OS_EVENT *Sem3;
OS_EVENT *KeyPress; void *KeyMsg[10]; /* * Task running at the highest priority. */
void Task1(void *i) { unsigned char key[5]; unsigned char i1,temp; unsigned char NewKey,OldKey; ARMTargetStart(); for (;;) { NewKey=rPDATG&0xf0; if(NewKey!=OldKey) { OldKey=NewKey; if((NewKey&0x10)==0) temp='a'; else if((NewKey&0x20)==0) temp='b'; else if((NewKey&0x40)==0) temp='c'; else if((NewKey&0x80)==0) temp='d'; else temp=0; if(temp!=0) { for(i1=0;i1<5;i1++) if(key[i1]==0) break; key[i1]=temp; OSQPost(KeyPress,&(key[i1])); } } OSTimeDly(20); //20ms } }
void Task2(void *i) { unsigned char key[5]; unsigned char i1; unsigned char NewKey; for (;;) { NewKey=Uart_GetKey(); if(NewKey!=0) { for(i1=0;i1<5;i1++) if(key[i1]==0) break; key[i1]=NewKey; OSQPost(KeyPress,&(key[i1])); } OSTimeDly(10); } }
void Task3(void *i) { unsigned char *ip; INT8U err; for (;;) { ip=OSQPend(KeyPress,0,&err); if(*ip=='a') Uart_Printf("\nYou Press a!"); else if(*ip=='b') Uart_Printf("\nYou Press b!"); else if(*ip=='c') Uart_Printf("\nYou Press c!"); else if(*ip=='d') Uart_Printf("\nYou Press d!"); *ip=0; } }
/* * Main function. */ void Main(void) { char Id1 = '1'; char Id2 = '2'; char Id3 = '3'; Port_Init(); Uart_Init(0,57600); Delay(1000); Uart_Select(0); //Select UART0
Uart_Printf("Uc-OS ii will run at once!");
/* 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], 1); OSTaskCreate(Task2, (void *)&Id2, (void *)&Stack2[STACKSIZE - 1], 2); OSTaskCreate(Task3, (void *)&Id3, (void *)&Stack3[STACKSIZE - 1], 3); /* Start the (uHAL based ARM system) system running */ //ARMTargetStart(); KeyPress=OSQCreate(KeyMsg,10); //创建一个按键的消息队列
/* start the game */ OSStart();
/* never reached */ } /* main */
|