x393  1.0
FPGAcodeforElphelNC393camera
dct1d_chen_reorder_out.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
42  parameter WIDTH = 24
43  )(
44  input clk,
45  input rst,
46  input en, // sampled at timeslot of pre2_start
47  input [WIDTH -1:0] din, // pre2_start-X-F4-X-F2-X-F6-F5-F0-F3-X-F1-X-F7
48  input pre2_start, // Two cycles ahead of F4
49  output [WIDTH -1:0] dout, // data in natural order: F0-F1-F2-F3-F4-F5-F6-F7
50  output start_out, // 1 ahead of the first F0
51  output reg dv, // output data valid
52  output en_out // to be sampled when start_out is expected
53 );
54  reg [WIDTH -1:0] reord_buf_ram[0:15];
55  reg [WIDTH -1:0] dout_r;
56  reg [3:0] cntr_in;
57  reg pre_we_r;
58  reg we_r;
59  reg [3:0] ina_rom;
60  wire [3:0] waddr = {ina_rom[3] ^ cntr_in[3], ina_rom[2:0]};
61  reg [3:0] raddr;
62  reg [2:0] per_type; // idle/last:0, first cycle - 1, 2-nd - 2, other - 3,... ~en->6 ->7 -> 0 (to generate pre2_start_out)
64  reg en_out_r;
65  wire stop_out; // qualify with en
66  assign dout = dout_r;
67  assign start_out = start_out_r;
68  assign en_out = en_out_r;
69 
70  always @(posedge clk) begin
71  if (rst) per_type <= 0;
72  else if (pre2_start) per_type <= 3'h1;
73  else if (&cntr_in[2:0]) begin
74  if (!per_type[2] && !en) per_type <= 3'h6;
75  else if ((per_type != 0) && (per_type != 3)) per_type <= per_type + 1;
76  end
77 
78  if (rst) pre_we_r <= 0;
79  else if (pre2_start) pre_we_r <= 1;
80  else if ((per_type == 0) || ((cntr_in==3) && per_type[2])) pre_we_r <= 0;
81  we_r <= pre_we_r;
82 
83  if (rst) cntr_in <= 0;
84  else if (pre2_start) cntr_in <= {~cntr_in[3],3'b0};
85  else if (pre_we_r) cntr_in <= cntr_in + 1;
86  case (cntr_in[2:0])
87  3'h0: ina_rom <= {1'b0,3'h4};
88  3'h1: ina_rom <= {1'b1,3'h1};
89  3'h2: ina_rom <= {1'b0,3'h2};
90  3'h3: ina_rom <= {1'b1,3'h7};
91  3'h4: ina_rom <= {1'b0,3'h6};
92  3'h5: ina_rom <= {1'b0,3'h5};
93  3'h6: ina_rom <= {1'b0,3'h0};
94  3'h7: ina_rom <= {1'b1,3'h3};
95  endcase
96 
97  if (we_r) reord_buf_ram[waddr] <= din;
98 
99  if ((per_type == 2) && (cntr_in == 1)) raddr <= {~cntr_in[3], 3'b0};
100  else if ((raddr[2:0] != 0) || (per_type !=0)) raddr <= raddr + 1;
101 
103 
104  start_out_r <= (per_type == 2) && (cntr_in == 1);
105 
106  if (rst ||(per_type == 0) ) en_out_r <= 0;
107 // else if (cntr_in == 1) en_out_r <= (per_type == 2) || !per_type[2];
108  else if ((cntr_in == 1) && (per_type == 2)) en_out_r <= 1;
109  else if (stop_out && !en) en_out_r <= 0;
110  //stop_out
111 
112  dv <= en_out_r;
113 
114 // if (rst) dv <= 0;
115 // else if (start_out_r) dv <= 1;
116 // else if ((raddr[2:0] == 0) && !en_out_r) dv <= 0;
117  end
118 
119  dly01_16 dly01_16_i (
120  .clk (clk), // input
121  .rst (rst), // input
122  .dly (4'd8), // input[3:0]
123  .din ((&cntr_in[2:0]) && !en), // input
124  .dout (stop_out) // output
125  );
126 
127 endmodule
128 
10329dout
Definition: dly01_16.v:46
[3:0] 10327dly
Definition: dly01_16.v:44
10326rst
Definition: dly01_16.v:43
[0:15] 3253reord_buf_ramreg[WIDTH-1:0]
10325clk
Definition: dly01_16.v:42
10328din
Definition: dly01_16.v:45