Imported Upstream version 3.0
[debian/gnuradio] / usrp / fpga / tb / usrp_tasks.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2003 Matt Ettus
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 2 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
20 //
21
22 // Tasks
23
24 /////////////////////////////////////////////////
25 // USB interface
26
27 task initialize_usb;
28 begin
29         OE = 0;WE = 0;RD = 0;
30         usbdatareg <= 16'h0;
31 end
32 endtask
33
34 task write_from_usb;
35 begin
36         tb_oe <= 1'b1;
37         @(posedge usbclk);
38         usbdatareg <= #1 $random % 65536;
39         WE <= #1 1'b1;
40         @(posedge usbclk)
41         WE <= #1 1'b0;
42         tb_oe <= #1 1'b0;
43 end
44 endtask
45
46 task burst_usb_write;
47       input [31:0] repeat_count;
48       
49       begin
50          tb_oe <= 1'b1;
51          repeat(repeat_count)
52            begin
53               @(posedge usbclk)
54                 usbdatareg <= #1 usbdatareg + 1;              //$random % 65536;
55               WE <= #1 1'b1;
56            end
57          @(posedge usbclk)
58            WE <= #1 1'b0;
59          tb_oe <= 1'b0;
60       end
61 endtask // burst_usb_write
62
63
64 task read_from_usb;
65 begin
66         @(posedge usbclk);
67         RD <= #1 1'b1;
68         @(posedge usbclk);
69         RD <= #1 1'b0;
70         OE <= #1 1'b1;
71         @(posedge usbclk);
72         OE <= #1 1'b0;
73 end
74 endtask
75
76 task burst_usb_read;
77       input [31:0] repeat_count;
78       begin
79          while (~have_packet_rdy) begin
80             @(posedge usbclk);
81          end
82          
83          @(posedge usbclk)
84            RD <= #1 1'b1;
85          repeat(repeat_count)
86            begin
87               @(posedge usbclk)
88                 OE <= #1 1'b1;
89            end
90          RD <= #1 1'b0;
91          @(posedge usbclk);
92          OE <= #1 1'b0;
93       end
94 endtask // burst_usb_read
95
96 /////////////////////////////////////////////////
97 // TX and RX enable
98
99 //////////////////////////////////////////////////
100 // Set up control bus
101
102 `define ch1in_freq 0
103 `define ch2in_freq 1
104 `define ch3in_freq 2
105 `define ch4in_freq 3
106 `define ch1out_freq 4
107 `define ch2out_freq 5
108 `define ch3out_freq 6
109 `define ch4out_freq 7
110 `define rates 8
111 `define misc 9
112   
113   task send_config_word;
114       input [7:0] addr;
115       input [31:0] data;
116       integer i;
117       
118       begin
119          #10 serenable = 1;
120          for(i=7;i>=0;i=i-1)
121            begin
122               #10 serdata = addr[i];
123               #10 serclk = 0;
124               #10 serclk = 1;
125               #10 serclk = 0;
126            end
127          for(i=31;i>=0;i=i-1)
128            begin
129               #10 serdata = data[i];
130               #10 serclk = 0;
131               #10 serclk = 1;
132               #10 serclk = 0;
133            end
134          #10 serenable = 0;
135          //     #10 serload = 0;
136          //     #10 serload = 1;
137          #10 serclk = 1;
138          #10 serclk = 0;
139          //#10 serload = 0;
140       end
141   endtask // send_config_word
142
143
144 /////////////////////////////////////////////////////////
145