Codiode

Arbiter FSM with Fixed Priority

HardVerilog / SystemVerilogBuild

When two agents ask for a shared bus in the same cycle, an arbiter grants it to exactly one. Here the priority is fixed.

The solution module receives access requests from two agents, A and B. It grants access to one agent at a time. If both agents request access while the arbiter is idle, agent A receives the grant due to its higher fixed priority. Once an agent receives the grant, it retains ownership of the resource until it drops its request. The arbiter is non-preemptive; if agent B holds the grant, agent A cannot steal it, even if agent A asserts its request. When the current owner drops its request, the arbiter can immediately grant access to a pending request on the next clock cycle without passing through an idle state.

The module operates on a positive-edge triggered clock clk and an active-low synchronous reset rst_n. On reset, both grants are driven to 0 and the FSM enters the IDLE state. Outputs must be registered (Moore machine configuration) and reflect the current state of the FSM, meaning there is a one-cycle delay from a request being evaluated to the grant being asserted.

Cycle-by-cycle trace for simultaneous requests and non-preemption:

  • Cycle 1: rst_n=0 → state=IDLE, gnt_a=0, gnt_b=0
  • Cycle 2: rst_n=1, req_a=1, req_b=1 → priority A wins, state goes to GRANT_A
  • Cycle 3: gnt_a=1, gnt_b=0 → state=GRANT_A. Both still requesting
  • Cycle 4: req_a=0, req_b=1 → A drops request, state transitions to GRANT_B
  • Cycle 5: gnt_a=0, gnt_b=1 → state=GRANT_B. A requests again, but B holds grant (non-preemptive)
  • Cycle 6: req_a=1, req_b=0 → B drops request, state transitions to GRANT_A
  • Cycle 7: gnt_a=1, gnt_b=0 → state=GRANT_A. A drops request, state transitions to IDLE
  • Cycle 8: gnt_a=0, gnt_b=0 → state=IDLE
Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst_n input 1 Synchronous active-low reset; FSM goes to IDLE and grants go to 0
req_a input 1 Request from agent A
req_b input 1 Request from agent B
gnt_a output 1 Grant for agent A; 1 when FSM is in GRANT_A state
gnt_b output 1 Grant for agent B; 1 when FSM is in GRANT_B state

Constraints

  • The reset must be synchronous and active-low.
  • The FSM must be implemented as a Moore machine (outputs depend only on the current state).
  • If both requests arrive in the IDLE state, agent A must receive the grant.
  • The arbiter must be non-preemptive; an agent retains its grant as long as its request remains high, regardless of the other agent.
  • The arbiter must be capable of handing off the grant directly from agent A to agent B (and vice versa) without passing through the IDLE state.

Topics

sequentialfsmpriorityarbiter

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of FSM Coding

Problem 13 of 15 in the FSM Coding track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.