G4.10.1 One Driver at a Time

MediumImplementIcarus Verilog + Yosys · serverReview the topic

Drive the active-low enables of four devices on a shared bus so that exactly one drives at every moment.

Hardware context: A board bus shared by a CPU, peripherals and a DMA engine through tri-state drivers, with a keeper. Decode active-low enables with a DMA override and a parking driver.

Four devices share an 8-bit board bus through tri-state drivers. Device 3 is a DMA engine. The others answer CPU reads. The bus must never float and never see two drivers, or the bus monitor flags z or x.

This is an Implement problem. Write bus_ctl. When dma is 1, device 3 drives. Otherwise, when cpu_rd is 1, device sel drives. Otherwise device 0 parks the bus by driving it. The enables are active-low: oe_n[k] = 0 lets device k drive.

The fixture builds the bus from four real tri-state drivers. It applies eight requests, one per nanosecond. After each it records the bus, and flags any bit that was x or z. The check also synthesizes the module on the site's flow and rejects any latch.

Signals in the Timeline

SignalWidthRole
script32input of each check
Full specification
The module (keep the name and the ports)
module bus_ctl (
  input  logic [1:0] sel,        // the device the CPU reads
  input  logic       cpu_rd,     // 1: the CPU is reading
  input  logic       dma,        // 1: the DMA engine (device 3) takes the bus
  output logic [3:0] oe_n        // active-low output enables: oe_n[k] = 0 lets device k drive
);
  // your design
endmodule
dmacpu_rdDevice that drivesoe_n
1any3 (DMA engine)0111
01selbit sel is 0, the others 1
000 (parks the bus)1110
Device0123
Data it drives11224488

The result fields are bus_stepK, bus_has_x_stepK and bus_has_z_stepK for the steps 0 to 7. bus_stepK shows 00 when a bit was x or z.

Examples

Example 1

The CPU Reads Every Device
Input
CPU reads 0; CPU reads 1; CPU reads 2; CPU reads 3; CPU reads 1; CPU reads 0; CPU reads 2; CPU reads 3
Output
bus_step0 = 0x11, bus_has_x_step0 = no, bus_has_z_step0 = no, bus_step1 = 0x22, bus_has_x_step1 = no, bus_has_z_step1 = no, bus_step2 = 0x44, bus_has_x_step2 = no, bus_has_z_step2 = no, bus_step3 = 0x88, bus_has_x_step3 = no, bus_has_z_step3 = no, bus_step4 = 0x22, bus_has_x_step4 = no, bus_has_z_step4 = no, bus_step5 = 0x11, bus_has_x_step5 = no, bus_has_z_step5 = no, bus_step6 = 0x44, bus_has_x_step6 = no, bus_has_z_step6 = no, bus_step7 = 0x88, bus_has_x_step7 = no, bus_has_z_step7 = no

Each read puts that device's data on the bus: 11, 22, 44 or 88. No bit is ever x or z.

Example 2

The Bus Goes Idle Between Reads
Input
CPU reads 2; idle (sel 2); CPU reads 1; idle (sel 1); CPU reads 3; idle (sel 3); idle (sel 0); CPU reads 0
Output
bus_step0 = 0x44, bus_has_x_step0 = no, bus_has_z_step0 = no, bus_step1 = 0x11, bus_has_x_step1 = no, bus_has_z_step1 = no, bus_step2 = 0x22, bus_has_x_step2 = no, bus_has_z_step2 = no, bus_step3 = 0x11, bus_has_x_step3 = no, bus_has_z_step3 = no, bus_step4 = 0x88, bus_has_x_step4 = no, bus_has_z_step4 = no, bus_step5 = 0x11, bus_has_x_step5 = no, bus_has_z_step5 = no, bus_step6 = 0x11, bus_has_x_step6 = no, bus_has_z_step6 = no, bus_step7 = 0x11, bus_has_x_step7 = no, bus_has_z_step7 = no

When nobody reads, device 0 parks the bus, so it reads 11 instead of floating.

Example 3

The DMA Engine Takes Over
Input
CPU reads 1; DMA (sel 1); DMA (sel 1); CPU reads 2; DMA (sel 2); DMA (sel 0); idle (sel 0); DMA (sel 3)
Output
bus_step0 = 0x22, bus_has_x_step0 = no, bus_has_z_step0 = no, bus_step1 = 0x88, bus_has_x_step1 = no, bus_has_z_step1 = no, bus_step2 = 0x88, bus_has_x_step2 = no, bus_has_z_step2 = no, bus_step3 = 0x44, bus_has_x_step3 = no, bus_has_z_step3 = no, bus_step4 = 0x88, bus_has_x_step4 = no, bus_has_z_step4 = no, bus_step5 = 0x88, bus_has_x_step5 = no, bus_has_z_step5 = no, bus_step6 = 0x11, bus_has_x_step6 = no, bus_has_z_step6 = no, bus_step7 = 0x88, bus_has_x_step7 = no, bus_has_z_step7 = no

While dma is 1 the bus carries 88 from device 3, whatever the CPU asks for.

Constraints and Contract

  • Inputs are known 0/1 values. Each request is held for one nanosecond and the bus is sampled at its end.
  • Keep the module name and the ports. The design is combinational.

Hints

Hint 1

Start with every enable off (all ones), then turn exactly one on. An if, else if, else chain picks exactly one branch.

Hint 2

The order of the tests is the priority: the DMA engine first, then a CPU read, then parking.

Hint 3

Active-low means 0 turns a driver on. Check the parked case too: oe_n must not be all ones.

What the grader checks: Five directed and eight seeded cases of eight requests each cover every mix of dma, cpu_rd and sel. The bus value and its x and z flags come from four real tri-state drivers. They are compared with a model written in JavaScript after every step. The synthesis check rejects a latch.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

13 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 steps and the final capstone

Report a problem with this page

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

The CPU Reads Every Device

Input
CPU reads 0; CPU reads 1; CPU reads 2; CPU reads 3; CPU reads 1; CPU reads 0; CPU reads 2; CPU reads 3
Expected output
bus_step0 = 0x11, bus_has_x_step0 = no, bus_has_z_step0 = no, bus_step1 = 0x22, bus_has_x_step1 = no, bus_has_z_step1 = no, bus_step2 = 0x44, bus_has_x_step2 = no, bus_has_z_step2 = no, bus_step3 = 0x88, bus_has_x_step3 = no, bus_has_z_step3 = no, bus_step4 = 0x22, bus_has_x_step4 = no, bus_has_z_step4 = no, bus_step5 = 0x11, bus_has_x_step5 = no, bus_has_z_step5 = no, bus_step6 = 0x44, bus_has_x_step6 = no, bus_has_z_step6 = no, bus_step7 = 0x88, bus_has_x_step7 = no, bus_has_z_step7 = no

Each read puts that device's data on the bus: 11, 22, 44 or 88. No bit is ever x or z.

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

Icarus Verilog + Yosys · server