Interface Protocols
8-Bit GPIO Set/Clear Register
An 8-bit GPIO register with atomic Set and Clear operations where Clear takes priority over Set.
About this block
Simulate it in the Verilog IDE
8-Bit GPIO Set/Clear Register is a Verilog reference block in the Interface Protocols catalog. UART, SPI, I2C, and other serial or peripheral protocol interfaces. Marked Medium: more state or a wider datapath, still one workspace in the IDE.
This IP implements an 8-bit General Purpose Input/Output (GPIO) register designed for atomic Set and Clear operations. It provides a standard, low-latency interface for controlling GPIO pins in embedded systems.
A key feature of this design is that Clear operations take precedence over Set operations within the same clock cycle. This effectively prevents race conditions when updating pin states concurrently. The module is synchronous, uses an active-low reset, and is suitable for simple GPIO control tasks without the overhead of complex state machines.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit GPIO Set/Clear Register.
- Read the Verilog module in the editor. The catalog line for this block: An 8-bit GPIO register with atomic Set and Clear operations where Clear takes priority over Set.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- 8-Bit Parallel Data Width: Supports control of 8 independent GPIO pins.
- Atomic Set/Clear: Separate
set_maskandclr_maskinputs allow simultaneous updates. - Clear Priority: If a bit is specified in both
set_maskandclr_mask, the Clear operation dominates, forcing the bit to 0. - Synchronous Reset: Active-low reset (
rst_n) forces all output bits to 0 on the next clock edge. - Low Latency: Combinatorial output logic ensures minimal propagation delay.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input. Updates occur on the positive edge. |
rst_n | Input | 1 | Active-low synchronous reset. |
set_mask | Input | [7:0] | Mask bits to set to logic 1. |
clr_mask | Input | [7:0] | Mask bits to set to logic 0. |
dout | Output | [7:0] | Current state of the GPIO register. |
Architecture
The internal logic implements a priority-based update scheme. The output dout is updated on the positive edge of the clock. The logic equation is:
This equation ensures that:
- Bits in
clr_maskare forced to 0 (Clear Priority). - Bits in
set_maskare forced to 1. - Bits not in either mask retain their previous state.
### Block Diagram
Verification
The provided testbench (tb/tb_gpio_set_clr_8.v) verifies five key scenarios to ensure functional correctness:
- Reset Check: Verifies that
rst_nclears all output bits to zero. - Set Check: Verifies that
set_maskcorrectly sets bits to 1. - Clear Check: Verifies that
clr_maskcorrectly clears bits to 0. - Priority Check: Verifies that simultaneous Set and Clear operations result in Clear (0).
- Re-set Check: Verifies that bits previously cleared can be set again.
### Expected Simulation Results
After running the simulation, the log panel should display:
More in Interface Protocols
- 1-Bit GPIO Pin Driver (Combinational) — L1 Upgrade — L2 Upgrade
- 32-Bit MMIO GPIO (DI Read, Byte-Strobed DO) — L2 Upgrade
- 8-Bit GPIO Output Register
- 8-Bit GPIO with Direction and Rising-Edge IRQ
- I2C Arbitration Lost Detector
- I2C Bus Idle Timeout
- I2C Clock Stretch Detector
- I2C NACK Sticky Flag Detector
- I2C Start/Stop Detector
- JTAG TAP Controller
- Lightweight I²C Master Controller (Standard Mode)
- Lightweight I²C Slave Controller (Standard Mode)
- SPI Master Lite
- SPI Mode-0 Host (8-Bit Frames)
- SPI Mode-3 Slave (CPOL=1, CPHA=1) 8-Bit
- SPI Slave Controller (Mode 0)