S7.2.1 Set, Clear, Toggle

MediumImplement22 minIcarus Verilog · serverReview the topic

Two byte lanes share a 16-pin output latch. Accept a pair of masked commands together, even when each byte asks for a different operation.

Hardware context: ap_soc 16-pin GPIO bank. Board bring-up and interrupt-driven I/O

Two byte lanes share a 16-pin output latch. Accept a pair of masked commands together, even when each byte asks for a different operation.

Signals in the Timeline

SignalWidthRole
port_clk1stimulus, the same for every design
port_rst_n1stimulus, the same for every design
port_commit1stimulus, the same for every design
port_op4stimulus, the same for every design
port_lanes2stimulus, the same for every design
port_mask16stimulus, the same for every design
port_value16stimulus, the same for every design
Full specification

This exercise combines two commands on one edge. op[1:0] controls the low byte. op[3:2] controls the high byte. Each code selects hold (0), set (1), clear (2) or toggle (3).

A mask bit of one selects a pin. lanes[0] permits changes to bits 7:0 and lanes[1] to bits 15:8. Preserve every other bit. Apply both commands when commit is high. Reset clears the latch.

Examples

Example 1

Reset Edge
Input
rst_n=1'h0, commit=1'h1, op=4'h5, lanes=2'h3, mask=16'hffff
Output
value = 0x0

Reset discards both offered commands.

Example 2

Set Opposite Ends
Input
rst_n=1'h1, commit=1'h1, op=4'h5, lanes=2'h3, mask=16'h8001
Output
value = 0x8001

Both lanes set a selected pin.

Example 3

Two Commands on One Edge
Input
rst_n=1'h1, commit=1'h1, op=4'hb, lanes=2'h3, mask=16'h8003
Output
value = 0x2

The high byte clears pin 15 while the low byte toggles pins 0 and 1.

Constraints and Contract

  • Sample on each rising edge. Synchronous active-low reset wins over all other inputs. Binary inputs only.

Hints

Hint 1

Label the operation and enable above each byte.

Hint 2

Work through one selected pin for each operation.

Hint 3

Repeat with a neighboring pin that already holds one.

What the grader checks: All sixteen operation pairs and all four lane selections act on both latch values. Mixed words, walking masks and inactive commits follow.

369 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Reset Edge

Input
rst_n=1'h0, commit=1'h1, op=4'h5, lanes=2'h3, mask=16'hffff
Expected output
value = 0x0

Reset discards both offered commands.

Run samples executes all 3 public checks. Check all tests runs 369 checks on the server.

Icarus Verilog · server