x393  1.0
FPGAcodeforElphelNC393camera
dct1d_chen_reorder_in.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, // to be sampled when start is expected (start time slot)
47  input [WIDTH -1:0] din,
48  input start, // with first pixel
49  output [2*WIDTH -1:0] dout_10_32_76_54, // Concatenated/reordered output data {x[1],x[0]}/{x[3],x[2]}/ {x[7],x[6]}/{x[5],x[4]}
50  output reg start_out,
51  output en_out // to be sampled when start_out is expected
52 );
53  reg last_r;
54  reg [2:0] cntr_in;
55  reg [1:0] raddr;
56  wire restart = !rst && en && (start || last_r);
57 // wire [1:0] we = ((|cntr_in) || en)? {~cntr_in[0]^cntr_in[2],cntr_in[0]^cntr_in[2]}:2'b0;
58  wire [1:0] we = ((|cntr_in) || en)? {cntr_in[0]^cntr_in[2], ~cntr_in[0]^cntr_in[2]}:2'b0;
59  wire [1:0] waddr = {cntr_in[2],cntr_in[2]^cntr_in[1]};
60  reg [WIDTH-1:0] bufl_ram[0:3];
61  reg [WIDTH-1:0] bufh_ram[0:3];
62  reg [2*WIDTH -1:0] dout_10_32_76_54_r;
64  reg en_out_r;
65  reg last_out;
66  reg re_r;
68  assign en_out = en_out_r;
69 
70  always @(posedge clk) begin
71  if (rst) last_r <= 0;
72  else last_r <= &cntr_in;
73 
74  last_out <= raddr == 2;
75 
76  if (rst) re_r <= 0;
77  else if (cntr_in == 5) re_r <= 1;
78  else if (last_out) re_r <= 0;
79 
80  if (rst) cntr_in <= 0;
81  else if (restart || (|cntr_in)) cntr_in <= cntr_in + 1;
82 
83  if (we[0]) bufl_ram[waddr] <= din;
84  if (we[1]) bufh_ram[waddr] <= din;
85 
86  if (rst ) raddr <= ~0;
87  else if (cntr_in == 5) raddr <= 0;
88  else if (!(&raddr)) raddr <= raddr + 1;
89 
90  if (rst) first_period <= 0;
91  else if (start && en) first_period <= 1;
92  else if (last_r) first_period <= 0;
93 
95 
96  start_out <= first_period && (cntr_in == 5);
97 
98  if (rst) en_out_r <= 0;
99  else if (cntr_in == 5) en_out_r <= 1;
100  else if ((raddr == 2) && !en) en_out_r <= 0;
101 
102  end
103 endmodule
104 
[0:3] 3236bufl_ramreg[WIDTH-1:0]
[2*WIDTH -1:0] 3227dout_10_32_76_54
[0:3] 3237bufh_ramreg[WIDTH-1:0]
3238dout_10_32_76_54_rreg[2*WIDTH-1:0]