Latch a switch pattern inside a C interrupt handler
Online version: https://fpga.labsland.com/altera/computer-organization/lab-07/part-01/
Debugger setup
CPUlator simulatorC · DE1-SoC Nios V computer, simulated in your browser. No board or sign-in needed.
- Get the sourceDownload
main.c - Open the simulatorOpen CPUlator
Let the main loop copy the ten switches to the red LEDs. A separate pushbutton interrupt takes a snapshot of the seven lowest switches for HEX0. Moving a switch between button releases should affect only the LEDs.
In CPUlator select C in Language, open File → Open and choose main.c. Use Compile and Load (F5), then Continue (F3).
Follow two paths through the program
Find main and machine_event. Which function needs to read SWITCHES on every pass? Which should update HEX_LOW exactly once per button event? Inspect the bit mask for the four pushbuttons. Keep the write that acknowledges KEY_EDGES and fix the assignment to HEX_LOW.
Try two snapshots
Use the Switches and Push buttons panels. Set the switch word to 6. Press and release KEY0, switch to 64 without touching a key, press and release KEY3, then move all switches down. At every step record the LED word and sketch HEX0. Pattern 6 lights the two right bars. Pattern 64 lights the middle bar.
Return to the interrupted program
Restart. In Disassembly, go to machine_event and set a breakpoint on the first instruction. Continue and release a key. Compare pc with mtvec, read mcause and mepc, then step through the prologue and the final mret. Submit the five output pairs and show where the compiler restores the interrupted stack and program counter.
Original LabsLand activity following FPGAcademy Computer Organization Lab 7, Part I. FPGAcademy PDF · MIT
