Summary of the invention
Embodiments of the invention provide a kind of interruption processing method and microcontroller, can reduce the time that response is interrupted, and improve the efficient of interrupting processing.
The technical scheme that the embodiment of the invention adopts is:
A kind of interruption processing method comprises:
When having the interrupt routine that responds, executive chairman's call instruction, wherein, described long call instruction comprises 7 clock period;
The value that program pointer is current is pressed into storehouse, with the protection breakpoint;
In the 2nd and the 4th clock period of described long call instruction, will interrupt accordingly the entry address and send into program bus;
In the second-to-last clock period of described long call instruction, program pointer is sent into from program bus in described interruption entry address, so that after described interrupt routine executes, carry out next bar instruction from described interruption entry address.
A kind of microcontroller comprises:
Execution module is used for when having the interrupt routine that responds, executive chairman's call instruction, and wherein, described long call instruction comprises 7 clock period;
Be pressed into module, be used for the value that program pointer is current and be pressed into storehouse, with the protection breakpoint;
The first processing module was used in the 2nd and the 4th clock period of described long call instruction, will interrupt accordingly the entry address and send into program bus;
The second processing module is used in the second-to-last clock period of described long call instruction program pointer being sent into from program bus in described interruption entry address, so that after described interrupt routine executes, from next the bar instruction of execution of described interruption entry address.
The interruption processing method that the embodiment of the invention provides and microcontroller; when having the interrupt routine that responds; execution comprises the long call instruction of 7 clock period; the value that program pointer is current is pressed into storehouse; with the protection breakpoint; in the 2nd and the 4th clock period of described long call instruction; to interrupt accordingly the entry address and send into program bus; in the second-to-last clock period of described long call instruction; program pointer is sent into from program bus in described interruption entry address; so that after described interrupt routine executes, carry out next bar instruction from described interruption entry address.Compared with prior art, long call instruction only needs 7 clock period, and the instruction operation speed can reduce the time that response is interrupted, and improves the efficient of interrupting processing.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making all other embodiment that obtain under the creative work prerequisite.
For the advantage that makes technical solution of the present invention is clearer, below in conjunction with drawings and Examples the present invention is elaborated.
Embodiment one
Present embodiment provides a kind of interruption processing method, in the present embodiment, describes as an example of 8051 microcontrollers example.
As shown in Figure 1, described method comprises:
101, carry out interrupt arbitrage in last clock period of every instruction, judge whether to block interrupt response, if do not block interrupt response, then enter the processing of interrupt response.
Particularly, the interrupt timing module is in last clock period that every instruction is carried out, namely during SL=1, carry out interrupt arbitrage, when finding to respond a certain interruption, interrupt flag bit is drawn high, cause in next clock period interrupt request singal to uprise that expression enters the processing of interrupt response.Owing to read next bar instruction before the SL state carries out interrupt arbitrage, next the bar instruction that therefore will read first executes, at the S2L state of next bar instruction of reading, by interrupt request singal mask program storer fetching signal.
Wherein, described interrupt arbitrage specifically can comprise:
Judge whether next bar instruction of getting into is RETI (interrupt return instruction), the instruction of perhaps IE (interrupting allowing register), IP (interrupt priority level register) being read and write, if present instruction is RETI, the instruction of perhaps IE, IP being read and write then can be blocked interrupt response.
Wherein, last state every instruction, get into next bar instruction, if the instruction of getting into is the RETI instruction, then the Reti_decode signal is 1, when in the end a state carries out interrupt arbitrage, Reti_decode 1 will stop interrupt request singal intack to uprise, thereby can not respond interruption.
When IE, IP register selected signal ie_sel or ip_sel were effective, the ieip that will reset was 1, otherwise at the S1 state of every instruction of rising edge of clkb ieip was set to 0.Ieip represents when being high level that present instruction is the instruction to IE, IP register manipulation.When ieip was effective, shielding interrupt response signal intack dragged down it, thereby can not respond interruption.
Further, described interrupt arbitrage can also comprise:
If find to respond the current interruption that monitors, just the confirm signal is put 1, indicate to enter the interrupt response operation;
When processing at the same level the interruption, process according to the natural order of interrupt priority level;
When having high level interrupt responding, the interruption of priority processing high priority;
When interrupt nesting occurring, that is to say, when in commission the interruption of high priority occurring in the disconnected process, preferentially carry out the interruption of high priority, until executing the breakpoint succession that returns again original interrupt routine, carries out high priority.
102, after 8051 microcontrollers receive interrupt request singal intack, in last clock period of the instruction of current execution, it is invalid to be set to for the control signal of the data writing program bus of control program storer, to suspend the data writing program bus in the program storage.
103, put into the operational code of long call instruction LCALL at program bus, because this moment is read opcode from program storage not, therefore program pointer can not change, effectively and in the second-to-last clock period of present instruction suspend the change that PC (program pointer) is worth at interrupt request singal intack, interrupt the entry address until executive chairman's call instruction LCALL jumps to program pointer.
Wherein, long call instruction LCALL comprises 7 clock period, residing 7 clock period when adopting S1, S2, S3, S4, S5, S2L, SL to represent respectively this long call instruction LCALL execution here.
104, executive chairman's call instruction LCALL, the value that program pointer is current is pressed into storehouse, with the protection breakpoint.
105, in the 2nd and the 4th clock period of long call instruction LCALL, the entry address of interrupt routine is placed on the program bus.
106, in second-to-last clock period of described long call instruction LCALL, program pointer is sent into from program bus in described interruption entry address, so that after described interrupt routine executed, 8051 microcontrollers were then from next the bar instruction of execution of described interruption entry address.
The interruption processing method that the embodiment of the invention provides; when having the interrupt routine that responds; execution comprises the long call instruction of 7 clock period; the value that program pointer is current is pressed into storehouse; with the protection breakpoint; in the 2nd and the 4th clock period of described long call instruction; to interrupt accordingly the entry address and send into program bus; in the second-to-last clock period of described long call instruction; program pointer is sent into from program bus in described interruption entry address; so that after described interrupt routine executes, carry out next bar instruction from described interruption entry address.Compared with prior art, long call instruction only needs 7 clock period, and the instruction operation speed can reduce the time that response is interrupted, and improves the efficient of interrupting processing.
Embodiment two
Present embodiment provides a kind of microcontroller, and as shown in Figure 2, described microcontroller comprises:
Execution module 201 is used for when having the interrupt routine that responds, executive chairman's call instruction, and wherein, described long call instruction comprises 7 clock period;
Be pressed into module 202, be used for the value that program pointer is current and be pressed into storehouse, with the protection breakpoint;
The first processing module 203 was used in the 2nd and the 4th clock period of described long call instruction, will interrupt accordingly the entry address and send into program bus;
The second processing module 204 is used in the second-to-last clock period of described long call instruction program pointer being sent into from program bus in described interruption entry address, so that after described interrupt routine executes, from next the bar instruction of execution of described interruption entry address.
Further, as shown in Figure 3, described microcontroller can also comprise:
Module 205 is set, be used for after receiving interrupt request singal, in last clock period of present instruction, it is invalid to be set to for the control signal of the data writing program bus of control program storer, to suspend the data writing program bus in the program storage;
Put into module 206, be used on program bus, putting into the operational code of described long call instruction.
Further, as shown in Figure 3, described microcontroller can also comprise:
Interrupt arbitrage module 207 was used in last clock period of present instruction, carried out interrupt arbitrage, judged whether to block interrupt response;
If do not block interrupt response, then enter the processing of interrupt response.
Further, described interrupt arbitrage module 207, concrete for judging whether next bar instruction of getting into is interrupt return instruction RETI, the perhaps instruction to interrupting allowing register IE, interrupt priority level register IP to read and write;
If present instruction is RETI, the instruction of perhaps IE, IP being read and write then can be blocked interrupt response.
Further, described interrupt arbitrage module 207, concrete being used for processes according to the natural order of interrupt priority level when having interruption at the same level responding; When having high level interrupt responding, the interruption of priority processing high priority; When the interruption of high priority occurring in the in commission disconnected process, carry out first the interruption of high priority, and then return the breakpoint succession execution of former interrupt routine.
The microcontroller that the embodiment of the invention provides; when having the interrupt routine that responds; execution comprises the long call instruction of 7 clock period; the value that program pointer is current is pressed into storehouse; with the protection breakpoint; in the 2nd and the 4th clock period of described long call instruction; to interrupt accordingly the entry address and send into program bus; in the second-to-last clock period of described long call instruction; program pointer is sent into from program bus in described interruption entry address; so that after described interrupt routine executes, carry out next bar instruction from described interruption entry address.Compared with prior art, long call instruction only needs 7 clock period, and the instruction operation speed can reduce the time that response is interrupted, and improves the efficient of interrupting processing.
The above-mentioned embodiment of the method that provides can be provided the microcontroller that the embodiment of the invention provides.The interruption processing method that the embodiment of the invention provides and microcontroller go for the interruption of 8051 microcontrollers and process, but are not limited only to this.
One of ordinary skill in the art will appreciate that all or part of flow process that realizes in above-described embodiment method, to come the relevant hardware of instruction to finish by computer program, described program can be stored in the computer read/write memory medium, this program can comprise the flow process such as the embodiment of above-mentioned each side method when carrying out.Wherein, described storage medium can be magnetic disc, CD, read-only store-memory body (Read-Only Memory, ROM) or store-memory body (RandomAccess Memory, RAM) etc. at random.
The above; be the specific embodiment of the present invention only, but protection scope of the present invention is not limited to this, anyly is familiar with those skilled in the art in the technical scope that the present invention discloses; the variation that can expect easily or replacement all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection domain of claim.