fifo_async.v 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. module fifo_async #(parameter DATA_WIDTH = 16, ADDR_WIDTH = 4)
  2. (
  3. input reset_n,
  4. input wr_clk,
  5. input wr_en,
  6. input [DATA_WIDTH - 1 : 0] wr_data,
  7. output full,
  8. input rd_clk,
  9. input rd_en,
  10. output [DATA_WIDTH - 1 : 0] rd_data,
  11. output empty
  12. );
  13. wire [ADDR_WIDTH - 1 : 0] rd_ptr;
  14. wire [ADDR_WIDTH - 1 : 0] rd_ptr_gray;
  15. wire [ADDR_WIDTH - 1 : 0] rd_ptr_gray_sync;
  16. wire [ADDR_WIDTH - 1 : 0] wr_ptr;
  17. wire [ADDR_WIDTH - 1 : 0] wr_ptr_gray;
  18. wire [ADDR_WIDTH - 1 : 0] wr_ptr_gray_sync;
  19. dp_ram #(DATA_WIDTH, ADDR_WIDTH)
  20. dp_ram (
  21. .wr_clk(wr_clk),
  22. .wr_en(wr_en),
  23. .wr_addr(wr_ptr),
  24. .wr_data(wr_data),
  25. .rd_clk(rd_clk),
  26. .rd_addr(rd_ptr),
  27. .rd_data(rd_data)
  28. );
  29. gen_wr_ptr #(ADDR_WIDTH)
  30. gen_wr_ptr (
  31. .reset_n(reset_n),
  32. .wr_clk(wr_clk),
  33. .wr_en(wr_en),
  34. .rd_ptr_gray_sync(rd_ptr_gray_sync),
  35. .wr_ptr_bin(wr_ptr),
  36. .wr_ptr_gray(wr_ptr_gray),
  37. .full(full)
  38. );
  39. gen_rd_ptr #(ADDR_WIDTH)
  40. gen_rd_ptr (
  41. .reset_n(reset_n),
  42. .rd_clk(rd_clk),
  43. .rd_en(rd_en),
  44. .wr_ptr_gray_sync(wr_ptr_gray_sync),
  45. .rd_ptr_bin(rd_ptr),
  46. .rd_ptr_gray(rd_ptr_gray),
  47. .empty(empty)
  48. );
  49. sync #(ADDR_WIDTH)
  50. sync_wr_ptr (
  51. .reset_n(reset_n),
  52. .clk(rd_clk),
  53. .in(wr_ptr_gray),
  54. .out(wr_ptr_gray_sync)
  55. );
  56. sync #(ADDR_WIDTH)
  57. sync_rd_ptr (
  58. .reset_n(reset_n),
  59. .clk(wr_clk),
  60. .in(rd_ptr_gray),
  61. .out(rd_ptr_gray_sync)
  62. );
  63. endmodule