e1_crc4_tb.v 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * e1_crc4_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 e1_crc4_tb;
  28. // Signals
  29. reg rst = 1;
  30. reg clk = 1;
  31. reg [31:0] data;
  32. wire in_bit;
  33. reg in_valid;
  34. reg in_first;
  35. wire [3:0] crc;
  36. // Setup recording
  37. initial begin
  38. $dumpfile("e1_crc4_tb.vcd");
  39. $dumpvars(0,e1_crc4_tb);
  40. end
  41. // Reset pulse
  42. initial begin
  43. # 31 rst = 0;
  44. # 20000 $finish;
  45. end
  46. // Clocks
  47. always #5 clk = !clk;
  48. // DUT
  49. e1_crc4 dut_I (
  50. .in_bit(in_bit),
  51. .in_first(in_first),
  52. .in_valid(in_valid),
  53. .out_crc4(crc),
  54. .clk(clk),
  55. .rst(rst)
  56. );
  57. // Data feed
  58. always @(posedge clk)
  59. if (rst)
  60. in_valid <= 1'b0;
  61. else
  62. in_valid <= 1'b1;
  63. always @(posedge clk)
  64. if (rst)
  65. in_first <= 1'b1;
  66. else if (in_valid)
  67. in_first <= 1'b0;
  68. always @(posedge clk)
  69. if (rst)
  70. //data <= 32'h600dbabe;
  71. data <= 32'h0badbabe;
  72. else if (in_valid)
  73. data <= { data[31:0], 1'b0 };
  74. assign in_bit = data[31];
  75. endmodule // e1_crc4_tb