x393  1.0
FPGAcodeforElphelNC393camera
status_read.v
Go to the documentation of this file.
1 
47 `timescale 1ns/1ps
48 
49 module status_read#(
50  parameter STATUS_ADDR = 'h0800, // AXI read address of status read registers
51  parameter STATUS_ADDR_MASK = 'h3c00, // AXI write address of status registers
52  parameter AXI_RD_ADDR_BITS = 14,
53  parameter integer STATUS_DEPTH= 8, // 256 cells, maybe just 16..64 are enough?
54  parameter FPGA_VERSION = 32'h03930001
55  )(
56  input mrst, // @posedge mclk - sync reset
57  input arst, // @posedge axi_clk - sync reset
58  input clk,
59  input axi_clk, // common for read and write channels
60  input [AXI_RD_ADDR_BITS-1:0] axird_pre_araddr, // status read address, 1 cycle ahead of read data
61  input axird_start_burst, // start of read burst, valid pre_araddr, save externally to control ext. dev_ready multiplexer
62  input [STATUS_DEPTH-1:0] axird_raddr, // .raddr(read_in_progress?read_address[9:0]:10'h3ff), // read address
63  input axird_ren, // .ren(bram_reg_re_w) , // read port enable
64  input axird_regen, //==axird_ren?? - remove? .regen(bram_reg_re_w), // output register enable
65  output [31:0] axird_rdata, // combinatorial multiplexed (add external register layer, modify axibram_read?) .data_out(rdata[31:0]), // data out
66  output axird_selected, // axird_rdata contains cvalid data from this module, vcalid next after axird_start_burst
67  // so with ren/regen it may be delayed 1 more cycle
68  input [7:0] ad, // byte-serial status data from the sources
69  input rq, // request from sources to transfer status data
70  output start // acknowledge receiving of first byte (address), currently always ready
71 );
72  localparam integer DATA_2DEPTH=(1<<STATUS_DEPTH)-1;
73  reg [31:0] ram [0:DATA_2DEPTH];
74  reg [STATUS_DEPTH-1:0] waddr;
75  reg we;
76  reg [31: 0] wdata;
77  reg rq_r;
78  reg [3:0] dstb;
79 
80  wire select_w;
81  reg select_r;
82  reg select_d;
83 
84  wire rd;
85  wire regen;
86  reg [31:0] axi_status_rdata;
87  reg [31:0] axi_status_rdata_r;
88 
90  assign rd = axird_ren && select_r;
91  assign regen = axird_regen && select_d;
92 
93 
94 
95 
96 // assign re= pre_stb && (((axi_pre_addr ^ STATUS_ADDR) & STATUS_ADDR_MASK) == 0);
97 // assign raddr=axi_pre_addr[STATUS_DEPTH-1:0];
98  assign start=rq && !rq_r;
100  assign axird_selected = select_r;
101  initial begin
103 `ifdef HISPI
104  ram [DATA_2DEPTH-1] = 1; //0 - parallel sensor, 1 - HiSPi sensor
105 `endif
106  end
107  always @ (posedge axi_clk) begin
108  if (arst) select_r <= 0;
109  else if (axird_start_burst) select_r <= select_w;
110  end
111  always @ (posedge axi_clk) begin
114 
115  select_d <= select_r;
116  end
117 
118  always @ (posedge clk) begin
119 
120  if (mrst) rq_r <= 0;
121  else rq_r <= rq;
122 
123  if (mrst) dstb <= 0;
124  else if (!rq) dstb <= 0;
125  else dstb <= {dstb[2:0],~rq_r};
126  // byte 0 - address
127  if (mrst) waddr <= 0;
128  else if (start) waddr <= ad[STATUS_DEPTH-1:0];
129 
130  // byte 1 - 2 payload bits and sequence number
131  // 6 bits of the sequence number will go to bits 26.. 31
132  // 2 bits (24,25) are payload status
133  if (mrst) wdata[31:24] <= 0;
134  else if (start) wdata[31:24] <= 0;
135  else if (dstb[0]) wdata[31:24] <= ad;
136 
137  // byte 2 - payload bits 0..7
138  if (mrst) wdata[ 7: 0] <= 0;
139  else if (start) wdata[ 7: 0] <= 0;
140  else if (dstb[1]) wdata[ 7: 0] <= ad;
141 
142  // byte 3 - payload bits 8..15
143  if (mrst) wdata[15: 8] <= 0;
144  else if (start) wdata[15: 8] <= 0;
145  else if (dstb[2]) wdata[15: 8] <= ad;
146 
147  // byte 4 - payload bits 16..23
148  if (mrst) wdata[23:16] <= 0;
149  else if (start) wdata[23:16] <= 0;
150  else if (dstb[3]) wdata[23:16] <= ad;
151 
152  if (mrst) we <= 0;
153  else we <= !rq && rq_r;
154  end
155 
156  always @ (posedge clk) begin
157  if (we) ram[waddr] <= wdata; // shifted data here
158  end
159 
160 
161 
162 endmodule
163 
164 
[STATUS_DEPTH-1:0] 10871axird_raddr
Definition: status_read.v:62
[7:0] 10876ad
Definition: status_read.v:68
[31:0] 10874axird_rdata
Definition: status_read.v:65
[0:DATA_2DEPTH] 10880ramreg[31:0]
Definition: status_read.v:73
10890regenwire
Definition: status_read.v:85
integer 10879DATA_2DEPTH(1<<STATUS_DEPTH)-1
Definition: status_read.v:72
10861STATUS_ADDR_MASK'h3c00
Definition: status_read.v:51
10881waddrreg[STATUS_DEPTH-1:0]
Definition: status_read.v:74
integer 10863STATUS_DEPTH8
Definition: status_read.v:53
10892axi_status_rdata_rreg[31:0]
Definition: status_read.v:87
[AXI_RD_ADDR_BITS-1:0] 10869axird_pre_araddr
Definition: status_read.v:60
10891axi_status_rdatareg[31:0]
Definition: status_read.v:86
10860STATUS_ADDR'h0800
Definition: status_read.v:50
10862AXI_RD_ADDR_BITS14
Definition: status_read.v:52
10864FPGA_VERSION32'h03930001
Definition: status_read.v:54
10887select_rreg
Definition: status_read.v:81
10885dstbreg[3:0]
Definition: status_read.v:78
10870axird_start_burst
Definition: status_read.v:61
10888select_dreg
Definition: status_read.v:82
10886select_wwire
Definition: status_read.v:80
10883wdatareg[31:0]
Definition: status_read.v:76