2 * Internal signal capture module
5 `define SIGCAP_WIDTH 64
6 `define SIGCAP_DEPTH 2048
7 `define SIGCAP_ADDRBITS 16
9 /* Capture RAM module, should infer a block RAM in ISE
11 * Based on XST example "Dual-Port Block RAM with Different Clocks"
18 input [`SIGCAP_ADDRBITS-1:0] addra,
19 input [`SIGCAP_ADDRBITS-1:0] addrb,
20 input [`SIGCAP_WIDTH-1:0] dia,
21 output [`SIGCAP_WIDTH-1:0] doa,
22 output [`SIGCAP_WIDTH-1:0] dob
24 reg [`SIGCAP_WIDTH-1:0] ram [`SIGCAP_DEPTH-1:0];
25 reg [`SIGCAP_ADDRBITS-1:0] addr_rega;
26 reg [`SIGCAP_ADDRBITS-1:0] addr_regb;
28 always @(posedge clka) begin
33 always @(posedge clkb) begin
36 assign doa = ram[addr_rega];
37 assign dob = ram[addr_regb];
40 /* WO: Capture control register */
41 `define SIGCAP_REG_CTRL 0
42 `define SIGCAP_CTRL_RESET 0 /* 8'b00000001 */
43 `define SIGCAP_CTRL_RUN 1 /* 8'b00000002 */
45 /* RO: Total sample count in buffer */
46 `define SIGCAP_REG_COUNT_0 2
47 `define SIGCAP_REG_COUNT_1 3
49 /* RW: Read next sample. Write reset read address */
50 `define SIGCAP_REG_DATA 4
53 * Note about clock domains:
55 * sysclk is used for the register interface, capclk for the actual
56 * capture. However, we don't use synchronizers when those domains
57 * collide, as we know that both clocks derive from the same DLL
58 * and shouldn't go metastable. Typically capclk is a multiple of
69 /* Signals to capture */
70 input [`SIGCAP_WIDTH-1:0] sigs,
72 /* Backbus interface */
75 output [7:0] bb_rdata,
81 reg [`SIGCAP_ADDRBITS-1:0] cap_addr;
82 reg [`SIGCAP_ADDRBITS-1:0] read_addr;
85 wire [`SIGCAP_WIDTH-1:0] cap_data;
87 wire [`SIGCAP_WIDTH-1:0] ram_ignore;
96 /* Instanciate capture memory */
97 capram capram0(.clka(capclk),
99 .wea(capturing && !cap_full),
106 /* Capture control logic */
107 always@(posedge capclk or posedge reset) begin
114 end else if (!do_run) begin
118 if (capturing && !cap_full) begin
119 cap_addr <= cap_addr + 1;
124 assign cap_full = cap_addr == (`SIGCAP_DEPTH - 1);
126 /* Mux memory output */
127 always@(read_byte or cap_data) begin
129 0: cap_byte = cap_data[63:56];
130 1: cap_byte = cap_data[55:48];
131 2: cap_byte = cap_data[47:40];
132 3: cap_byte = cap_data[39:32];
133 4: cap_byte = cap_data[31:24];
134 5: cap_byte = cap_data[23:16];
135 6: cap_byte = cap_data[15:8];
136 7: cap_byte = cap_data[7:0];
137 default: cap_byte = cap_data[7:0];
142 assign bb_rdata = (bb_addr[2:0] == `SIGCAP_REG_COUNT_0) ?
143 cap_addr[`SIGCAP_ADDRBITS-1:8] :
144 (bb_addr[2:0] == `SIGCAP_REG_COUNT_1) ? cap_addr[7:0] :
147 /* Fifo address counter */
148 assign do_reset_combo = reset | do_reset;
150 always@(posedge sysclk or posedge do_reset_combo) begin
151 if (do_reset_combo) begin
155 if (bb_strobe && bb_addr[2:0] == `SIGCAP_REG_DATA) begin
160 read_byte <= read_byte + 1;
161 if (read_byte == 3'b111)
162 read_addr <= read_addr + 1;
168 /* Control register write interface */
169 always@(posedge sysclk or posedge reset) begin
174 if (bb_strobe && bb_wr && bb_addr[2:0] == `SIGCAP_REG_CTRL) begin
175 do_reset <= bb_wdata[`SIGCAP_CTRL_RESET];
176 do_run <= bb_wdata[`SIGCAP_CTRL_RUN];