Advertisement
AlexanderAntonov

Untitled

Oct 17th, 2022
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // next-state logic for read and write pointers
  2. always @*
  3.     begin
  4.     // successive pointer values
  5.     w_ptr_succ = w_ptr_reg + 1;
  6.     r_ptr_succ = r_ptr_reg + 1;
  7.     // default: keep old values
  8.     w_ptr_next = w_ptr_reg;
  9.     r_ptr_next = r_ptr_reg;
  10.     full_next = full_reg;
  11.     empty_next = empty_reg;
  12.     case ({wr, rd})
  13.     // 2'b00: no op
  14.         2'b01: // read
  15.         if (~empty_reg) // not empty
  16.             begin
  17.             r_ptr_next = r_ptr_succ;
  18.             full_next = 1'b0;
  19.             if (r_ptr_succ==w_ptr_reg)
  20.                 empty_next = 1'b1;
  21.             end
  22.         2'b10: // write
  23.         if (~full_reg) // not full
  24.             begin
  25.             w_ptr_next = w_ptr_succ ;
  26.             empty_next = 1'b0;
  27.             if (w_ptr_succ==r_ptr_reg)
  28.                 full_next = 1'b1;
  29.             end
  30.         2'b11: // write and read
  31.             begin
  32.             w_ptr_next = w_ptr_succ;
  33.             r_ptr_next = r_ptr_succ;
  34.             end
  35.     endcase
  36. end
  37. // output
  38. assign full = full_reg;
  39. assign empty = empty_reg;
  40.  
  41. endmodule
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement