Electrical Eng ; lab reports paraphrase
ECE 425L
Lab #10: Interrupts
Introduction:
In this lab, different types of interrupts will be introduced that can branch to different interrupt handlers to perform things such as lighting certain LED patterns or flashing a display on the LCD. The first interrupt that will be covered is the Software Interrupt. As its name suggests it is an interrupt that is generated by software. The Fast Interrupt (FIQ) and Normal Interrupt (IRQ) are interrupts used by peripherals. These two flags can be enabled and disabled as desired by setting or clearing the F and I bits on the CPSR register. By configuring the external interrupt inputs and the Vectored Interrupt Controller, these interrupts can be triggered using the joystick on the education board.
Equipment Used:
Keil tools to compile and debug the code.
LPC2148 Education Board.
Procedure:
The first procedure that must be taken care of are the stacks for each of the modes. Each stack must have enough memory associated to it so that it will not lead to overflows. Therefore the processor will be switched to every possible mode during initialization and the stacks will be configured while in each mode. The interrupt bits must be disabled at this time so that they do not interrupt this procedure. Once this is accomplished, the next step can be started.
The Software Interrupt is generated by software unlike the other two interrupts that will be discussed later. The instruction used to call this interrupt is “SWI”. When this instruction is executed, the processor will switch to Supervisor mode and branch to the SWI handler. Here is where the procedure that the programmer wants to be executed when the SWI is called is placed. The interrupt handler must remember to save the registers, flags, and the returning address so that the instruction that was following before the interrupt was called can be executed once done. The procedure that is done when the SWI is executed is up to the programmer. For this experiment, a certain LED combination was displayed on the board to indicate a software interrupt had occurred.
The following tasks requires executing multiple software interrupt calls. The SWI instruction has a number part to it that allows programmers to use the same instruction to call different subroutines through the same interrupt handler. Since the number that is chosen is placed in the comment field of the SWI instruction, this number can be obtained by grabbing it from memory and masking the first couple bits. From here different numbers can branch to different subroutines that can have different displays such as all even LEDs or all odd LEDs. A delay may be added in between the different SWI calls so that it can be seen on the education board instead of it quickly flashing all the interrupts. This comes in handy when trying to execute different procedures using software interrupts.
The other two interrupts discussed in this experiments are the Fast Interrupt and Normal Interrupt. These can be programmed to be executed by using the joystick shown in Figure 1 below.
Figure 1: LPC2148 Education Board Schematic: Joystick-switch.
This experiments requires that pin 0.16 (clicking the joystick) and pin 0.20 (bottom right) to be used to execute an interrupt. EINT0 is the external interrupt input for P0.16 and EINT3 is for P0.20. These inputs can be programmed so that when clicked or moved either FIQ or IRQ will execute. First the PINSEL1 must be modified to select EINT0 and EINT3 for P0.16 and P0.20. Next EXTMODE and EXTPOLAR must be modified to choose between Level-sensitivity and falling/rising edge sensitive. And last the EXTINT must be modified so that the corresponding flags are cleared which would enable the IRQ and FIQ if the correct bit combination is sent to the register. Once these are set up the Vectored Interrupt Controllers must be set up before the joystick can be used.
The Interrupt Select Register (VICIntSelect) will define whether pin will trigger an IRQ or FIQ interrupt. Bit 14 controls EINT0 and bit 17 controls EINT3 and by setting one of them to “0” it will set it to IRQ while a “1” will set it to FIQ. Once these are assigned the Interrupt Enable Register (VICIntEnable) must be set up so that it enables these interrupts. Once all these registers have been set up, IRQ and FIQ handlers can be setup to execute similar to the SWI handler that was done in the previous task. However instead of being asserted through software these will be asserted by clicking or moving the joystick. Once one is triggered the interrupt handler starts to execute. Just like the SWI certain procedures are done before the interrupt begins to execute such as coping the CPR into the SPSR of the interrupt and loading the address of the interrupt exception vector into the PC.
Results:
Task One:
Task one required the startup code to be modified to initialize the stacks for each mode. Since each mode has its own stack pointer it is necessary to set up the stack pointer for each processor mode. Each mode must be given enough space in memory for the stack to be implemented so for this program to make it simple each mode was given 0x100 space starting with the supervisor mode at 0x40000100. The interrupt bits I and F must be disabled so that an interrupt does not stop this processes.
Task Two:
Task two required an assembly program that would call a single Software Interrupt to light up all eight LEDs. This was done by using the instruction “SWI”. By using this instruction it will branch to the Software Interrupt vector which then branches to the subroutine “SWI_Code”. This subroutine branches to “LED_init” to make sure the pins are set to GPIO and as outputs. After initialized it branches to the subroutine “Eight_On” that will turn on all the LEDS on the board. Once performed the LR is loaded back into PC as well as the copying the flags back to the CPSPR using the instruction MOVS pc, lr. The result can be seen in Result Figure 1 below.
Result Figure 1: ALL LEDs on using SWI.
Task Three:
Task three required an assembly program that would call three different software interrupt calls using SWI numbers. Since the instruction “SWI” is followed by a number that can be used to identify each of the intendance called. The SWI instructions branches to the SWI Handler no matter what number is associated with it. The number associated with the SWI is the first byte on the SVC instruction so by bit clearing everything but the first byte the number can be obtained. Once obtained the number was used to branch to the desired LED pattern. One of the patterns is shown in Result Figure 2 below.
Results Figure 2: Odd LEDs on using SWI.
Task Four:
Task four required an assembly program that would configure the joystick to generate an IRQ interrupt or a FIQ interrupt depending if the joystick is pushed down or moved to the bottom left direction. This was achieved by initializing the registers: PINSEL1; EXTMODE; EXTPOLAR; EXTINTFLG; VICIntSel, and VICIntEnable.
· PINSEL1 was initialized to be external interrupts instead of GPIO by setting bit 1:0 to 01(EINT0) and bit 9:8 to be 11(EINT3).
· EXTMODE was set to be edge sensitive by setting bit 0 and 3 to be 1.
· EXTPOLAR was set to be falling edge sensitive by setting bit 0 and 3 to 0.
· EXTINTFLG clears the external interrupt flags for EINT0 and EINT3.
· VICIntSelect register defines the interrupt type so bit 14(EINT0) was set to 1 making it the FIQ pin and bit 17(EINT0) was set to 0 making it the IRQ.
· VICIntEnable registers enables the interrupt by setting a 1 to bit 14 and 17.
Once these settings are processed whenever the pin associated with the desired interrupt, the handler is branched to and the subroutine is executed. IRQ and FIQ subroutine do a similar procedure as the SWI just with a different LED pattern. FIQ had the pattern that the first 4 LEDs were turned on and is shown in Result Figure 3 below.
Results Figure 3: First 4 LEDs on using FIQ interrupt triggered by joystick.
Questions:
Question 1: What would happen if “MOV pc, lr” is used instead of “MOVS pc, lr”?
The mode flags will not be updated, causing the processor to remain in its interrupt mode after it has exited the interrupt procedure and resumed execution of user code, and this will cause errors when the user code tries to read the stack.
Question 2: What signal type will you select for the interrupt inputs connected to the Joystick-switch in Figure 2?
External interrupts will be chosen, since these pins must link to the Vectored Interrupt Controller in order to interrupt execution when their state changes.
Question 3: What might happen if the EINT flags were not cleared in the interrupt service routine?
The service routine will execute continuously when the mode is returned to user. This will cause an infinite loop. Such loop occurred during testing, and fixing this step fixed the problem
Question 4: What will happen to the Link Register if a subroutine call is performed in the interrupt service routine?
The link register belonging to the interrupt mode will be updated to reflect the last PC location before the call. Therefore, the link register must always be saved at the beginning of the interrupt procedure, since it contains information needed to get back to User mode. However, the link register belonging to User mode will not be modified.
Conclusion:
This experiment introduced interrupts. An interrupt breaks the flow of a program and branches to a certain subroutine. There are three different interrupts: SWI, FIQ, and IRQ. Software Interrupts are called by the program while the Interrupt Request and Fast Interrupt Request are called by an external input. The SWI instruction is used to call the Software Interrupt which branches to the SWI subroutine and performs the desired operation and then branches back to whatever was being executed before the SWI was called.
The FIQ and IRQ were triggered by an external interrupt input. In this experiment the joystick was used to call the desired interrupt. Certain registers such as EXTMODE and EXTPOLAR must be set up correctly in order to use the joystick to signal the FIQ or IRQ interrupt. Once triggered the desired interrupt handler is branched to and the operation is executed.
This experiment also helped to set up different stacks for each of the modes in the startup file that may be used for the last experiment. This can prove helpful if operating in different modes allowing the use of stacks without having it clash with other modes stacks.