x393  1.0
FPGAcodeforElphelNC393camera
simul_fifo.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
41 module simul_fifo
42 #(
43  parameter integer WIDTH= 32, // total number of output bits
44  parameter integer DEPTH= 64, // maximal number of words in FIFO
45 // parameter OUT_DELAY = 3.5,
46  parameter integer FIFO_DEPTH=DEPTH+1
47 // parameter integer DATA_2DEPTH=(1<<DATA_DEPTH)-1
48 )(
49  input clk,
50  input reset,
51  input [WIDTH-1:0] data_in,
52  input load,
53  output input_ready,
54  output [WIDTH-1:0] data_out,
55  output valid,
56  input ready);
57 
58  reg [WIDTH-1:0] fifo [0:FIFO_DEPTH-1];
59  integer in_address;
60  integer out_address;
61  integer count;
62 
63  assign data_out= fifo[out_address];
64  assign valid= count!=0;
65  assign input_ready= count<DEPTH;
66 
67  always @ (posedge clk or posedge reset) begin
68  if (reset) in_address <= 0;
69  else if (load) in_address <= (in_address==(FIFO_DEPTH-1))?0:in_address+1;
70 
71  if (reset) out_address <= 0;
72  else if (valid && ready) out_address <= (out_address==(FIFO_DEPTH-1))?0:out_address+1;
73 
74 
75  if (reset) count <= 0;
76  else if (!(valid && ready) && load) count <= count+1;
77  else if (valid && ready && !load) count <= count-1;
78  end
79 
80  always @ (posedge clk) begin
81  if (load) fifo[in_address] <= data_in;
82  end
83 endmodule
integer 9213DEPTH64
Definition: simul_fifo.v:44
[0:FIFO_DEPTH-1] 9223fiforeg[WIDTH-1:0]
Definition: simul_fifo.v:58
integer 9214FIFO_DEPTHDEPTH+1
Definition: simul_fifo.v:46
9226countinteger
Definition: simul_fifo.v:61
[WIDTH-1:0] 9220data_out
Definition: simul_fifo.v:54
9225out_addressinteger
Definition: simul_fifo.v:60
9224in_addressinteger
Definition: simul_fifo.v:59
[WIDTH-1:0] 9217data_in
Definition: simul_fifo.v:51
integer 9212WIDTH32
Definition: simul_fifo.v:43