dsi_tb.v 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * dsi_tb.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * BSD 3-clause, see LICENSE.bsd
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * * Neither the name of the <organization> nor the
  19. * names of its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. `default_nettype none
  34. `timescale 1ns / 100ps
  35. module dsi_tb;
  36. // Signals
  37. reg rst = 1'b1;
  38. reg clk = 1'b0;
  39. // PHY
  40. output wire clk_lp;
  41. output wire clk_hs_p;
  42. output wire clk_hs_n;
  43. output wire data_lp;
  44. output wire data_hs_p;
  45. output wire data_hs_n;
  46. // Packet interface
  47. wire hs_clk_req;
  48. wire hs_clk_rdy;
  49. wire hs_clk_sync;
  50. wire hs_start;
  51. wire [7:0] hs_data;
  52. wire hs_last;
  53. wire hs_ack;
  54. reg [7:0] cnt;
  55. reg in_pkt;
  56. // Setup recording
  57. initial begin
  58. $dumpfile("dsi_tb.vcd");
  59. $dumpvars(0,dsi_tb);
  60. end
  61. // Reset pulse
  62. initial begin
  63. # 200 rst = 0;
  64. # 1000000 $finish;
  65. end
  66. // Clocks
  67. always #10 clk = !clk;
  68. // DUT
  69. nano_dsi_clk dsi_clk_I (
  70. .clk_lp(clk_lp),
  71. .clk_hs_p(clk_hs_p),
  72. .clk_hs_n(clk_hs_n),
  73. .hs_req(hs_clk_req),
  74. .hs_rdy(hs_clk_rdy),
  75. .clk_sync(hs_clk_sync),
  76. .cfg_hs_prep(8'h10),
  77. .cfg_hs_zero(8'h10),
  78. .cfg_hs_trail(8'h10),
  79. .clk(clk),
  80. .rst(rst)
  81. );
  82. nano_dsi_data dsi_data_I (
  83. .data_lp(data_lp),
  84. .data_hs_p(data_hs_p),
  85. .data_hs_n(data_hs_n),
  86. .hs_start(hs_start),
  87. .hs_data(hs_data),
  88. .hs_last(hs_last),
  89. .hs_ack(hs_ack),
  90. .clk_sync(hs_clk_sync),
  91. .cfg_hs_prep(8'h10),
  92. .cfg_hs_zero(8'h10),
  93. .cfg_hs_trail(8'h10),
  94. .clk(clk),
  95. .rst(rst)
  96. );
  97. // Packet generator
  98. always @(posedge clk)
  99. if (rst)
  100. cnt <= 0;
  101. else
  102. cnt <= cnt + (!in_pkt || hs_ack);
  103. always @(posedge clk)
  104. if (rst)
  105. in_pkt <= 1'b0;
  106. else
  107. in_pkt <= (in_pkt | hs_start) & ~(hs_last & hs_ack);
  108. assign hs_clk_req = (cnt != 8'h00);
  109. assign hs_start = (cnt == 8'h0f);
  110. assign hs_data = cnt;
  111. assign hs_last = (cnt == 8'h1f);
  112. endmodule // dsi_tb