QuadSPImTb.v 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. `timescale 1ns / 1ps
  2. module QuadSPImTb ();
  3. parameter CLK_PERIOD = 8.13; // Clock period in ns
  4. //================================================================================
  5. // REG/WIRE
  6. //================================================================================
  7. reg rst;
  8. reg clk;
  9. localparam [31:0] startData = 32'h1;
  10. // localparam [31:0] startData = 32'h0A0B0C0D;
  11. reg [31:0] data;
  12. reg [31:0] dataS;
  13. wire [1:0] widthSel = 2'h3;
  14. wire clockPol = 1'b0;
  15. wire clockPhase = 1'b0;
  16. wire endianSel = 1'b0;
  17. wire lag = 1'b0;
  18. wire lead = 1'b0;
  19. wire [5:0] stopDelay = 6'h0;
  20. wire selSt = 1'b1;
  21. wire val;
  22. wire valS;
  23. reg [31:0] tbCnt;
  24. wire start = (tbCnt>=100);
  25. wire fifoEmpty = (tbCnt >= 500);
  26. //================================================================================
  27. // ASSIGNMENTS
  28. //================================================================================
  29. //================================================================================
  30. // CODING
  31. //================================================================================
  32. always #(CLK_PERIOD/2) clk = ~clk;
  33. initial begin
  34. clk = 0;
  35. rst = 0;
  36. #40
  37. rst = 1;
  38. #100
  39. rst = 0;
  40. end
  41. always @(posedge clk) begin
  42. if (rst) begin
  43. tbCnt <= 0;
  44. end else begin
  45. tbCnt <= tbCnt+1;
  46. end
  47. end
  48. always @(posedge clk) begin
  49. if (rst) begin
  50. data <= startData;
  51. end else if (val) begin
  52. data <= data+32'h1000;
  53. end
  54. end
  55. always @(posedge clk) begin
  56. if (rst) begin
  57. dataS <= startData;
  58. end else if (valS) begin
  59. dataS <= dataS+32'h1000;
  60. end
  61. end
  62. QuadSPIm QuadSPIm
  63. (
  64. .Clk_i(clk),
  65. .Start_i(start),
  66. .Rst_i(rst),
  67. .EmptyFlag_i(fifoEmpty),
  68. .SpiData_i(data),
  69. .Sck_o(),
  70. .Ss_o(),
  71. .Mosi0_o(),
  72. .Mosi1_o(),
  73. .Mosi2_o(),
  74. .Mosi3_o(),
  75. .WidthSel_i(widthSel),
  76. .PulsePol_i(clockPol),
  77. .ClockPhase_i(clockPhase),
  78. .EndianSel_i(endianSel),
  79. .Lag_i(lag),
  80. .Lead_i(lead),
  81. .Stop_i(stopDelay),
  82. .SelSt_i(selSt),
  83. .Val_o(val)
  84. );
  85. SPIm Spi
  86. (
  87. .Clk_i (clk),
  88. .Rst_i (rst),
  89. .Start_i (start),
  90. .EmptyFlag_i (fifoEmpty),
  91. .ClockPhase_i (clockPol),
  92. .SpiData_i (dataS),
  93. .SelSt_i (selSt),
  94. .WidthSel_i (widthSel),
  95. .Lag_i (lag),
  96. .Lead_i (lead),
  97. .EndianSel_i (endianSel),
  98. .Stop_i (stopDelay),
  99. .PulsePol_i (clockPol),
  100. .Mosi0_o (),
  101. .Sck_o (),
  102. .Ss_o (),
  103. .Val_o (valS)
  104. );
  105. endmodule