motor_queue_storage_tb.v 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. `timescale 1ns/1ps
  2. // Independently exercise96 waiting plus3 urgent slots and every stored bit.
  3. module motor_queue_storage_tb;
  4. reg clk=0;always #20 clk=~clk;
  5. reg rst_n=0,we=0,re=0;
  6. reg [6:0] wa=0,ra=0;
  7. reg [127:0] input_word=0;
  8. wire busy,valid;
  9. wire [127:0] output_word;
  10. motor_queue_storage #(.SLOTS(99)) dut(.clk(clk),.rst_n(rst_n),.wr_req(we),.rd_req(re),
  11. .wr_slot(wa),.rd_slot(ra),.wr_data(input_word),.wr_busy(busy),.rd_data(output_word),.rd_valid(valid));
  12. reg [127:0] expected[0:98];
  13. integer slot,k,cycles;
  14. reg [127:0] value;
  15. task write_slot(input integer n,input [127:0] word_value);
  16. begin
  17. @(negedge clk);wa=n;input_word=word_value;we=1;
  18. @(negedge clk);we=0;cycles=0;
  19. while(busy && cycles<10)begin @(negedge clk);cycles=cycles+1;end
  20. if(busy || cycles!=4)$fatal(1,"four-word write completion %0d",cycles);
  21. end
  22. endtask
  23. task read_slot(input integer n);
  24. begin
  25. @(negedge clk);ra=n;re=1;@(negedge clk);re=0;cycles=0;
  26. while(!valid && cycles<20)begin @(negedge clk);cycles=cycles+1;end
  27. if(!valid || cycles!=5 || output_word!==expected[n])
  28. $fatal(1,"serial queue slot%0d cycles%0d data%032h expected%032h",n,cycles,output_word,expected[n]);
  29. end
  30. endtask
  31. initial begin
  32. repeat(4)@(negedge clk);rst_n=1;
  33. for(slot=0;slot<99;slot=slot+1)begin
  34. value=0;value[7:0]=slot<96 ? slot/32 : slot-96;value[15:8]=slot%5;
  35. value[23:16]=8'h0A | (slot[0] ? 8'h05 : 8'h00);
  36. value[63:32]=32'h80000001 ^ (slot*32'h1020101);
  37. value[95:64]=32'hFFFFFFFF-slot*1024;value[111:96]=16'hA500+slot;
  38. expected[slot]=value;
  39. write_slot(slot,value);
  40. end
  41. for(slot=98;slot>=0;slot=slot-1)read_slot(slot);
  42. // Walk every one of the 128 stored bits in the last address slot.
  43. for(k=0;k<128;k=k+1)begin
  44. value=128'd1<<k;
  45. expected[98]=value;write_slot(98,value);read_slot(98);
  46. end
  47. // Write one slot while the other port reads a different valid slot.
  48. expected[31]=128'h0000BEEFCAFEBABE89ABCDEF00050000;
  49. @(negedge clk);wa=31;input_word=expected[31];we=1;ra=32;re=1;
  50. @(negedge clk);we=0;re=0;wait(valid);@(negedge clk);
  51. if(output_word!==expected[32])$fatal(1,"independent queue read/write ports interfered");
  52. read_slot(31);read_slot(32);
  53. $display("QUEUE_WAITING_SLOTS=96 URGENT_SLOTS=3 STORED_BITS=128 WRITE_CLOCKS=4 READ_CLOCKS=5");
  54. $display("motor_queue_storage_tb PASS");$finish;
  55. end
  56. initial begin #1000000;$fatal(1,"queue storage bounded deadline");end
  57. endmodule