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);
25 `define TIMESTAMP 3'd3
28 `define MAXPAYLOAD 504
30 `define PAYLOAD_LEN 8:0
42 reg [8:0] read_length;
43 reg [8:0] payload_len;
47 wire [31:0] true_rssi;
49 assign debugbus = {state, chan_empty[0], chan_empty[1], check_next[0],
50 have_space, rd_select[0]};
51 assign chan_used = chan_usedw[8:0];
52 assign true_rssi = (rd_select[1]) ? ((rd_select[0]) ? rssi_3:rssi_2) :
53 ((rd_select[0]) ? rssi_1:rssi_0);
54 always @(posedge rxclk)
69 if(~chan_empty[check_next])
72 rd_select <= #1 check_next;
74 check_next <= #1 (check_next == channels ? 4'd0 : check_next + 4'd1);
79 fifodata[`PAYLOAD_LEN] <= #1 (chan_used > 9'd252
80 ? 9'd252 : chan_used << 1);
81 payload_len <= #1 (chan_used > 9'd252
82 ? 9'd252 : chan_used << 1);
83 fifodata[`TAG] <= #1 0;
84 fifodata[`MBZ] <= #1 0;
92 fifodata[`CHAN] <= #1 (check_next == 4'd0 ? 5'h1f : {1'd0, check_next - 4'd1});
93 fifodata[`RSSI] <= #1 true_rssi[5:0];
94 fifodata[`BURST] <= #1 0;
95 fifodata[`DROPPED] <= #1 0;
96 fifodata[`UNDERRUN] <= #1 0;
97 fifodata[`OVERRUN] <= #1 0;
99 state <= #1 `TIMESTAMP;
103 fifodata <= #1 (tstamp_complete ? adctime[31:16] : adctime[15:0]);
104 tstamp_complete <= #1 ~tstamp_complete;
106 if (~tstamp_complete)
109 state <= #1 (tstamp_complete ? `FORWARD : `TIMESTAMP);
113 read_length <= #1 read_length + 9'd2;
114 fifodata <= #1 (read_length >= payload_len ? 16'hDEAD : chan_fifodata);
116 if (read_length >= `MAXPAYLOAD)
121 else if (read_length == payload_len - 4)
126 //handling error state