x393  1.0
FPGAcodeforElphelNC393camera
cmprs_afi_mux_status.v
Go to the documentation of this file.
1 
43 `timescale 1ns/1ps
44 
46  parameter CMPRS_AFIMUX_STATUS_REG_ADDR= 'h20, //Uses 4 locations TODO: assign valid address
47  parameter CMPRS_AFIMUX_WIDTH = 26, // maximal for status: currently only works with 26)
48  parameter CMPRS_AFIMUX_CYCBITS = 3
49  ) (
50 // input rst,
51  input hclk, // global clock to run axi_hp @ 150MHz, shared by all compressor channels
52  input mclk, // for command/status
53  input mrst, // @posedge mclk, sync reset
54  input hrst, // @posedge xclk, sync reset
55  // mclk domain
56  input [15:0] cmd_data, //
57  input [ 1:0] cmd_a, //
58  input status_we, //
59  input mode_we, //
60 
61  output [7:0] status_ad, // status address/data - up to 5 bytes: A - {seq,status[1:0]} - status[2:9] - status[10:17] - status[18:25]
62  output status_rq, // input request to send status downstream
63  input status_start, // Acknowledge of the first status packet byte (address)
64  // hclk domain
65  input en, // 1- enable, 0 - reset
66  output reg [3:0] chunk_ptr_ra, // full pointer address - {eof,wresp,chn[1:0]}
67  input [CMPRS_AFIMUX_WIDTH-1:0] chunk_ptr_rd // pointer data
68 );
69  localparam MODE_WIDTH = 15;
70  reg [MODE_WIDTH-1:0] mode_data_mclk; // some bits unused
72  reg [7:0] mode_hclk;
73  reg [1:0] index;
75  reg [CMPRS_AFIMUX_WIDTH-1:0] chunk_ptr_hclk; // pointer data
76  reg [1:0] chunk_chn_hclk; // pointer channel
77 
79 
80  wire stb_w;
81  reg stb_r;
82  wire stb_mclk;
83 
84  wire [31:0] ad;
85  wire [3:0] rq;
86  wire [3:0] start;
87 
88  assign stb_w = en && (cntr==0);
89  always @ (posedge mclk) begin
91  end
92 
93  always @ (posedge hclk) begin
94  if (mode_we_hclk) begin
95  if (mode_data_mclk[ 2]) mode_hclk[1:0] <= mode_data_mclk[ 1: 0];
96  if (mode_data_mclk[ 6]) mode_hclk[3:2] <= mode_data_mclk[ 5: 4];
97  if (mode_data_mclk[10]) mode_hclk[5:4] <= mode_data_mclk[ 9: 8];
98  if (mode_data_mclk[14]) mode_hclk[7:6] <= mode_data_mclk[13:12];
99  end
100 
102 // if (stb_mclk && (chunk_chn_hclk == 2'h0)) status_data[0 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH] <= chunk_ptr_hclk;
103 // if (stb_mclk && (chunk_chn_hclk == 2'h1)) status_data[1 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH] <= chunk_ptr_hclk;
104 // if (stb_mclk && (chunk_chn_hclk == 2'h2)) status_data[2 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH] <= chunk_ptr_hclk;
105 // if (stb_mclk && (chunk_chn_hclk == 2'h3)) status_data[3 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH] <= chunk_ptr_hclk;
106 
107  if (!en) {index,cntr} <= 0;
108  else {index,cntr} <= {index,cntr} + 1;
109 
110  if (stb_w) begin
111  chunk_ptr_ra[1:0] <= index;
112  case (index)
113  2'h0: chunk_ptr_ra[3:2] <= mode_hclk[1:0] ^ 1; // so 0 will be eof, internal
114  2'h1: chunk_ptr_ra[3:2] <= mode_hclk[3:2] ^ 1;
115  2'h2: chunk_ptr_ra[3:2] <= mode_hclk[5:4] ^ 1;
116  2'h3: chunk_ptr_ra[3:2] <= mode_hclk[7:6] ^ 1;
117  endcase
118  end
119  stb_r <= stb_w;
120  if (stb_r) begin
121  chunk_ptr_hclk <= {chunk_ptr_rd[23:0],chunk_ptr_rd[25:24]}; // bits 0,1 are sent to 25:24
123  end
124 
125  end
126 
129  status_router4 status_router4_i (
130  .rst (1'b0), // rst), // input
131  .clk (mclk), // input
132  .srst (mrst), // input
133  .db_in0 (ad[0 * 8 +: 8]), // input[7:0]
134  .rq_in0 (rq[0]), // input
135  .start_in0 (start[0]), // output
136 
137  .db_in1 (ad[1 * 8 +: 8]), // input[7:0]
138  .rq_in1 (rq[1]), // input
139  .start_in1 (start[1]), // output
140  .db_in2 (ad[2 * 8 +: 8]), // input[7:0]
141  .rq_in2 (rq[2]), // input
142  .start_in2 (start[2]), // output
143  .db_in3 (ad[3 * 8 +: 8]), // input[7:0]
144  .rq_in3 (rq[3]), // input
145  .start_in3 (start[3]), // output
146  .db_out (status_ad), // output[7:0]
147  .rq_out (status_rq), // output
148  .start_out (status_start) // input
149  );
150 
152  .STATUS_REG_ADDR (CMPRS_AFIMUX_STATUS_REG_ADDR+0),
153  .PAYLOAD_BITS (CMPRS_AFIMUX_WIDTH)
154  ) status_generate0_i (
155  .rst (1'b0), //rst), // input
156  .clk (mclk), // input
157  .srst (mrst), // input
158  .we (status_we && (cmd_a==0)), // input
159  .wd (cmd_data[7:0]), // input[7:0]
160  .status (status_data[0 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH]), // input[25:0]
161  .ad (ad[0 * 8 +: 8]), // output[7:0]
162  .rq (rq[0]), // output
163  .start (start[0]) // input
164  );
165 
167  .STATUS_REG_ADDR (CMPRS_AFIMUX_STATUS_REG_ADDR+1),
168  .PAYLOAD_BITS (CMPRS_AFIMUX_WIDTH)
169  ) status_generate1_i (
170  .rst (1'b0), //rst), // input
171  .clk (mclk), // input
172  .srst (mrst), // input
173  .we (status_we && (cmd_a==1)), // input
174  .wd (cmd_data[7:0]), // input[7:0]
175  .status (status_data[1 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH]), // input[25:0]
176  .ad (ad[1 * 8 +: 8]), // output[7:0]
177  .rq (rq[1]), // output
178  .start (start[1]) // input
179  );
180 
182  .STATUS_REG_ADDR (CMPRS_AFIMUX_STATUS_REG_ADDR+2),
183  .PAYLOAD_BITS (CMPRS_AFIMUX_WIDTH)
184  ) status_generate2_i (
185  .rst (1'b0), //rst), // input
186  .clk (mclk), // input
187  .srst (mrst), // input
188  .we (status_we && (cmd_a==2)), // input
189  .wd (cmd_data[7:0]), // input[7:0]
190  .status (status_data[2 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH]), // input[25:0]
191  .ad (ad[2 * 8 +: 8]), // output[7:0]
192  .rq (rq[2]), // output
193  .start (start[2]) // input
194  );
195 
197  .STATUS_REG_ADDR (CMPRS_AFIMUX_STATUS_REG_ADDR+3),
198  .PAYLOAD_BITS (CMPRS_AFIMUX_WIDTH)
199  ) status_generate3_i (
200  .rst (1'b0), // rst), // input
201  .clk (mclk), // input
202  .srst (mrst), // input
203  .we (status_we && (cmd_a==3)), // input
204  .wd (cmd_data[7:0]), // input[7:0]
205  .status (status_data[3 * CMPRS_AFIMUX_WIDTH +: CMPRS_AFIMUX_WIDTH]), // input[25:0]
206  .ad (ad[3 * 8 +: 8]), // output[7:0]
207  .rq (rq[3]), // output
208  .start (start[3]) // input
209  );
210 
211 endmodule
212 
361status_datareg[4*CMPRS_AFIMUX_WIDTH-1:0]
359chunk_ptr_hclkreg[CMPRS_AFIMUX_WIDTH-1:0]
358cntrreg[CMPRS_AFIMUX_CYCBITS-1:0]
[7:0] 10990db_in2
status_generate3_i status_generate
[CMPRS_AFIMUX_WIDTH-1:0] 352chunk_ptr_rd
status_router4_i status_router4
[7:0] 10984db_in0
354mode_data_mclkreg[MODE_WIDTH-1:0]
[7:0] 10996db_out
[7:0] 10993db_in3
[7:0] 10987db_in1
[ALL_BITS-1:0] 10777status