gen_wr_ptr.v 740 B

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