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

65 lines
2.2 KiB
Systemverilog

`timescale 1ns/1ps
// Fixed four-channel pairing in the FIFO read/AXIS clock domain.
// Inputs are stable FIFO heads: {local_index[63:0], chip_word[31:0]}.
// Equality of local indices does not establish a common physical ADC epoch.
module sample_pairer (
input wire clk,
input wire rst,
input wire coherent_epoch_valid,
input wire session_fault,
input wire [95:0] a_data,
input wire a_valid,
output wire a_ready,
input wire [95:0] b_data,
input wire b_valid,
output wire b_ready,
output reg [63:0] m_data,
output reg [63:0] m_index,
output reg m_valid,
input wire m_ready,
output reg fault
);
reg [63:0] expected_index;
reg epoch_seen;
wire both_valid = a_valid && b_valid;
wire index_bad = (a_data[95:32] != b_data[95:32]) ||
(a_data[95:32] != expected_index);
wire epoch_lost = epoch_seen && !coherent_epoch_valid;
wire fault_event = session_fault || epoch_lost ||
(coherent_epoch_valid && both_valid && index_bad);
wire slot_available = !m_valid || m_ready;
wire pair_fire = !rst && !fault && !fault_event &&
coherent_epoch_valid && both_valid && slot_available;
// A pair is consumed atomically. Neither FIFO may discard/rebase a head.
assign a_ready = pair_fire;
assign b_ready = pair_fire;
always @(posedge clk) begin
if (rst) begin
m_data <= 0;
m_index <= 0;
m_valid <= 0;
fault <= 0;
expected_index <= 0;
epoch_seen <= 0;
end else begin
// A previously accepted word remains valid through a later fault.
// Once stalled, AXIS-like valid/payload may change only on transfer
// or an explicit interface reset; acquisition validity is external.
if (m_valid && m_ready)
m_valid <= 0;
if (fault_event)
fault <= 1;
if (pair_fire) begin
m_data <= {b_data[31:0], a_data[31:0]};
m_index <= a_data[95:32];
m_valid <= 1;
expected_index <= expected_index + 1'b1;
epoch_seen <= 1;
end
end
end
endmodule