1 module packet_builder #(parameter NUM_CHAN = 1)(
8 input [15:0]chan_fifodata,
9 input [NUM_CHAN:0]chan_empty,
10 input [9:0]chan_usedw,
11 output reg [3:0]rd_select,
12 output reg chan_rdreq,
15 output reg [15:0]fifodata,
17 input wire [31:0]rssi_0, input wire [31:0]rssi_1, input wire [31:0]rssi_2,
18 input wire [31:0]rssi_3, output wire [7:0] debugbus,
19 input [NUM_CHAN:0] overrun, input [NUM_CHAN:0] underrun);
26 `define TIMESTAMP 3'd3
29 `define MAXPAYLOAD 504
31 `define PAYLOAD_LEN 8:0
43 reg [8:0] read_length;
44 reg [8:0] payload_len;
48 wire [31:0] true_rssi;
49 wire [4:0] true_channel;
51 assign debugbus = {state, chan_empty[0], underrun[0], check_next[0],
52 have_space, rd_select[0]};
53 assign chan_used = chan_usedw[8:0];
54 assign true_rssi = (rd_select[1]) ? ((rd_select[0]) ? rssi_3:rssi_2) :
55 ((rd_select[0]) ? rssi_1:rssi_0);
56 assign true_channel = (check_next == 4'd0 ? 5'h1f : {1'd0, check_next - 4'd1});
57 always @(posedge rxclk)
73 if(~chan_empty[check_next])
76 rd_select <= #1 check_next;
78 check_next <= #1 (check_next == channels ? 4'd0 : check_next + 4'd1);
83 fifodata[`PAYLOAD_LEN] <= #1 (chan_used > 9'd252
84 ? 9'd252 : chan_used << 1);
85 payload_len <= #1 (chan_used > 9'd252
86 ? 9'd252 : chan_used << 1);
87 fifodata[`TAG] <= #1 0;
88 fifodata[`MBZ] <= #1 0;
96 fifodata[`CHAN] <= #1 true_channel;
97 fifodata[`RSSI] <= #1 true_rssi[5:0];
98 fifodata[`BURST] <= #1 0;
99 fifodata[`DROPPED] <= #1 0;
100 fifodata[`UNDERRUN] <= #1 (check_next == 0) ? 1'b0 : underrun[true_channel];
101 fifodata[`OVERRUN] <= #1 (check_next == 0) ? 1'b0 : overrun[true_channel];
102 state <= #1 `TIMESTAMP;
106 fifodata <= #1 (tstamp_complete ? adctime[31:16] : adctime[15:0]);
107 tstamp_complete <= #1 ~tstamp_complete;
109 if (~tstamp_complete)
112 state <= #1 (tstamp_complete ? `FORWARD : `TIMESTAMP);
116 read_length <= #1 read_length + 9'd2;
117 fifodata <= #1 (read_length >= payload_len ? 16'hDEAD : chan_fifodata);
119 if (read_length >= `MAXPAYLOAD)
125 else if (read_length == payload_len - 4)
130 //handling error state