Listing 2—Event.plm EventScheduler: Do; /* _________________________________________________ Event Scheduler Development started : 16/07/95 Last Updated : 31/08/95 S/W Designed and Developed by Ramakrishnan.K.V _________________________________________________*/ Declare FunctionReference Literally 'word '; Declare true Literally '0ffh'; Declare FREE Literally '0ffffh'; Declare PoolSize Literally '20';/* maximum timer pool available */ Declare IntNo Literally '10'; /* int. level, used for syntax */ Declare Dummy Word; /* dummy used to assign return values */ declare data$seg$ptr pointer; /* to separate offset and base */ declare data$seg$addr structure(offset word , base word) at (@data$seg$ptr); /*______________________________________________________ */ /* Data structure used for event scheduler */ Declare CurrentToken Byte; Declare Pool(PoolSize)Structure( AssignedToken Word, /* AssignedToken are made true */ CounterValue Word, /* max count is loaded */ ActionTask FunctionReference /* to execute when TC reached */ ); /* Interrupt related variables. Initialized according to the hardware configuration of system by the user while initializing timer & interrupt controller. (Refer procedure done init$80186 to use this with a 80186 based system. */ Declare EoiPort word public; /* eoi port address of PIC */ Declare EoiValue word public; /* eoi value to be given on eoi */ Declare TIMER$INTLEVEL byte public; /* interrupt vector number */ /*______________________________________________________________ The following 3 functions are local a) Despatching - EventScheduler interrupt service routine b) rq$set$interrupt - for Interrupt vector setting c) Search - search for a given token and return its index in timer pool ______________________________________________________________*/ Despatching : Procedure interrupt IntNo; /* This function is an interrupt program. Invoked by the timer at every slot-time. This will execute all the ActionTasks which require service at this timer event. And also update timer pools. */ Declare i Byte; Declare ActionTaskPtr FunctionReference; Do i = 0 to PoolSize-1; If Pool(i).AssignedToken<>FREE then Do; If Pool(i).AssignedToken >PoolSize then Do; /* it is a task pool */ Pool(i).CounterValue = Pool(i).CounterValue - 1; If Pool(i).CounterValue = 0 then Do; ActionTaskPtr = Pool(i).ActionTask; /* take the ActionTask */ Call ActionTaskPtr; Pool(i).AssignedToken = FREE; End; End; Else Do; /* it is a timer pool */ Pool(i).CounterValue = Pool(i).CounterValue + 1; End; End; End; outword(EoiPort) = EoiValue; End Despatching; /*_______________________________________________________________*/ rq$set$interrupt: Procedure( level, interrupt$task$flag, interrupt$handler, interrupt$handler$ds, except$ptr ); /* Function to set interrupt vector.*/ Declare level Word, interrupt$task$flag Byte, interrupt$handler POINTER, interrupt$handler$ds Word, except$ptr POINTER; Declare exception based except$ptr Word; Declare INT$addr structure(offset Word , base Word) at (@interrupt$handler); Declare ptr$loc pointer, vct$addr structure(offset Word , base Word) at (@ptr$loc), w based ptr$loc(2) Word; If level > 255 then Do; exception = 1; Return; End; vct$addr.offset = level * 4; vct$addr.base = 0; w(0) = int$addr.offset; w(1) = int$addr.base; exception = 0; End rq$set$interrupt; /*_______________________________________________________________*/ Search:Procedure(Token) Word; /* this Procedure will search the given token and Return the index at which the match is found. Else Return 0FFFFH; */ Declare i Word; Declare Token Word; i = 0; Do While(((Pool(i).AssignedToken)<>Token) and (i= Count then Do;/* Requested delay elapsed */ Dummy = StopTimer(TimerToken);/*free timer*/ Return; End; End; End RequestDelay; /*_______________________________________________________________*/ SubmitTask:Procedure(MaxWaitTime,FunctionPtr)byte reentrant Public; /* function to execute a function after given delay (MaxWaitTime * slot-time ) is occurred */ Declare MaxWaitTime Word, FunctionPtr FunctionReference; Declare i Word; disable; /* search for the Pool */ i = Search(FREE); If(i 0ffffh then Do;/* Do not wait indefinitely */ If ElapsedTime(TimerToken) >= WaitTime then Do;/* condition not satisfied */ Dummy = StopTimer(TimerToken);/*free timer*/ Return(0ffffh); /* with in the specified time */ End; End; End; End StopWatch; /*_______________________________________________________________*/ StartTimer:Procedure Word Public; Declare i Word; /* Search For the Free Timer Pool*/ disable; i = Search(FREE); If(iFREE then Do; If Pool(i).AssignedToken >PoolSize then Do; /* it is a task pool */ Pool(i).CounterValue = Pool(i).CounterValue - 1; If Pool(i).CounterValue = 0 then Do; ActionTaskPtr = Pool(i).ActionTask; /* take the ActionTask */ Call ActionTaskPtr; Pool(i).AssignedToken = FREE; End; End; Else Do; /* it is a timer pool */ Pool(i).CounterValue = Pool(i).CounterValue + 1; End; End; End; outword(EoiPort) = EoiValue; End Despatching; /*_______________________________________________________________*/ rq$set$interrupt: Procedure( level, interrupt$task$flag, interrupt$handler, interrupt$handler$ds, except$ptr ); /* Function to set interrupt vector.*/ Declare level Word, interrupt$task$flag Byte, interrupt$handler POINTER, interrupt$handler$ds Word, except$ptr POINTER; Declare exception based except$ptr Word; Declare INT$addr structure(offset Word , base Word) at (@interrupt$handler); Declare ptr$loc pointer, vct$addr structure(offset Word , base Word) at (@ptr$loc), w based ptr$loc(2) Word; If level > 255 then Do; exception = 1; Return; End; vct$addr.offset = level * 4; vct$addr.base = 0; w(0) = int$addr.offset; w(1) = int$addr.base; exception = 0; End rq$set$interrupt; /*_______________________________________________________________*/ Search:Procedure(Token) Word; /* this Procedure will search the given token and Return the index at which the match is found. Else Return 0FFFFH; */ Declare i Word; Declare Token Word; i = 0; Do While(((Pool(i).AssignedToken)<>Token) and (i= Count then Do;/* Requested delay elapsed */ Dummy = StopTimer(TimerToken);/*free timer*/ Return; End; End; End RequestDelay; /*_______________________________________________________________*/ SubmitTask:Procedure(MaxWaitTime,FunctionPtr)byte reentrant Public; /* function to execute a function after given delay (MaxWaitTime * slot-time ) is occurred */ Declare MaxWaitTime Word, FunctionPtr FunctionReference; Declare i Word; disable; /* search for the Pool */ i = Search(FREE); If(i 0ffffh then Do;/* Do not wait indefinitely */ If ElapsedTime(TimerToken) >= WaitTime then Do;/* condition not satisfied */ Dummy = StopTimer(TimerToken);/*free timer*/ Return(0ffffh); /* with in the specified time */ End; End; End; End StopWatch; /*_______________________________________________________________*/ StartTimer:Procedure Word Public; Declare i Word; /* Search For the Free Timer Pool*/ disable; i = Search(FREE); If(i