📄 example3.c
字号:
/*> example3.c <*//*---------------------------------------------------------------------------*//* * $Revision: 0.1 $ * $Author: jsmith $ * $Date: 941103 $ * * Copyright (c) 1994, VLSI Technology Inc. All Rights Reserved. *//*---------------------------------------------------------------------------*/#include "ucos.h" /* uC/OS interface */#include "osdefs.h" /* uC/OS ARM interface */#define NUM_TASKS 3 /* must be number in range 1 to 62 *//* * P r o t o t y p e s */void Task(int *id);void Timer_IRQ( void );/* allocate memory for tasks' stacks */#define TASK_STK_SIZE 64/* * G l o b a l V a r i a b l e s */OS_EVENT *DispSem;OS_EVENT *Mbox[NUM_TASKS];uint TaskStk[NUM_TASKS][TASK_STK_SIZE];IRQHandlerFn prev_hand; /* function pointer to previous handler *//* * T a s k * * This is being used by NUM_TASKS tasks. */void Task(int *id){ int msg[NUM_TASKS]; uint err; while(FOREVER) { msg[*id] = *(int *)OSMboxPend(Mbox[*id], 0, &err); /* wait for message */ SWI_WriteC(msg[*id]); /* print task's id */ if(*id < NUM_TASKS) { OSMboxPost(Mbox[*id+1], (void *)(*id+'1')); } else { OSMboxPost(Mbox[0], (void *)'1'); }/*OSTimeDly(300);*/ /* Delay 3 second */ }}/* * m a i n */int main( void ){ int id[NUM_TASKS]; int j; union gp { unsigned char *b; unsigned int *w; } p; p.b = (unsigned char *) IOBase; SWI_Write0("\nExample3 using uC/OS for PID600\n\n\0"); SWI_Write0("\nGenerating ID's...\0"); for(j=0; j<NUM_TASKS; j++) /* generate the ID's */ { id[j] = j; /* create an id */ } SWI_Write0("\nDoing an OSInit()...\0"); OSInit(); /* needed by uC/OS */ DispSem = OSSemCreate( 1 ); /* Display semaphore */ SWI_Write0("\nCreating the tasks...\0"); for(j=0; j<NUM_TASKS; j++) /* generate the tasks */ { OSTaskCreate((PTV)Task, (void *)&id[j], (void *)&TaskStk[j][TASK_STK_SIZE], j + 10); } SWI_Write0("\nCreating the mailboxess...\0"); for(j=0; j<NUM_TASKS; j++) /* generate the mailboxess */ { Mbox[j] = OSMboxCreate((void *)0); } OSMboxPost(Mbox[0], (void *)'1'); /* get task 1 started */ SWI_Write0("\nHooking into the C-DEMON's TIMER...\0"); /* * Now HOOK the DEMON's TIMER to uC/OS */ *(p.b + IRQM) = 0; /* stop the TIMER interrupt */ /* * TIMER is bit position 1 in FIQ (vecnum = FIQbitvector+bit1 = 0x20 + 1) */ if ((prev_hand = ARMInstallIRQHandler(1,Timer_IRQ)) == NULL) { SWI_Write0("\nError: Unable to install timer handler.\n") ; } *(p.b + IRQM) = TimerIT; /* restart the TIMER interrupt */ SWI_Write0("\nDoing an OSStart()...\0"); OSStart(); /* start the game */ /*----------------- never reached ----------------------------------------- * * Following code is here to show how to restore the original timer vector */ *(p.b + IRQM) = 0; /* remove the TIMER interrupt */ /* * TIMER is bit position 1 in FIQ (vecnum = FIQbitvector+bit1 = 0x20 + 1) */ if (ARMInstallIRQHandler(1,prev_hand) == NULL) { SWI_Write0("\nError: Unable to reinstall handler.\n") ; } *(p.b + IRQM) = TimerIT; /* restart the TIMER interrupt */}/****************************************************************************** * * T i m e r _ I R Q * * ENTER: void * EXIT: void * * Timer interrupt routine */void Timer_IRQ( void ){ union gp { unsigned char *b; unsigned int *w; } p; p.b = (unsigned char *) IOBase; *(p.b + IRQRST) = TimerIT; /* reset Timer interrupt */ OSTimeTick(); /* do uC/OS tick routine */}/*---------------------------------------------------------------------------*//*> EOF example3.c <*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -