x393  1.0
FPGAcodeforElphelNC393camera
sens_hispi_fifo.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
42 // parameter COUNT_START = 7, // wait these many samples input before starting output
43  parameter DATA_WIDTH = 12,
44  parameter DATA_DEPTH = 4 // >=3
45 ) (
46  input ipclk,
47  input irst,
48  input we,
49  input sol, // start of line - 1 cycle before dv
50  input eol, // end of line - last dv
51  input [DATA_WIDTH-1:0] din,
52  input [DATA_DEPTH-1:0] out_dly, // wait these many samples input before starting output
53  input pclk,
54  input prst,
55  input re,
56  output reg [DATA_WIDTH-1:0] dout, // valid next cycle after re
57  output run // has latency 1 after last re
58 );
59  reg [DATA_WIDTH-1:0] fifo_ram[0 : (1 << DATA_DEPTH) -1];
60  reg [DATA_DEPTH:0] wa;
61  reg [DATA_DEPTH:0] ra;
64  reg line_run_ipclk_d; // to generate start for very short lines (may just use small out_dly value)
66  reg run_r;
69 
70  assign run = run_r;
71  // TODO: generate early done by comparing ra with (wa-1) - separate counter
72 
73  always @ (posedge ipclk) begin
74  if (irst ||sol) wa <= 0;
75  else if (we && line_run_ipclk) wa <= wa + 1;
76 
77  if (we && line_run_ipclk) fifo_ram[wa[DATA_DEPTH-1:0]] <= din;
78 
79  if (irst || eol) line_run_ipclk <= 0;
80  else if (sol) line_run_ipclk <= 1;
81 
82  if (!line_run_ipclk) start_sent <= 0;
83  else if (start_out_ipclk) start_sent <= 1;
84 
86 
87  if (irst) start_out_ipclk <= 0;
89 
90  end
91 
92  always @(posedge pclk) begin
94 
95  if (prst) run_r <= 0;
96  else if (line_start_pclk) run_r <= 1;
97  else if (!line_run_pclk && (ra == wa)) run_r <= 0;
98 
99  if (prst ||line_start_pclk) ra <= 0;
100  else if (re) ra <= ra + 1;
101 
102  if (re) dout <= fifo_ram[ra[DATA_DEPTH-1:0]];
103 
104  end
105 
107  .EXTRA_DLY(0)
108  ) pulse_cross_clock_line_start_i (
109  .rst (irst), // input
110  .src_clk (ipclk), // input
111  .dst_clk (pclk), // input
112 // .in_pulse (we && (wa == COUNT_START)), // input
113  .in_pulse (start_out_ipclk), // input
114  .out_pulse (line_start_pclk), // output
115  .busy() // output
116  );
117 
118 
119 endmodule
120 
[DATA_WIDTH-1:0] 7236din
reg [DATA_WIDTH-1:0] 7241dout
[0:1<<DATA_DEPTH-1] 7243fifo_ramreg[DATA_WIDTH-1:0]
7244wareg[DATA_DEPTH:0]
7245rareg[DATA_DEPTH:0]
[DATA_DEPTH-1:0] 7237out_dly
pulse_cross_clock_line_start_i pulse_cross_clock