R7.3.1 Clean the Controller

EasyFixIcarus Verilog + Yosys · serverReview the topic

A controller passed its bench and came to review with four Lint messages. Fix what each message points at, so that the design matches its brief.

Hardware context: A one-shot gate controller with a mode, a length, a cancel input and a one-hot status, as it arrived for review with four Lint messages. Fix the four defects that Lint points at in the gate controller.

A laser driver fires one pulse per request. The controller shot_ctl holds gate at 1 for a number of cycles, then cools down for two cycles. Its author ran one bench: mode 0 with a length of 5. The bench passed. Lint printed four messages, and the author asked for a waiver on all four.

The reviewer refused. In this design every message marks a place where the code and the brief disagree. This is a Fix problem. Read the four messages, find what each one points at, and change the design to match the brief.

The tests drive the inputs the shipped bench never tried, so a defect hidden by a cast still fails. They also run Lint on your file: it must report no WIDTH, UNUSED, UNDRIVEN or CASEINCOMPLETE message, and a lint_off waiver fails. Clean up the names and the structure as lesson R7.3 does if you like; the ports must stay.

Brief: rising-edge clk; rst_n asynchronous and active-low, after which the controller is idle. Synthesis check: the file must build on the site's synthesis flow, with shot_ctl as the top, and with no latch.

Signals in the Timeline

SignalWidthRole
script180input of each check
Full specification
The ports (keep the name and the ports)
module shot_ctl (
  input  logic       clk,
  input  logic       rst_n,      // asynchronous, active-low
  input  logic       fire,       // start a pulse; ignored unless idle
  input  logic       cancel,     // end a running pulse at this edge
  input  logic [1:0] mode,       // how len sets the pulse length
  input  logic [4:0] len,        // 1 to 31
  output logic       gate,       // 1 while the pulse runs
  output logic [2:0] status      // {cooling, running, idle}, one bit set
);
  ...
endmodule
StateAt a rising edge, from the values before the edge
idlefire = 1 starts a pulse whose length comes from mode and len at this edge. cancel is ignored.
runninggate is 1. The pulse ends after its length in cycles, or at an edge where cancel is 1. Then the cool-down starts. fire is ignored.
coolingTwo cycles, then idle. fire and cancel are ignored.
modePulse length in cycles
0len
1twice len
21
3len, the same as mode 0
OutputValue
gate1 while running
statusbit 0: idle, bit 1: running, bit 2: cooling. Exactly one bit is 1.
What Lint prints on the shipped file (Verilator 5.052, -Wall)
WIDTHTRUNC      line 19  Operator ASSIGNDLY expects 4 bits on the Assign RHS, but Assign RHS's SUB generates 32 or 6 bits.
UNUSEDSIGNAL    line 2   Signal is not used: 'cancel'
UNDRIVEN        line 4   Bits of signal are not driven: 'status'[2]
CASEINCOMPLETE  line 10  Case values incompletely covered (example pattern 0x3)

Each test resets the controller, then runs 20 steps of one edge each. The result holds status and gate after every edge.

Examples

Example 1

The Shipped Bench
Input
fire mode=0 len=5, idle inputs x8, fire mode=0 len=5, idle inputs x10
Output
status_step0 = 'b010, gate_step0 = yes, status_step1 = 'b010, gate_step1 = yes, status_step2 = 'b010, gate_step2 = yes, status_step3 = 'b010, gate_step3 = yes, status_step4 = 'b010, gate_step4 = yes, status_step5 = 'b100, gate_step5 = no, status_step6 = 'b100, gate_step6 = no, status_step7 = 'b001, gate_step7 = no, status_step8 = 'b001, gate_step8 = no, status_step9 = 'b010, gate_step9 = yes, status_step10 = 'b010, gate_step10 = yes, status_step11 = 'b010, gate_step11 = yes, status_step12 = 'b010, gate_step12 = yes, status_step13 = 'b010, gate_step13 = yes, status_step14 = 'b100, gate_step14 = no, status_step15 = 'b100, gate_step15 = no, status_step16 = 'b001, gate_step16 = no, status_step17 = 'b001, gate_step17 = no, status_step18 = 'b001, gate_step18 = no, status_step19 = 'b001, gate_step19 = no

Mode 0, length 5: gate is 1 for five cycles, then status shows cooling for two. The shipped design gets gate right here and still fails, because status bit 2 is never driven.

Example 2

A Length of 18
Input
fire mode=0 len=18, idle inputs x19
Output
status_step0 = 'b010, gate_step0 = yes, status_step1 = 'b010, gate_step1 = yes, status_step2 = 'b010, gate_step2 = yes, status_step3 = 'b010, gate_step3 = yes, status_step4 = 'b010, gate_step4 = yes, status_step5 = 'b010, gate_step5 = yes, status_step6 = 'b010, gate_step6 = yes, status_step7 = 'b010, gate_step7 = yes, status_step8 = 'b010, gate_step8 = yes, status_step9 = 'b010, gate_step9 = yes, status_step10 = 'b010, gate_step10 = yes, status_step11 = 'b010, gate_step11 = yes, status_step12 = 'b010, gate_step12 = yes, status_step13 = 'b010, gate_step13 = yes, status_step14 = 'b010, gate_step14 = yes, status_step15 = 'b010, gate_step15 = yes, status_step16 = 'b010, gate_step16 = yes, status_step17 = 'b010, gate_step17 = yes, status_step18 = 'b100, gate_step18 = no, status_step19 = 'b100, gate_step19 = no

The pulse must last 18 cycles. A 4-bit count keeps only the low bits of 17, which is 1, so the shipped pulse ends after two cycles.

Example 3

A Cancel in the Middle
Input
fire mode=0 len=9, idle inputs x3, cancel, idle inputs x4, fire mode=2 len=1, idle inputs x10
Output
status_step0 = 'b010, gate_step0 = yes, status_step1 = 'b010, gate_step1 = yes, status_step2 = 'b010, gate_step2 = yes, status_step3 = 'b010, gate_step3 = yes, status_step4 = 'b100, gate_step4 = no, status_step5 = 'b100, gate_step5 = no, status_step6 = 'b001, gate_step6 = no, status_step7 = 'b001, gate_step7 = no, status_step8 = 'b001, gate_step8 = no, status_step9 = 'b010, gate_step9 = yes, status_step10 = 'b100, gate_step10 = no, status_step11 = 'b100, gate_step11 = no, status_step12 = 'b001, gate_step12 = no, status_step13 = 'b001, gate_step13 = no, status_step14 = 'b001, gate_step14 = no, status_step15 = 'b001, gate_step15 = no, status_step16 = 'b001, gate_step16 = no, status_step17 = 'b001, gate_step17 = no, status_step18 = 'b001, gate_step18 = no, status_step19 = 'b001, gate_step19 = no

cancel arrives at step 4. gate falls at that edge and the two cool-down cycles follow. The shipped design never reads cancel.

Constraints and Contract

  • Inputs are known 0/1 values and change while clk is low. len is 1 to 31.
  • Keep the module name and the ports.

Hints

Hint 1

Take the messages one at a time. For each, ask what the brief says about that signal or that value.

Hint 2

WIDTHTRUNC: work out the longest pulse the brief allows, and count the bits its counter needs.

Hint 3

A cast or a lint_off comment removes a message and keeps the defect. The tests reach each defect through the ports, and a waiver fails the Lint check.

What the grader checks: Ten directed and twelve seeded scripts of twenty edges each are compared with an independent model after every edge. They reach long pulses, cancel, mode 3 and the cooling status. Lint runs on the file with the Lint button's rules; any WIDTH, UNUSED, UNDRIVEN or CASEINCOMPLETE message, or a lint_off waiver, fails. Other Lint messages are not graded.

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.

22 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 1 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 Shipped Bench

Input
fire mode=0 len=5, idle inputs x8, fire mode=0 len=5, idle inputs x10
Expected output
status_step0 = 'b010, gate_step0 = yes, status_step1 = 'b010, gate_step1 = yes, status_step2 = 'b010, gate_step2 = yes, status_step3 = 'b010, gate_step3 = yes, status_step4 = 'b010, gate_step4 = yes, status_step5 = 'b100, gate_step5 = no, status_step6 = 'b100, gate_step6 = no, status_step7 = 'b001, gate_step7 = no, status_step8 = 'b001, gate_step8 = no, status_step9 = 'b010, gate_step9 = yes, status_step10 = 'b010, gate_step10 = yes, status_step11 = 'b010, gate_step11 = yes, status_step12 = 'b010, gate_step12 = yes, status_step13 = 'b010, gate_step13 = yes, status_step14 = 'b100, gate_step14 = no, status_step15 = 'b100, gate_step15 = no, status_step16 = 'b001, gate_step16 = no, status_step17 = 'b001, gate_step17 = no, status_step18 = 'b001, gate_step18 = no, status_step19 = 'b001, gate_step19 = no

Mode 0, length 5: gate is 1 for five cycles, then status shows cooling for two. The shipped design gets gate right here and still fails, because status bit 2 is never driven.

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

Icarus Verilog + Yosys · server