Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
fchan_subset Source File
1`timescale 1ns / 1ns
2
3// Name: Channel Subset
4//% Runtime-configurable selection of which data to keep within each block
5//% Typically used on the input to a waveform memory
6module fchan_subset #(
7 parameter KEEP_OLD = 0,
8 parameter a_dw = 20,
9 parameter o_dw = 20,
10 parameter len = 16
11) (
12 input clk,
13 input reset,
14 input [len-1:0] keep,
15 input signed [a_dw-1:0] a_data,
16 input a_gate, a_trig,
17 output signed [o_dw-1:0] o_data,
18 output o_gate, o_trig,
19 output time_err
20);
21
22// Reverse bit order of mask
23// We use historical code in fchan_subset that defines its keep input in
24// the left-to-right sense. But for ease of documentation and consistency
25// with banyan switch code, our keep input has its bits counted from
26// right to left: lsb is bit 0, corresponds to channel 0.
27wire [len-1:0] keep_use;
28genvar ix;
29generate
30 if (KEEP_OLD==1) begin : G_KEEP_OLD
31 for (ix=0; ix<len; ix=ix+1) begin
32 assign keep_use[ix] = keep[len-1-ix];
33 end
34 end
35 else begin : G_NKEEP_OLD
36 for (ix=0; ix<len; ix=ix+1) begin
37 assign keep_use[ix] = keep[ix];
38 end
39 end
40endgenerate
41
42reg [len-1:0] live=0;
43always @(posedge clk) begin
44 if (reset)
45 live <= 0;
46 else if (a_gate|a_trig) live <= a_trig ? keep_use : {live[len-2:0],1'b0};
47end
48
49assign o_data = a_data;
50assign o_gate = a_gate & live[len-1];
51assign o_trig = a_trig;
52
53demand_gpt #(.gpt(len)) tcheck(.clk(clk), .gate(a_gate), .trig(a_trig), .time_err(time_err));
54
55endmodule