x393  1.0
FPGAcodeforElphelNC393camera
fifo_sameclock_control.v
Go to the documentation of this file.
1 
26 `timescale 1ns/1ps
27 
29  parameter WIDTH = 9
30 )(
31  input clk,
32  input rst, // clock-sync reset
33  input wr, // write to FIFO (also applied directly to memory)
34  input rd, // read from FIFO, internally masked by nempty
35  output nempty, // at read side
36  output [WIDTH:0] fill_in, // valid at write side, latency 1 for read
37  output reg [WIDTH-1:0] mem_wa,
38  output reg [WIDTH-1:0] mem_ra,
39  output mem_re,
40  output mem_regen,
41  output reg over,
42  output reg under
43 
44 );
45  reg [WIDTH:0] fill_ram;
46 
47  reg ramo_full;
48  reg rreg_full;
49 
50  assign mem_re = (|fill_ram) && (!ramo_full || !rreg_full || rd);
51  assign mem_regen = ramo_full && (!rreg_full || rd);
52  assign nempty = rreg_full;
53  assign fill_in = fill_ram;
54 
55  always @ (posedge clk) begin
56  if (rst) mem_wa <= 0;
57  else if (wr) mem_wa <= mem_wa + 1;
58 
59  if (rst) mem_ra <= 0;
60  else if (mem_re) mem_ra <= mem_ra + 1;
61 
62  if (rst) fill_ram <= 0;
63  else if (wr ^ mem_re) fill_ram <= mem_re ? (fill_ram - 1) : (fill_ram + 1);
64 
65  if (rst) ramo_full <= 0;
66  else if (mem_re ^ mem_regen) ramo_full <= mem_re;
67 
68  if (rst) rreg_full <= 0;
69  else if (mem_regen ^ (rd && rreg_full)) rreg_full <= mem_regen;
70 
71  if (rst) under <= 0;
72  else under <= rd && ! rreg_full;
73 
74  if (rst) over <= 0;
75  else over <= wr && fill_ram[WIDTH] && !fill_ram[WIDTH-1];
76 
77  end
78 
79 endmodule
80