hdb3_tb.v 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * hdb3_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. * LGPL v3+, see LICENSE.lgpl3
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 3 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with this program; if not, write to the Free Software Foundation,
  23. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. `default_nettype none
  26. `timescale 1ns / 100ps
  27. module hdb3_tb;
  28. // Signals
  29. reg rst = 1;
  30. reg clk = 0;
  31. reg in_data;
  32. reg in_valid;
  33. wire hdb3_pos;
  34. wire hdb3_neg;
  35. wire hdb3_valid;
  36. wire out_data;
  37. wire out_valid;
  38. reg [31:0] data;
  39. wire out_data_ref;
  40. wire out_data_err;
  41. // Setup recording
  42. initial begin
  43. $dumpfile("hdb3_tb.vcd");
  44. $dumpvars(0,hdb3_tb);
  45. end
  46. // Reset pulse
  47. initial begin
  48. # 31 rst = 0;
  49. # 10000 $finish;
  50. end
  51. // Clocks
  52. always #5 clk = !clk;
  53. // DUT
  54. hdb3_enc dut_enc_I (
  55. .in_data(in_data),
  56. .in_valid(in_valid),
  57. .out_pos(hdb3_pos),
  58. .out_neg(hdb3_neg),
  59. .out_valid(hdb3_valid),
  60. .clk(clk),
  61. .rst(rst)
  62. );
  63. hdb3_dec dut_dec_I (
  64. .in_pos(hdb3_pos),
  65. .in_neg(hdb3_neg),
  66. .in_valid(hdb3_valid),
  67. .out_data(out_data),
  68. .out_valid(out_valid),
  69. .clk(clk),
  70. .rst(rst)
  71. );
  72. // Data feed
  73. always @(posedge clk)
  74. begin
  75. if (rst) begin
  76. in_data <= 1'b0;
  77. in_valid <= 1'b0;
  78. data <= 32'h6ac0c305;
  79. end else begin
  80. in_data <= data[0];
  81. in_valid <= 1'b1;
  82. data <= { data[0], data[31:1] };
  83. end
  84. end
  85. assign out_data_ref = data[23];
  86. assign out_data_err = out_data_ref != out_data;
  87. endmodule // hdb3_tb