mc97_fifo.v 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * mc97_fifo.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2021 Sylvain Munaut <tnt@246tNt.com>
  7. * SPDX-License-Identifier: CERN-OHL-P-2.0
  8. */
  9. `default_nettype none
  10. module mc97_fifo (
  11. // Write
  12. input wire [15:0] wr_data,
  13. input wire wr_ena,
  14. output wire wr_full,
  15. // Read
  16. output wire [15:0] rd_data,
  17. input wire rd_ena,
  18. output wire rd_empty,
  19. // Control
  20. output reg [ 8:0] ctl_lvl,
  21. input wire ctl_flush,
  22. // Clock / Reset
  23. input wire clk,
  24. input wire rst
  25. );
  26. // Signals
  27. // -------
  28. (* keep *) reg [8:0] mod;
  29. wire wr_ena_i;
  30. wire rd_ena_i;
  31. // FIFO Instance
  32. // -------------
  33. fifo_sync_ram #(
  34. .DEPTH(256),
  35. .WIDTH(16)
  36. ) fifo_I (
  37. .wr_data (wr_data),
  38. .wr_ena (wr_ena_i),
  39. .wr_full (wr_full),
  40. .rd_data (rd_data),
  41. .rd_ena (rd_ena_i),
  42. .rd_empty (rd_empty),
  43. .clk (clk),
  44. .rst (rst)
  45. );
  46. // Control
  47. // -------
  48. assign wr_ena_i = ~wr_full & wr_ena ;
  49. assign rd_ena_i = ~rd_empty & (rd_ena | ctl_flush);
  50. // Level
  51. // -----
  52. // Level counter
  53. always @(posedge clk)
  54. if (rst)
  55. ctl_lvl <= 0;
  56. else
  57. ctl_lvl <= ctl_lvl + mod;
  58. assign mod = { {8{rd_ena_i & ~wr_ena_i}}, rd_ena_i ^ wr_ena_i };
  59. endmodule // mc97_fifo