x393  1.0
FPGAcodeforElphelNC393camera
cmprs_out_fifo.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
42 // input rst, // mostly for simulation
43 
44  // wclk domain
45  input wclk, // source clock (2x pixel clock, inverted)
46  input wrst, // @posedge wclk, sync reset
47  input we,
48  input [15:0] wdata,
49  input wa_rst, // reset low address bits when stuffer is disabled (to make sure it is multiple of 32 bytes
50  input wlast, // written last 32 bytes of a frame (flush FIFO) - stuffer_done (has to be later than we)
51  output eof_written_wclk, // eof_written - reclocked to wclk
52 
53  // rclk domain
54  input rclk,
55  input rrst, // @posedge rclk, sync reset
56  input rst_fifo, // reset FIFO (set read address to write, reset count)
57  input ren,
58  output [63:0] rdata,
59  output eof, // single rclk pulse signalling EOF
60  input eof_written, // confirm frame written ofer AFI to the system memory (single rclk pulse)
61  output flush_fifo, // EOF, need to output all what is in FIFO (Stays active until enough data chunks are read)
62  output [7:0] fifo_count // number of 32-byte chunks in FIFO
63 
64 );
65  reg regen;
66  reg [ 8:0] raddr;
67  reg [ 7:0] count32;
68  reg [ 7:0] lcount32; // counting chunks left in the same frame
69  reg [10:0] waddr;
70  wire written32b; // written 32 bytes, re-clocked to read clock domain (single-cycle)
71  wire wlast_rclk;
73 
74  assign flush_fifo = flush_fifo_r;
75  assign fifo_count = count32;
76  assign eof = wlast_rclk;
77 
78  always @ (posedge wclk) begin
79  if (wrst) waddr <= 0;
80  else if (wa_rst) waddr <= waddr & 11'h7f0; // reset 4 LSBs only
81  else if (we) waddr <= waddr + 1;
82  end
83 
84  always @ (posedge rclk) begin
85  regen <= ren;
86 
87  if (rst_fifo) raddr <= {waddr[10:4],2'b0};
88  else if (ren) raddr <= raddr + 1;
89 
90  if (rst_fifo) count32 <= 0;
91  else if ( written32b && !(ren && (&raddr[1:0]))) count32 <= count32 + 1;
92  else if (!written32b && (ren && (&raddr[1:0]))) count32 <= count32 - 1;
93 
94 
95  if (rst_fifo) lcount32 <= 0;
96  else if (wlast_rclk) lcount32 <= count32;
97  else if ((lcount32 !=0) && ren && (&raddr[1:0])) lcount32 <= lcount32 - 1;
98 
99  if (rst_fifo) flush_fifo_r <= 0;
100  else if (wlast_rclk) flush_fifo_r <= 1;
101  else if ((count32[7:1] == 0) && ( !count32[0] || ren)) flush_fifo_r <= 0;
102 
103  end
104 
105 // wclk -> rclk
106  pulse_cross_clock written32b_i (.rst(wrst), .src_clk(wclk), .dst_clk(rclk), .in_pulse(we && (&waddr[3:0])), .out_pulse(written32b),.busy());
108 // rclk -> wclk
111  .REGISTERS(1),
112  .LOG2WIDTH_WR(4),
113  .LOG2WIDTH_RD(6)
114  ) fifo_i (
115  .rclk (rclk), // input
116  .raddr (raddr), // input[8:0]
117  .ren (ren), // input
118  .regen (regen), // input
119  .data_out (rdata), // output[63:0]
120  .wclk (wclk), // input - OK, negedge mclk
121  .waddr (waddr), // input[10:0]
122  .we (we), // input
123  .web (8'hff), // input[7:0]
124  .data_in (wdata) // input[15:0]
125  );
126 
127 
128 endmodule
129 
[63:0] 1693rdata
1699raddrreg[8:0]
[7:0] 1697fifo_count
1700count32reg[7:0]
[1 << LOG2WIDTH_WR-1:0] 11872data_in
[14-LOG2WIDTH_WR:0] 11869waddr
eof_written_wclk_i pulse_cross_clock
1702waddrreg[10:0]
[1 << LOG2WIDTH_RD-1:0] 11867data_out
[14-LOG2WIDTH_RD:0] 11864raddr
[15:0] 1685wdata
1701lcount32reg[7:0]
fifo_i ram_var_w_var_r