#define Task2_Prio 15
OS_STK task3_Stack[STACKSIZE]={0, }; //test_Test_Task堆栈 void Task3(void *Id); //test_Test_Task #define Task3_Prio 17
OS_STK task4_Stack[STACKSIZE]={0, }; //test_Test_Task堆栈 void Task4(void *Id); //test_Test_Task #define Task4_Prio 11
/**************已经定义的OS任务************* #define SYS_Task_Prio
1 9
#define Touch_Screen_Task_Prio
#define Main_Task_Prio 12 #define Key_Scan_Task_Prio 58 #define Lcd_Fresh_prio 59 #define Led_Flash_Prio 60
***************************************///////// #define rUTRSTAT0 (*(volatile unsigned *)0x50000010) #define RdURXH0() (*(volatile unsigned char *)0x50000024) #define WrUTXH0(ch) (*(volatile char)(ch)
#define RdURXH0() (*(volatile unsigned char *)0x50000024) #define TRUE 1 #define FALSE 0
extern U32 LCDBufferII2[LCDHEIGHT][LCDWIDTH]; BOOLEAN ac_key; char *c,err=0;
///*****************事件定义*****************/// void display(U32 jcolor); void Uart_SendByten(U8);
char Uart_Getchn(char* Revdata, int timeout); /////////////////////////////////////////////////////
unsigned
char
*)0x50000020)=(unsigned
// Main function. // int main(void) {
ARMTargetInit(); // do target (uHAL based ARM system) initialisationOSInit(); // needed by uC/OS-II //
LCD_Init(); ac_key=1; //OSInitUart(); //initOSMessage(); //initOSDC(); //LoadFont(); //#endif
//loadsystemParam();
// create the tasks in uC/OS and assign increasing // // the pipeline has the highest priority. // //LCD_printf(\
//OSTaskCreate(SYS_Task,(void*)0,(OS_STK*)&SYS_Task_Stack[STACKSIZ
E-1], SYS_Task_Prio);
OSTaskCreate(Task1, (void *)0, (OS_STK *)&task1_Stack[STACKSIZE-1],
Task1_Prio);
OSTaskCreate(Task2, (void *)0, (OS_STK *)&task2_Stack[STACKSIZE-1],
Task2_Prio);
OSTaskCreate(Task3, (void *)0, (OS_STK *)&task3_Stack[STACKSIZE-1],
Task3_Prio);
OSTaskCreate(Task4, (void *)0, (OS_STK *)&task4_Stack[STACKSIZE-1], Task4_Prio);
OSAddTask_Init(0);
BSPprintf(0,\
//LCD_printf(\//LCD_printf(\
//LCD_ChangeMode(DspGraMode); OSStart(); // start the OS // // never reached // return 0;
}//main
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Task1(void *Id) {
for(;;){
if(ac_key==1) { ac_key=0;
BSPprintf(0,\ display(0x000000f8); //显示红色 ac_key=1; } }
void Task2(void *Id) {
for(;;){ }
OSTimeDly(300);
if(ac_key==1) { ac_key=0;
BSPprintf(0,\ display(0x0000fc00);//显示绿色 ac_key=1; }
}
OSTimeDly(1000);
}
void Task3(void *Id) {
for(;;){
if(ac_key==1) {
ac_key=0;
BSPprintf(0,\ display(0x00f80000);//显示蓝色 ac_key=1; } }
void Task4(void *Id) {
for(;;){
err=Uart_Getchn(c,0);
}
OSTimeDly(7000);
if (err==TRUE&&*c!=0x0d)
Uart_SendByten(*c);
else if(err==TRUE) {
Uart_SendByten(0xa); Uart_SendByten(0xd); } }
void display(U32 jcolor) {
}
OSTimeDly(300);
int i,j;
for(i=0;i for(j=0;j void Uart_SendByten(U8 data)//ok eric rong { //int i; } while(!(rUTRSTAT0 & 0x4)); //Wait until THR is empty. hudelay(10); WrUTXH0(data); char Uart_Getchn(char* Revdata, int timeout) { if(!(rUTRSTAT0 & 0x1)) return FALSE; //Receive data read else { *Revdata=RdURXH0(); return TRUE; } } 八、思考题 1)如何提高键盘的响应速度? 答:1.可以采用中断响应的方式。即有键盘输入时,引发中断响应,在中断处理程序中实现在超级终端上答应相应的字符。2.将键盘应答的任务的优先级设定的尽可能的高。 2)全局变量ac_key对共享资源管理有何意义? 答:由于程序中有多个task,使用这个全局变量可以避免task 之间发生冲突,在进入LCD逐个点刷屏的时候,由于ac_key为假,其他任务不可以运行,保证每次刷屏都可以完整刷完。可见,全局变量实际上相当于一个资源使用标志,标识资源是否在使用中,任务通过判断该标志实现对资源访问的互斥。