Merged features/inband -r4812:5218 into trunk. This group of changes
[debian/gnuradio] / usrp / fpga / inband_lib / tx_buffer_inband.v
1 module tx_buffer_inband
2   ( input usbclk,
3     input bus_reset,  // Used here for the 257-Hack to fix the FX2 bug
4     input reset,  // standard DSP-side reset
5     input [15:0] usbdata,
6     input wire WR,
7     output wire have_space,
8     output reg tx_underrun,
9     input wire [3:0] channels,
10     output [15:0] tx_i_0,
11     output [15:0] tx_q_0,
12     output [15:0] tx_i_1,
13     output [15:0] tx_q_1,
14     //NOT USED
15     output reg [15:0] tx_i_2,
16     output reg [15:0] tx_q_2,
17     output reg [15:0] tx_i_3,
18     output reg [15:0] tx_q_3,
19     input txclk,
20     input txstrobe,
21     input clear_status,
22     output wire tx_empty,
23     output [11:0] debugbus
24     );
25
26    wire [15:0] tx_data_bus;
27
28    wire WR_chan_0;
29    wire chan_0_done;
30    wire OR0;
31    wire UR0;
32    
33    wire WR_chan_1;
34    wire chan_1_done;
35    wire OR1;
36    wire UR1;
37    
38    // NOT USED yet
39    wire WR_cmd;
40    wire cmd_done;
41    
42    //EXTERNAL REGISTER
43    //TODO: increment it
44    reg [31:0] time_counter;
45    reg [7:0] txstrobe_rate_0;
46    reg [7:0] txstrobe_rate_1;
47    
48    
49    //Usb block
50    wire [15:0] tupf_fifodata;
51    wire tupf_pkt_waiting;
52    wire tupf_rdreq;
53    wire tupf_skip;
54    wire tupf_have_space;
55    
56    usb_packet_fifo2 tx_usb_packet_fifo 
57      (  .reset         (reset),
58         .usb_clock     (usbclk), 
59         .fpga_clock    (txclk),
60         .write_data    (usbdata),
61         .write_enable  (WR),
62         .read_data     (tupf_fifodata),
63         .pkt_waiting   (tupf_pkt_waiting),
64         .read_enable   (tupf_rdreq), 
65         .skip_packet   (tupf_skip),
66         .have_space    (tupf_have_space),
67         .tx_empty      (tx_empty)
68        );
69    
70         usb_fifo_reader tx_usb_packet_reader (
71                 .reset(reset),
72                 .tx_clock(txclk),
73                 .tx_data_bus(tx_data_bus),
74       .WR_chan_0(WR_chan_0),
75       .WR_chan_1(WR_chan_1),
76       .WR_cmd(WR_cmd),
77       .chan_0_done(chan_0_done),
78       .chan_1_done(chan_1_done),
79       .cmd_done(cmd_done),
80       .rdreq(tupf_rdreq),
81       .skip(tupf_skip),
82       .pkt_waiting(tupf_pkt_waiting),
83       .fifodata(tupf_fifodata)
84         );
85
86
87    //Channel 0 block
88    wire [15:0] tdpf_fifodata_0;
89    wire tdpf_pkt_waiting_0;
90    wire tdpf_rdreq_0;
91    wire tdpf_skip_0;
92    wire tdpf_have_space_0;
93    wire txstrobe_chan_0;
94
95    data_packet_fifo tx_data_packet_fifo_0 
96      (  .reset(reset),
97         .clock(txclk), 
98         .ram_data_in(tx_data_bus),
99         .write_enable(WR_chan_0),
100         .ram_data_out(tdpf_fifodata_0),
101         .pkt_waiting(tdpf_pkt_waiting_0),
102         .read_enable(tdpf_rdreq_0),
103         .pkt_complete(chan_0_done), 
104         .skip_packet(tdpf_skip_0),
105         .have_space(tdpf_have_space_0)
106        );
107    
108    strobe_gen strobe_gen_0
109     (   .clock(txclk),
110         .reset(reset),
111         .enable(1'b1),
112         .rate(txstrobe_rate_0),
113         .strobe_in(txstrobe),
114         .strobe(txstrobe_chan_0) 
115        );
116    
117    chan_fifo_reader tx_chan_0_reader (
118       .reset(reset),
119       .tx_clock(txclk),
120       .tx_strobe(txstrobe),
121       //.tx_strobe(txstrobe_chan_0),
122       .adc_clock(time_counter),
123       .samples_format(4'b0),
124       .tx_q(tx_q_0),
125       .tx_i(tx_i_0),
126       .overrun(OR0),
127       .underrun(UR0),
128       .skip(tdpf_skip_0),
129       .rdreq(tdpf_rdreq_0),
130       .fifodata(tdpf_fifodata_0),
131       .pkt_waiting(tdpf_pkt_waiting_0)
132    );   
133    
134    
135    //Channel 1 block
136    wire [15:0] tdpf_fifodata_1;
137    wire tdpf_pkt_waiting_1;
138    wire tdpf_rdreq_1;
139    wire tdpf_skip_1;
140    wire tdpf_have_space_1;
141    wire txstrobe_chan_1;
142    
143    data_packet_fifo tx_data_packet_fifo_1 
144      (  .reset(reset),
145         .clock(txclk), 
146         .ram_data_in(tx_data_bus),
147         .write_enable(WR_chan_1),
148         .ram_data_out(tdpf_fifodata_1),
149         .pkt_waiting(tdpf_pkt_waiting_1),
150         .read_enable(tdpf_rdreq_1),
151         .pkt_complete(chan_1_done), 
152         .skip_packet(tdpf_skip_1),
153         .have_space(tdpf_have_space_1)
154        );
155    
156    strobe_gen strobe_gen_1
157     (   .clock(txclk),
158         .reset(reset),
159         .enable(1'b1),
160         .rate(txstrobe_rate_1),
161         .strobe_in(txstrobe),
162         .strobe(txstrobe_chan_1) 
163        );
164    
165    chan_fifo_reader tx_chan_1_reader (
166       .reset(reset),
167       .tx_clock(txclk),
168       .tx_strobe(txstrobe),
169       //.tx_strobe(txstrobe_chan_1),
170       .adc_clock(time_counter),
171       .samples_format(4'b0),
172       .tx_q(tx_q_1),
173       .tx_i(tx_i_1),
174       .overrun(OR1),
175       .underrun(UR1),
176       .skip(tdpf_skip_1),
177       .rdreq(tdpf_rdreq_1),
178       .fifodata(tdpf_fifodata_1),
179       .pkt_waiting(tdpf_pkt_waiting_1)
180    );
181    
182 endmodule // tx_buffer
183