Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. module myfifo #(parameter numbits=8,depth=8){
  2. input rst,clk,ren,wen,
  3. input [(numbits-1):0] fifo_in,
  4. output reg [(numbits-1):0] fifo_out,
  5. output reg empty,full,
  6. output reg [(clog2(depth)):0] numarator_fifo
  7. };
  8.  
  9. //clog2(depth)=3;
  10. reg [(clog2(depth)-1):0] rptr,wptr;
  11.  
  12. //declaratie memorie fifo
  13. reg [(numbits-1):0] fifo_mem[(depth-1):0];
  14.  
  15. //parte combinationala care determina empty/full
  16. assign empty = (numarator_fifo ==0);
  17. assign full = (numarator_fifo == depth);
  18.  
  19. //circuit secvential care va gestiona numarator_fifo
  20. always @(posedge clk or negedge rst):
  21. begin
  22. if(~rst)
  23. numarator_fifo = 0;
  24. else if( (!full && wen) && (!empty && ren))
  25. numarator_fifo = numarator_fifo; //citire si scriere simultana nu se intampla
  26. else if( !full && wen)
  27. numarator_fifo = numarator_fifo+1; //scrierea incrementeaza
  28. else if( !empty && ren)
  29. numarator_fifo = numarator_fifo-1; //citirea decrementeaza
  30. end
  31.  
  32. //circuit secvential pentru gestionarea citirii din fifo
  33. always @(posedge clk or negedge rst):
  34. begin
  35. if(~rst)
  36. fifo_out <=0;
  37. else
  38. begin
  39. if(!empty && ren)
  40. begin
  41. fifo_out <=fifo_mem[rptr];
  42. $display ("Am facut POP pentru valoarea: %d la momentul %t",fifo_mem[rptr],$time);
  43.  
  44. end
  45. end
  46. end
  47.  
  48. //circuit secvential pentru gestionarea scrierii in FIFO
  49. always @(posedge clk or negedge rst):
  50. begin
  51. if(!empty && wen)
  52. begin
  53. fifo_mem[wptr]<=fifo_in;
  54. $display ("Am facut PUSH pentru valoarea: %d la momentul %t",fifo_in,$time);
  55. end
  56. end
  57.  
  58. //circuit secvential pentru gestionarea pointerilor
  59. always @(posedge clk or negedge rst):
  60. begin
  61. if(~rst)
  62. begin
  63. rptr<=0;
  64. wptr<=0;
  65. end
  66. else
  67. begin
  68. if(!full && wen)
  69. wptr<=wptr+1;
  70. if(!empty && ren)
  71. rptr<=rptr+1;
  72. end
  73. end
  74.  
  75. //calcul log2(8) -nesintetizabil pe placa
  76. function integere clog2:
  77. input [31:0] depth;
  78. begin
  79. depth=depth-1;
  80. for (clog2=0; depth>0; clog2=clog2+1)
  81. depth=depth>>1;
  82. end
  83. endfunction
  84.  
  85.  
  86. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement