gen_rd_ptr.v 565 B

123456789101112131415161718192021222324252627
  1. module gen_rd_ptr #(parameter ADDR_WIDTH = 4)
  2. (
  3. input reset_n,
  4. input rd_clk,
  5. input rd_en,
  6. input [ADDR_WIDTH - 1 : 0] wr_ptr_gray_sync,
  7. output [ADDR_WIDTH - 1 : 0] rd_ptr_bin,
  8. output [ADDR_WIDTH - 1 : 0] rd_ptr_gray,
  9. output empty
  10. );
  11. reg [ADDR_WIDTH - 1 : 0] binary;
  12. assign rd_ptr_bin = binary;
  13. assign rd_ptr_gray = (binary >> 1) ^ binary;
  14. assign empty = rd_ptr_gray == wr_ptr_gray_sync;
  15. always @(posedge rd_clk) begin
  16. if (reset_n == 1'b0) begin
  17. binary <= 0;
  18. end else if (rd_en == 1'b1 & empty == 1'b0) begin
  19. binary <= binary + 1;
  20. end
  21. end
  22. endmodule