What you practice
Timer IRQ handler (3.2). Configure timer interrupts and implement the handler to toggle GPIO outputs. It is in Timer IRQ handler — Part 3 · Interrupts & DMA of the RISC-V on SoC & System Masterclass.
The core and the mini-SoC simulate as one workspace in the IDE. Follow MMIO, interrupts, and the program on the Verilator waveform, not only a pass line.
What you will learn
Today you will configure the timer and interrupt controller to trigger an IRQ, and write the handler code to toggle GPIO outputs. This is a critical step for understanding how software interacts with hardware interrupts in a real SoC.
Learning objectives
- Understand the sequence for enabling timer interrupts in the CSR registers.
- Implement the IRQ handler to modify GPIO output enable and data registers.
- Verify the system halts correctly after the handler completes its task.
Theory
Interrupts allow the CPU to pause its main loop and execute a specific handler when a hardware event occurs. The timer generates a periodic signal that asserts the irq_line input to the core. The core must have the global interrupt enable bit set in the status register to respond. The timer control register must be configured to generate an interrupt event. The handler code must clear the interrupt pending bit to acknowledge the event.
| Component | Role in IRQ | Key Action |
|---|---|---|
| Timer | Generates periodic signal | Set compare value and enable interrupt bit |
| IRQ CSR | Routes interrupt to core | Enable specific IRQ line in enable register |
| Core | Responds to interrupt | Jump to mtvec address on IRQ assert |
| Handler | Executes ISR logic | Clear pending bit and perform task |
Practice
Open this chapter in RtlStudio and confirm the files appear in the Explore tree. Open student/rtl/design.sv to complete the interface port connections. Replace the __TODO__[0] placeholder in the axi_if instance declarations with the correct address width value 32. Open student/tb/tb_top.sv to verify the testbench structure includes the IRQ stimulus. Run Simulation from the sidebar and check the Log panel for the initial INFO banner. Inspect the waveform in the Waveform tab to see the clock, reset, and irq_line signals.
Summary
You configured the timer and interrupt controller to generate periodic interrupts that trigger the CPU core. You implemented the Interrupt Service Routine to acknowledge the timer event and toggle the GPIO outputs. This practice demonstrated the complete flow of interrupt handling from signal generation to execution and return.
© 2026 RtlStudio. Licensed under CC BY-NC-ND 4.0. Commercial use and modifications by third parties are not permitted.
Run it in the Verilog IDE
- Open the system lesson in the IDE. The RV32I core and the mini-SoC fabric simulate together.
- Run Verilator and trace the program through MMIO: address, load/store data, and the peripheral response.
- Interrupts and DMA belong on the waveform next to the instruction stream, not only in a pass/fail line.
- Edit the integration RTL, resimulate, and run Yosys on the structural block when you want a netlist.
The lesson is done when the simulation matches Timer IRQ handler. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.