x393  1.0
FPGAcodeforElphelNC393camera
debug_slave.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
41 module debug_slave#(
42  parameter SHIFT_WIDTH = 32, // data width (easier to use multiple of 32, but not required)
43  parameter READ_WIDTH = 32, // number of status bits to send over the ring (LSB aligned to the shift register)
44  parameter WRITE_WIDTH = 32, // number of status bits to receive over the ring (LSB aligned to the shift register)
45  parameter DEBUG_CMD_LATENCY = 2 // >0 extra registers in the debug_sl (distriburted in parallel)
46 )(
47  input mclk,
48  input mrst,
49  // 3-wire debug interface
50  input debug_di, // debug data received over the ring
51  input debug_sl, // 0 - idle, (1,0) - shift, (1,1) - load
52  output debug_do, // debug data sent over the ring
53 
54  // payload interface
55  input [READ_WIDTH - 1 : 0] rd_data, // local data to send over the daisy-chained ring
56  output [WRITE_WIDTH - 1 : 0] wr_data, // received data to be used here (some bits may be used as address and wr_en
57  output stb
58 );
59  reg [SHIFT_WIDTH - 1 : 0] data_sr;
60  reg cmd; //command stae (0 - idle)
61  reg [DEBUG_CMD_LATENCY : 0] cmd_reg; // MSB not used and will be optimized out
63  wire [SHIFT_WIDTH + READ_WIDTH - 1 :0] ext_rdata = {{SHIFT_WIDTH{1'b0}}, rd_data};
64  assign wr_data = data_sr[WRITE_WIDTH - 1 : 0];
65  assign stb = cmd && cmd_reg_dly;
66  assign debug_do = data_sr[0];
67  always @ (posedge mclk) begin
68 
69  if (mrst) cmd_reg <= 0;
70  else cmd_reg <= {cmd_reg[DEBUG_CMD_LATENCY - 1 : 0], debug_sl};
71 
72  if (mrst) cmd <= 0;
73  else cmd <= cmd_reg_dly & ~cmd;
74 
75  if (cmd && !cmd_reg_dly) data_sr <= {debug_di, data_sr[SHIFT_WIDTH - 1 :1]};
76  else if (cmd && cmd_reg_dly) data_sr <= ext_rdata[SHIFT_WIDTH - 1 : 0];
77 
78  end
79 
80 endmodule
81 
[WRITE_WIDTH - 1 : 0] 10318wr_data
Definition: debug_slave.v:56
10323cmd_reg_dlywire
Definition: debug_slave.v:62
10324ext_rdatawire[SHIFT_WIDTH+READ_WIDTH-1:0]
Definition: debug_slave.v:63
10310WRITE_WIDTH32
Definition: debug_slave.v:44
[READ_WIDTH - 1 : 0] 10317rd_data
Definition: debug_slave.v:55
10320data_srreg[SHIFT_WIDTH-1:0]
Definition: debug_slave.v:59
10322cmd_regreg[DEBUG_CMD_LATENCY:0]
Definition: debug_slave.v:61
10308SHIFT_WIDTH32
Definition: debug_slave.v:42
10311DEBUG_CMD_LATENCY2
Definition: debug_slave.v:45
10309READ_WIDTH32
Definition: debug_slave.v:43