Listing 1-Eventest.plm EventTest:Do; Declare Dummy Word; /* dummy used to assign return values */ $include(c:\ram\event\event.inc) declare _FR_ literally '.'; /* function reference operator in plm*/ init$80186:Procedure; /* This function must be modified/rewritten according to the H/W configuration of the system. Mainly the devices initializations and address allocated for them. a) The processor used. b) The Interrupt controller used. c) The Timer used. The sequence of operations it has to perform are. a) Processor initialization if any. b) Assignment of Scheduler global variables. c) Programming of timer d) Programming of interrupt controller. Procedure for initializing 80186 timer channel 2 for generating 1ms pulse. This Procedure must be called before invoking interrupt programs. The slot-time selected here is 1ms. */ outword(0fffeh) = 2090h; /* non iRMX,interrupt controller in master mode */ /* Initialize Scheduler global variables. */ EoiPort = 9022h; /* eoi port of 80186 */ EoiValue = 8000h; /* int 3 nonspecific(to all) */ TIMER$INTLEVEL = 19 ; /* Timer2 interrupt of 80186 */ /* program timer 2 for 1ms square pulse. */ outword(9060h) = 1000; /* dummy value < max count */ outword(9062h) = 2000; /* maxcount. 1ms/500ns = 2000 */ /* enable counting,generate interrupt on TC, continues counting */ outword(9066h) = 1110$0000$0000$0001b; outword(9028h) = 1111$1110b;/* enable Timer only mask others */ /*Control register programming of 80186 */ outword(9032h)= 00;/* timer high priority*/ outword(902ah) = 0007h; /* priority mask register */ End init$80186; /*_______________________________________________________________*/ /***** Example programs. Port address and other routines are according to the H/W configuration ********************************************************************/ Clock:procedure; declare (Hr,Mi,Sc) byte;/* can be made global for setting time */ Sc=Sc+1; If Sc>=60 then Do; SC = 0; Mi=Mi+1; If Mi>=60 then Do; Mi = 0; Hr=Hr+1; If Hr>=24 then Hr = 0; End; End; Call DisplayTime(Hr,Mi,Sc); Dummy = SubmitTask(1000,_FR_ Clock); /* every one second */ End Clock; /*_______________________________________________________________*/ ReadKb:procedure; /* this program assumes a ring buffer to store key depressions the following routines are assumed. PushToKbBuffer - push a char to ring buffer NotKBBufferEmpty - check keyboard hit PopFromKbBuffer - pop a char from ring buffer */ Declare Key byte; /* procedure to read non-intelegent keyboard */ Key = ScanKb; /* 0ff means no key pressed */ If Key <> 0ffh then Call PushToKbBuffer(Key); Dummy = SubmitTask(100,_FR_ ReadKb); /* scan keyboard every 100ms */ End ReadKb; Call init$80186; Call Initializations; Call Clock; /* update and display time at every one second */ Call ReadKb; /*scan keyboard and push charactor every 100ms */ /* USER CODE any other event monitoring programs */ Do While 1; If NotKBBufferEmpty then do; Declare Key byte; Key = PopFromKbBuffer; Do case Key; ; /*USER CODE. actions according to the key press */ ; End; End; /* USER CODE any other event monitoring, timer allocation and time measuring code segments. */ End; End EventTest;