QuadSPImTb.v 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. reg [31:0] data;
  11. wire [1:0] widthSel = 2'h2;
  12. wire clockPol = 1'b0;
  13. wire clockPhase = 1'b0;
  14. wire endianSel = 1'b0;
  15. wire lag = 1'b0;
  16. wire leadx = 1'b0;
  17. wire [5:0] stopDelay = 6'h0;
  18. wire selSt = 1'b1;
  19. wire val;
  20. reg [31:0] tbCnt;
  21. wire start = (tbCnt>=100);
  22. wire fifoEmpty = (data > 32'h29);
  23. //================================================================================
  24. // ASSIGNMENTS
  25. //================================================================================
  26. //================================================================================
  27. // CODING
  28. //================================================================================
  29. always #(CLK_PERIOD/2) clk = ~clk;
  30. initial begin
  31. clk = 0;
  32. rst = 0;
  33. #40
  34. rst = 1;
  35. #100
  36. rst = 0;
  37. end
  38. always @(posedge clk) begin
  39. if (rst) begin
  40. tbCnt <= 0;
  41. end else begin
  42. tbCnt <= tbCnt+1;
  43. end
  44. end
  45. always @(posedge clk) begin
  46. if (rst) begin
  47. data <= startData;
  48. end else if (val) begin
  49. data <= data+10;
  50. end
  51. end
  52. QuadSPIm QuadSPIm
  53. (
  54. .Clk_i(clk),
  55. .Start_i(start),
  56. .Rst_i(rst),
  57. .EmptyFlag_i(fifoEmpty),
  58. .SpiData_i(data),
  59. .Sck_o(),
  60. .Ss_o(),
  61. .Mosi0_o(),
  62. .Mosi1_o(),
  63. .Mosi2_o(),
  64. .Mosi3_o(),
  65. .WidthSel_i(widthSel),
  66. .PulsePol_i(clockPol),
  67. .ClockPhase_i(clockPhase),
  68. .EndianSel_i(endianSel),
  69. .Lag_i(lag),
  70. .Lead_i(leadx),
  71. .Stop_i(stopDelay),
  72. .SelSt_i(selSt),
  73. .Val_o(val)
  74. );
  75. endmodule