`timescale 1ns/1ps // Independently exercise96 waiting plus3 urgent slots and every stored bit. module motor_queue_storage_tb; reg clk=0;always #20 clk=~clk; reg rst_n=0,we=0,re=0; reg [6:0] wa=0,ra=0; reg [127:0] input_word=0; wire busy,valid; wire [127:0] output_word; motor_queue_storage #(.SLOTS(99)) dut(.clk(clk),.rst_n(rst_n),.wr_req(we),.rd_req(re), .wr_slot(wa),.rd_slot(ra),.wr_data(input_word),.wr_busy(busy),.rd_data(output_word),.rd_valid(valid)); reg [127:0] expected[0:98]; integer slot,k,cycles; reg [127:0] value; task write_slot(input integer n,input [127:0] word_value); begin @(negedge clk);wa=n;input_word=word_value;we=1; @(negedge clk);we=0;cycles=0; while(busy && cycles<10)begin @(negedge clk);cycles=cycles+1;end if(busy || cycles!=4)$fatal(1,"four-word write completion %0d",cycles); end endtask task read_slot(input integer n); begin @(negedge clk);ra=n;re=1;@(negedge clk);re=0;cycles=0; while(!valid && cycles<20)begin @(negedge clk);cycles=cycles+1;end if(!valid || cycles!=5 || output_word!==expected[n]) $fatal(1,"serial queue slot%0d cycles%0d data%032h expected%032h",n,cycles,output_word,expected[n]); end endtask initial begin repeat(4)@(negedge clk);rst_n=1; for(slot=0;slot<99;slot=slot+1)begin value=0;value[7:0]=slot<96 ? slot/32 : slot-96;value[15:8]=slot%5; value[23:16]=8'h0A | (slot[0] ? 8'h05 : 8'h00); value[63:32]=32'h80000001 ^ (slot*32'h1020101); value[95:64]=32'hFFFFFFFF-slot*1024;value[111:96]=16'hA500+slot; expected[slot]=value; write_slot(slot,value); end for(slot=98;slot>=0;slot=slot-1)read_slot(slot); // Walk every one of the 128 stored bits in the last address slot. for(k=0;k<128;k=k+1)begin value=128'd1<