Files
templates/hdl/scope-acquisition/rtl/capture_stream.sv
T

58 lines
2.3 KiB
Systemverilog

`timescale 1ns/1ps
// One ADC chip -> indexed asynchronous stream. Fault is sticky in rd_clk.
module capture_stream #(
parameter integer FIFO_ADDR_BITS = 9
) (
input wire arst_n,
input wire adc_clk,
input wire ready_async,
input wire [9:0] adc_data_a, adc_data_b,
input wire stream_clk,
output wire [95:0] stream_data,
output wire stream_valid,
input wire stream_ready,
output wire session_fault,
output wire [31:0] overflow_count_adc
);
wire [31:0] sample_word;
wire [63:0] sample_index;
wire sample_valid, adc_rst;
wire fifo_ready, overflow_pulse, overflow_sticky;
reg seen_valid, ready_lost;
(* ASYNC_REG = "TRUE", SHREG_EXTRACT = "NO" *) reg [1:0] fault_sync;
wire stream_rst;
adc_capture capture_i (
.adc_clk(adc_clk), .arst_n(arst_n), .ready_async(ready_async),
.adc_data_a(adc_data_a), .adc_data_b(adc_data_b),
.sample_word(sample_word), .sample_valid(sample_valid),
.sample_index(sample_index)
);
reset_sync adc_reset_i (.clk(adc_clk), .arst_n(arst_n), .rst(adc_rst));
reset_sync stream_reset_i (.clk(stream_clk), .arst_n(arst_n), .rst(stream_rst));
async_sample_fifo #(.WIDTH(96), .ADDR_BITS(FIFO_ADDR_BITS)) fifo_i (
.arst_n(arst_n), .wr_clk(adc_clk), .wr_valid(sample_valid),
.wr_data({sample_index, sample_word}), .wr_ready(fifo_ready),
.wr_overflow(overflow_pulse), .wr_overflow_sticky(overflow_sticky),
.wr_overflow_count(overflow_count_adc),
.rd_clk(stream_clk), .rd_valid(stream_valid),
.rd_data(stream_data), .rd_ready(stream_ready)
);
always @(posedge adc_clk or posedge adc_rst) begin
if (adc_rst) begin seen_valid <= 0; ready_lost <= 0; end
else begin
if (sample_valid) seen_valid <= 1;
if (seen_valid && !sample_valid) ready_lost <= 1;
end
end
always @(posedge stream_clk or posedge stream_rst) begin
if (stream_rst) fault_sync <= 0;
else fault_sync <= {fault_sync[0], ready_lost || overflow_sticky};
end
assign session_fault = fault_sync[1];
// overflow_count_adc belongs to adc_clk. ARM must use a coherent snapshot,
// not independent per-bit synchronizers. A stopped ADC clock needs an
// external watchdog: this block cannot detect absence of its own clock.
endmodule