2020-02-02 21:35:15 -05:00
|
|
|
// A stimulus file provides inputs signals to the design under test (DUT).
|
|
|
|
// This stimulus module is designed to be compatible with verilog simulators,
|
2020-02-02 23:11:29 -05:00
|
|
|
// emulators, and FPGA prototyping. This is akin to a simple test vector generator
|
|
|
|
// No looping supported!
|
2020-02-02 21:35:15 -05:00
|
|
|
//
|
|
|
|
// Memory format:
|
2020-02-03 13:19:55 -05:00
|
|
|
// b0 = valid,
|
|
|
|
// b1-7 = wait time
|
|
|
|
// b8-bxxx = packet
|
2020-02-02 21:35:15 -05:00
|
|
|
//
|
2020-02-02 23:11:29 -05:00
|
|
|
// Test Process:
|
|
|
|
// 1. Zero out memory (or write program)
|
|
|
|
// 2. Set go signal
|
|
|
|
//
|
2020-02-03 13:19:55 -05:00
|
|
|
module stimulus #( parameter DW = 32, // Memory width=DW+
|
|
|
|
parameter MAW = 15, // Memory address width
|
|
|
|
parameter HEXFILE = "NONE" // Name of hex file
|
2020-02-02 23:11:29 -05:00
|
|
|
)
|
|
|
|
(
|
2020-02-03 13:19:55 -05:00
|
|
|
//Asynchronous Stimulus Reset
|
|
|
|
input nreset,
|
|
|
|
input ext_start, // Start driving stimulus
|
2020-02-06 12:50:34 -05:00
|
|
|
input use_timestamps,//b1-7 used for timestamps
|
|
|
|
input ignore_valid,//b0 valid bit ignored
|
2020-02-03 13:19:55 -05:00
|
|
|
//External Load port
|
2020-02-02 23:11:29 -05:00
|
|
|
input ext_clk,// External clock for write path
|
|
|
|
input ext_access, // Valid packet for memory
|
2020-02-03 13:19:55 -05:00
|
|
|
input [DW-1:0] ext_packet, // Packet for memory
|
2020-02-02 23:11:29 -05:00
|
|
|
//DUT Drive port
|
|
|
|
input dut_clk, // DUT side clock
|
|
|
|
input dut_wait, // DUT stall signal
|
|
|
|
output stim_access, // Access signal
|
2020-02-03 13:19:55 -05:00
|
|
|
output [DW-1:0] stim_packet, // Packet
|
2020-02-02 23:11:29 -05:00
|
|
|
output stim_done // Stimulus program done
|
|
|
|
);
|
2020-02-02 21:35:15 -05:00
|
|
|
|
2020-02-02 23:11:29 -05:00
|
|
|
localparam MD = 1<<MAW; // Memory depth
|
2020-02-02 21:35:15 -05:00
|
|
|
|
2020-02-02 23:11:29 -05:00
|
|
|
//Registers
|
2020-02-04 22:42:41 -05:00
|
|
|
reg [DW-1:0] ram[0:MD-1];
|
2020-02-03 13:19:55 -05:00
|
|
|
reg [1:0] rd_state;
|
2020-02-02 23:11:29 -05:00
|
|
|
reg [MAW-1:0] wr_addr;
|
|
|
|
reg [MAW-1:0] rd_addr;
|
|
|
|
reg [255:0] memhfile;
|
2020-02-03 13:19:55 -05:00
|
|
|
reg [1:0] sync_pipe;
|
|
|
|
reg [6:0] rd_delay;
|
|
|
|
reg [DW-1:0] stim_packet;
|
|
|
|
reg stim_read;
|
|
|
|
|
2020-02-02 23:11:29 -05:00
|
|
|
//#################################
|
|
|
|
// Init memory if configured
|
|
|
|
//#################################
|
|
|
|
generate
|
2020-02-03 13:19:55 -05:00
|
|
|
if(!(HEXFILE=="NONE"))
|
2020-02-02 23:11:29 -05:00
|
|
|
initial
|
|
|
|
begin
|
2020-02-03 13:19:55 -05:00
|
|
|
$display("Initializing STIMULUS from %s", HEXFILE);
|
|
|
|
$readmemh(HEXFILE, ram);
|
2020-02-02 23:11:29 -05:00
|
|
|
end
|
|
|
|
endgenerate
|
2015-11-03 14:16:50 -05:00
|
|
|
|
2020-02-02 23:11:29 -05:00
|
|
|
//#################################
|
|
|
|
// Write port state machine
|
|
|
|
//#################################
|
2015-11-03 14:16:50 -05:00
|
|
|
|
2020-02-02 23:11:29 -05:00
|
|
|
always @ (posedge ext_clk or negedge nreset)
|
|
|
|
if(!nreset)
|
2020-02-03 13:19:55 -05:00
|
|
|
wr_addr[MAW-1:0] <= 'b0;
|
2020-02-02 23:11:29 -05:00
|
|
|
else if(ext_access)
|
2020-02-03 13:19:55 -05:00
|
|
|
wr_addr[MAW-1:0] <= wr_addr[MAW-1:0] + 1;
|
|
|
|
|
|
|
|
//Synchronize ext_start to dut_clk domain
|
|
|
|
always @ (posedge dut_clk or negedge nreset)
|
|
|
|
if(!nreset)
|
|
|
|
sync_pipe[1:0] <= 1'b0;
|
|
|
|
else
|
|
|
|
sync_pipe[1:0] <= {sync_pipe[0],ext_start};
|
|
|
|
assign dut_start = sync_pipe[1];
|
|
|
|
|
2020-02-02 23:11:29 -05:00
|
|
|
//#################################
|
|
|
|
// Read port state machine
|
|
|
|
//#################################
|
|
|
|
//1. Start on dut_start
|
2020-02-03 13:19:55 -05:00
|
|
|
//2. After thar update rd state machine on all not stall and not wait
|
|
|
|
//3. Set end state on special end packet
|
2020-02-02 23:11:29 -05:00
|
|
|
|
2020-02-03 13:19:55 -05:00
|
|
|
`define STIM_IDLE 2'b00
|
|
|
|
`define STIM_ACTIVE 2'b01
|
|
|
|
`define STIM_PAUSE 2'b10
|
|
|
|
`define STIM_DONE 2'b11
|
2015-11-03 19:56:27 -05:00
|
|
|
|
2020-02-03 13:19:55 -05:00
|
|
|
always @ (posedge dut_clk or negedge nreset)
|
|
|
|
if(!nreset)
|
2015-11-03 19:56:27 -05:00
|
|
|
begin
|
2020-02-03 13:19:55 -05:00
|
|
|
rd_state[1:0] <= `STIM_IDLE;
|
|
|
|
rd_addr[MAW-1:0] <= 'b0;
|
|
|
|
rd_delay[6:0] <= 'b0;
|
2015-11-03 19:56:27 -05:00
|
|
|
end
|
|
|
|
else if(~dut_wait)
|
2020-02-03 13:19:55 -05:00
|
|
|
case (rd_state[1:0])
|
|
|
|
`STIM_IDLE :
|
|
|
|
rd_state[1:0] <= dut_start ? `STIM_ACTIVE : `STIM_IDLE;
|
|
|
|
`STIM_ACTIVE :
|
|
|
|
begin
|
|
|
|
rd_state[1:0] <= (|rd_delay[6:0]) ? `STIM_PAUSE :
|
2020-02-06 12:50:34 -05:00
|
|
|
~stim_valid ? `STIM_DONE :
|
2020-02-03 13:19:55 -05:00
|
|
|
`STIM_ACTIVE;
|
|
|
|
rd_addr[MAW-1:0] <= rd_addr[MAW-1:0] + 1'b1;
|
2020-02-06 12:50:34 -05:00
|
|
|
rd_delay[6:0] <= {(7){use_timestamps}} & stim_packet[7:1];
|
2020-02-03 13:19:55 -05:00
|
|
|
end
|
|
|
|
`STIM_PAUSE :
|
|
|
|
begin
|
|
|
|
rd_state[1:0] <= (|rd_delay[6:0]) ? `STIM_PAUSE : `STIM_ACTIVE;
|
|
|
|
rd_delay[6:0] <= rd_delay[6:0] - 1'b1;
|
|
|
|
end
|
|
|
|
endcase // case (rd_state[1:0])
|
2015-11-03 14:16:50 -05:00
|
|
|
|
2020-02-03 13:19:55 -05:00
|
|
|
//Output Driver
|
|
|
|
assign stim_done = (rd_state[1:0] == `STIM_DONE);
|
2020-02-06 12:50:34 -05:00
|
|
|
assign stim_valid = ignore_valid | stim_packet[0];
|
|
|
|
|
2020-02-03 13:19:55 -05:00
|
|
|
//#################################
|
|
|
|
// RAM
|
|
|
|
//#################################
|
2015-11-03 14:16:50 -05:00
|
|
|
|
2020-02-03 13:19:55 -05:00
|
|
|
//write port
|
|
|
|
always @(posedge ext_clk)
|
|
|
|
if(ext_access)
|
|
|
|
ram[wr_addr[MAW-1:0]] <= ext_packet[DW-1:0];
|
2015-11-03 14:16:50 -05:00
|
|
|
|
2020-02-03 13:19:55 -05:00
|
|
|
//read port
|
|
|
|
always @ (posedge dut_clk)
|
|
|
|
begin
|
|
|
|
stim_packet[DW-1:0] <= ram[rd_addr[MAW-1:0]];
|
|
|
|
stim_read <= (rd_state==`STIM_ACTIVE); //mem-cycle adjust
|
|
|
|
end
|
|
|
|
|
|
|
|
//Shut off access immediately, but pipeline delay by one cycle
|
2020-02-06 12:50:34 -05:00
|
|
|
assign stim_access = stim_valid & stim_read & ~stim_done;
|
2020-02-03 13:19:55 -05:00
|
|
|
|
|
|
|
endmodule // stimulus
|
|
|
|
|
|
|
|
|