Wire everything from Module 6 into one block. You build a valid-ready transfer controller that accepts bytes from a source interface, buffers them, and forwards to a sink — all driven by a 3-state Moore FSM with safe defaults and a self-checking testbench.
Produce a synthesizable proto_xfer_ctrl module plus testbench you can paste into the EcrioniX Verilog simulator and run immediately. This is the Module 6 checkpoint.
Accept from source when buffer empty; forward to sink when sink is ready.
| State | Moore outputs | Transition |
|---|---|---|
IDLE | s_ready=1, m_valid=0 | s_valid → HOLD (latch data) |
HOLD | s_ready=0, m_valid=1 | m_ready → IDLE (xfer done) |
2'b11 etc. | safe low outputs | default → IDLE |
s_valid, s_data[7:0] in; s_ready outm_valid, m_data[7:0] out; m_ready ins_valid && s_ready; sink xfer = m_valid && m_readydefault: next = IDLETwo-state core FSM — simplest protocol controller. HOLD until sink accepts.
localparam IDLE = 2'd0;
localparam HOLD = 2'd1;
reg [1:0] state, next;
// Block 1: state + data register
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
state <= IDLE;
data_reg <= 8'h00;
end else begin
state <= next;
if (state == IDLE && s_valid && s_ready)
data_reg <= s_data;
end
end
// Block 2: next-state
always @(*) begin
next = IDLE;
case (state)
IDLE: if (s_valid) next = HOLD;
HOLD: if (m_ready) next = IDLE;
default: next = IDLE;
endcase
end
// Block 3: Moore outputs
assign s_ready = (state == IDLE);
assign m_valid = (state == HOLD);
assign m_data = data_reg;
s_ready must NOT depend on s_valid. It depends only on state == IDLE. Same for m_valid — only from state, not m_ready.
// proto_xfer_ctrl — Module 6.7 lab DUT
// Valid-ready byte pipe: source → buffer → sink
module proto_xfer_ctrl (
input wire clk,
input wire rst_n,
// Source (we are sink to source)
input wire s_valid,
input wire [7:0] s_data,
output wire s_ready,
// Sink (we are source to sink)
output wire m_valid,
output wire [7:0] m_data,
input wire m_ready
);
localparam IDLE = 2'd0;
localparam HOLD = 2'd1;
reg [1:0] state, next;
reg [7:0] data_reg;
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
state <= IDLE;
data_reg <= 8'h00;
end else begin
state <= next;
if (state == IDLE && s_valid && s_ready)
data_reg <= s_data;
end
end
always @(*) begin
next = IDLE;
case (state)
IDLE: if (s_valid) next = HOLD;
HOLD: if (m_ready) next = IDLE;
default: next = IDLE;
endcase
end
assign s_ready = (state == IDLE);
assign m_valid = (state == HOLD);
assign m_data = data_reg;
endmodule
module proto_xfer_ctrl_tb;
reg clk, rst_n;
reg s_valid, m_ready;
reg [7:0] s_data;
wire s_ready, m_valid;
wire [7:0] m_data;
proto_xfer_ctrl dut (
.clk(clk), .rst_n(rst_n),
.s_valid(s_valid), .s_data(s_data), .s_ready(s_ready),
.m_valid(m_valid), .m_data(m_data), .m_ready(m_ready)
);
initial clk = 0;
always #5 clk = ~clk;
integer errors, bytes_rcvd;
reg [7:0] expect;
initial begin
errors = 0; bytes_rcvd = 0;
rst_n = 0; s_valid = 0; s_data = 0; m_ready = 1;
#20 rst_n = 1;
// Test 1: single byte
@(posedge clk); s_valid = 1; s_data = 8'hA5;
@(posedge clk); s_valid = 0;
wait(m_valid); expect = 8'hA5;
if (m_data !== expect) begin
$display("FAIL: got %h expected %h", m_data, expect);
errors = errors + 1;
end else $display("PASS: single byte 0xA5");
@(posedge clk);
// Test 2: back-pressure (m_ready low)
m_ready = 0;
@(posedge clk); s_valid = 1; s_data = 8'h3C;
@(posedge clk); s_valid = 0;
repeat(3) @(posedge clk);
if (!m_valid) begin $display("FAIL: m_valid should be high"); errors++; end
m_ready = 1;
@(posedge clk);
if (m_data !== 8'h3C) begin $display("FAIL: back-pressure byte"); errors++; end
else $display("PASS: back-pressure byte 0x3C");
// Test 3: two bytes back-to-back
m_ready = 1;
@(posedge clk); s_valid = 1; s_data = 8'h11;
@(posedge clk); s_valid = 1; s_data = 8'h22;
wait(m_valid && m_ready); @(posedge clk);
wait(m_valid && m_ready);
if (m_data !== 8'h22) begin $display("FAIL: second byte"); errors++; end
else $display("PASS: back-to-back");
if (errors == 0) $display("=== ALL TESTS PASSED ===");
else $display("=== %0d TESTS FAILED ===", errors);
$finish;
end
endmodule
Add a second buffer slot so s_ready=1 in HOLD if one slot free — throughput boost.
Add byte_count output that increments on each successful sink transfer.
Force state=2'b11 and verify recovery to IDLE within 1 cycle.
defaultModule 7 is next: Datapath & Memory Systems — skid buffers, FIFOs, and tying control FSMs to real datapaths.
ready from state; valid from state — never cross-combine.