The edge triggers and interrupts sharing method
Technical field
The present invention relates to a kind of interruption and share method, particularly relate to a kind of edge and trigger the shared method of interruption.
Background technology
For the interrupt request that external unit proposes, can use two kinds of detection methods: level triggers and edge trigger.
1, level triggering mode
On IR (interrupt request) incoming line, detect a significant level (high level or low level), and after interrupting the sampling pulse arrival, first can keep significant level, just thinking has external unit to propose interrupt request, and make SR (Interrupt Status Register, interrupt status register) corresponding positions continue to put 1.Level triggering mode provides the interruption that repeats to produce, and is used for the situation of the continuous execution subroutine of needs till interrupt request IR neutralizes.This mode allow to interrupt request line by " or " relation connects, promptly several interrupt request are imported with same IR.
2, edge triggering mode
When detect from low to high at the IR input end (or from high to low) go up (or down) saltus step the time, and level remains to first and interrupts after sampling pulse arrives, just thinking has interrupt request.
Yet the edge triggering mode designs for connecting single interrupt source.In this case, expanding extra interruption input if desired, is very difficult.Because the edge triggering mode that interrupts is not supported to interrupt sharing, do not allow a plurality of interrupt sources to be connected to the same interrupting input end of interruptable controller.
Interrupt sharing problem for solving the edge triggering, U.S. Pat 4631670 has disclosed a kind of edge triggering of using hardware approach to realize and has interrupted shared method.
Summary of the invention
Technical matters to be solved by this invention provides a kind of edge and triggers the shared method of interruption, and the edge triggering mode that the solution prior art is interrupted is not supported to interrupt shared, does not allow a plurality of interrupt sources to be connected to the problem of the same interrupting input end of interruptable controller.
For achieving the above object, the invention provides a kind of edge and trigger the shared method of interruption, its characteristics are, realize that by repeatedly recursive call device interrupt routine the edge triggers interruption and shares, comprise: step 1, detect each device interrupt request and enter main Interrupt Process; Step 2 is called out each device interrupt routine treatment facility successively and is interrupted; Step 3, the result carry out step 2 once more according to Interrupt Process.
Above-mentioned edge triggers and interrupts sharing method, and its characteristics are that this step 2 is to detect per unit interruption status one by one, and this interruption is handled.
Above-mentioned edge triggers and interrupts sharing method, its characteristics are, this step 3 is meant as long as detect arbitrary equipment after this step 2 that finishes interrupts, then carry out this step 2 again, and after this step 2 that is finished, when not detecting any equipment and taking place to interrupt, just stop to carry out this step 2, and withdraw from main Interrupt Process.
Above-mentioned edge triggers and interrupts sharing method, and its characteristics are, before this step 2, comprise that also one forbids the step of main interrupt line.
Above-mentioned edge triggers and interrupts sharing method, and its characteristics are that this device interrupt routine treatment facility must return a state value when interrupting, if this equipment does not interrupt, then returns vacation, if taken place to interrupt then return true.
Above-mentioned edge triggers and interrupts sharing method, and its characteristics are, after this step 2, as long as the return state value that an equipment is arranged is then carried out recursive call once more and handled for true.
Technique effect of the present invention is: the present invention is in the routine of recursive call device interrupt each time (Routine), if detected and handled the interruption of some or a plurality of equipment, then must recycle once detect, only once do not detecting the interruption generation in the circulation, just can withdraw from Interrupt Process, so just can avoid interrupting losing or interrupting deadlock, realize that the edge triggers interruption and shares.
Further describe specific embodiments of the invention below in conjunction with accompanying drawing.
Description of drawings
Fig. 1 is a hardware environment synoptic diagram of the present invention;
Fig. 2 is traditional interrupt handling routine process flow diagram;
Fig. 3 loses sequential chart for the interruption of using traditional interrupt handling routine to cause;
The interruption deadlock sequential chart of Fig. 4 for using traditional interrupt handling routine to cause;
Fig. 5 is that method flow diagram is shared in interruption of the present invention;
Fig. 6 is the overall flow figure that contains the device interrupt routine of the present invention;
Fig. 7 solves the sequential chart that interruption is lost for adopting the present invention; And
Fig. 8 solves the sequential chart that interrupts deadlock for adopting the present invention.
Wherein, description of reference numerals is as follows:
Tri-state gate circuit 10
Step 201 is removed the INTx state
The ISR of step 202 calling device 1
Step 203 is called out successively, until equipment n
Step 501 detects each device interrupt request and enters main Interrupt Process
Step 502 is called out each device interrupt routine treatment facility successively and is interrupted
Step 503 is called out each device interrupt routine once more successively according to the Interrupt Process result
Step 601 is forbidden main interrupt line
Step 602 is removed main interruption status and is installed and is equipped with interrupt identification RV for false
Step 603 is called out each device interrupt routine successively, promptly at first reads this device interrupt state
Step 604 judges whether to interrupt
If step 605 has taken place to interrupt then has carried out Interrupt Process
Step 606 is removed this device interrupt state
Step 607 is returned very
If step 608 does not take place to interrupt then returns vacation
If step 609 rreturn value is for very then put the RV value for true
Step 610 judges whether the RV sign is true
Step 611 allows main interrupt line
Embodiment
As shown in Figure 1, be hardware environment synoptic diagram of the present invention, equipment 1 to many device interrupt of equipment n with " or " relation connect, as long as any one device interrupt state becomes " produce and interrupt ", then the interruption status of INTx line just becomes " produce interrupt ", is handled by the main interrupt handling program (Routine) of the Interrupt Process of interruptable controller.The interrupting input end of supposing the edge triggering of interruptable controller is that negative edge triggers, and the output of interrupt source can be pulse output, also can be level output, if pulse output, requirement is that the negative pulse negative edge is effective, if level output, requirement is that low level is effective.If signal does not meet above condition, then add a phase inverter and get final product.If the output of interrupt source is not OC (Open-Collector, open collector) output, then need to add a tri-state gate circuit (tri-state buffer) 10.
Traditional interrupt handling routine, as shown in Figure 2, after INTx interrupted entering, main routine was at first removed INTx state (step 201); The ISR of calling device 1 (Interrupt Service Routine, Interrupt Service Routine) (step 202) then; Call out successively then, until equipment n (step 203); Last INTx withdraws from.
But, connect for hardware as shown in Figure 1, if adopt interruption shared routing shown in Figure 2 to handle, will produce many problems.As shown in Figure 3, when the interruption of equipment is output as pulse output, can causes and interrupt losing.With reference to this sequential chart, in taking place, equipment n has no progeny, interrupt line produces negative edge and triggers main interrupt routine, traditional program adopts training in rotation mechanism, interrupt handling program at t1 moment calling device 1, but when equipment 1 reads self interruption status, equipment 1 does not interrupt as yet, and when it take place to interrupt, the interruption that interrupt line can the output negative edge come response apparatus 1, that is to say, at the A point, interrupt line remains low, can not produce negative edge, therefore, the interruption that main interrupt routine can treatment facility 1.
When the interruption of equipment was output as level output, its sequential chart was shown in Figure 4, can cause the interruption deadlock.With reference to its sequential chart, by the same token, at the B point, it is low that interrupt line keeps always, can not produce negative edge, the interruption of equipment 2 will can not get handling, and therefore also just the level of equipment 2 can not be retracted high level, like this, because level output, it is low that interrupt line will keep, and causes deadlock.
Interruption provided by the present invention is shared method and has been solved the problems referred to above, please refer to Fig. 5, and at first step 501 enters main Interrupt Process because of detecting each device interrupt request, as long as there is any one equipment that main Interrupt Process takes place to interrupt promptly entering; Step 502 is called out each device interrupt routine treatment facility successively and is interrupted, and just detects per unit interruption status one by one, and this interruption is handled; Final step 503 is called out each device interrupt routine once more successively according to the Interrupt Process result, as long as detecting arbitrary equipment in this time circulation took place to interrupt, each device interrupt routine of recursive call does not once more then only detect any equipment main Interrupt Process takes place to interrupt just withdrawing from circulation once.
See also Fig. 6, be the present invention's the overall flow figure that comprises the device interrupt routine, at first forbid (Disable) main interrupt line (step 601) after entering Interrupt Process; The processing sign RV that removes main interruption status (being the Status Flag of the interrupt INT x of interruptable controller) then and put main interruption routine is false (step 602); Call out each device interrupt routine then successively, promptly at first read the interruption status (step 603) of this equipment; Judge whether then to interrupt (step 604); If taken place to interrupt then carried out Interrupt Process (step 605); Removing this device interrupt state promptly notifies this equipment release interrupt line (step 606) and returns true (step 607); If generation is interrupted then is returned vacation (step 608); If rreturn value is for very then put the RV value and be true (step 609); After treating that armamentarium all detects, judge whether the RV sign is true (step 610); If be true, then return step 602, cycle detection interrupting device again, otherwise allow (Enable) main interrupt line (step 611), withdraw from then.
The unique distinction that device interrupt in the present embodiment is handled routine is to require each device interrupt to handle routine to return a state value, if this equipment does not interrupt, then return vacation (False), if taken place to interrupt then return true (True).In main interrupt routine, if the rreturn value of any one equipment is true, then set handling sign RV is true.When the loop ends each time of main interrupt routine, judge the state of RV, if RV is true, then returns round-robin and begin, handle the interruption of each equipment again, if RV is false, then withdraws from circulation, and withdraw from interruption routine.
If when detecting Dev_n in the circulation the last time, Dev_1 ... or interruption taken place in Dev_ (n-1), and so current interruption can't obtain handling, and interrupting master routine can directly withdraw from.Current interruption can be provided with the interruption status sign of interruptable controller, after the interruption master routine withdraws from, can reenter the interruption master routine immediately, so this interruption can not lost yet.
Processing procedure of the present invention please refer to Fig. 7 Fig. 8, in contrast to Fig. 2, Fig. 3, adopts this method, and all interruptions all can be processed, can not lose to interrupt or generation level deadlock.For example, the C point in Fig. 7, equipment 1 interrupts, and through the cycle detection second time, at the D point, the interruption of equipment 1 is processed.E point in Fig. 8, equipment 2 interrupts, and through the cycle detection second time, at the F point, the interruption of equipment 2 is processed.
The above is preferred embodiment of the present invention only, is not to be used for limiting practical range of the present invention; Every according to equivalence variation and modification that the present invention did, all contained by claim of the present invention.