root/gnuradio/branches/developers/zhuochen/simulations/burst_test/test_chan_fifo_reader.v

Revision 6111 (checked in by zhuochen, 1 year ago)

Test bench does been modified

Line 
1 `include "math_real.v"
2
3 module chan_fifo_readers_test();
4    
5     // Inputs
6     reg reset;
7     reg txclock;
8     reg [31:0] datain;
9     reg [31:0] ttime;
10     reg WR;
11     reg adcclock;
12     reg debug;
13     reg WR_done;
14     wire [15:0] tx_q;
15     wire [15:0] tx_i;
16     wire underrun;
17
18     reg [15:0] i ;
19     reg [15:0] phase ;
20
21     // fifo inputs
22     wire skip;
23     wire rdreq;
24    
25     // fifo ouputs
26     wire [31:0] fifodata;
27     wire pkt_waiting;
28     wire tx_strobe;
29     wire tx_empty;
30    
31     math math ( ) ;
32    
33     reg [15:0] siga ;
34     reg [15:0] sigb ;
35    
36     chan_fifo_reader chan0 (
37         .reset              (reset),
38         .tx_clock           (txclock),
39         .adc_time           (ttime),
40         .skip               (skip),
41         .rdreq              (rdreq),
42         .pkt_waiting        (pkt_waiting),
43         .fifodata           (fifodata),
44         .tx_q               (tx_q),
45         .tx_i               (tx_i),
46         .underrun           (underrun),
47         .samples_format     (4'd0),
48         .tx_empty           (tx_empty),
49         .tx_strobe          (tx_strobe)
50     );
51    
52    
53     // Channel fifo
54     channel_ram tx_data_fifo ( 
55         .reset              (reset),
56         .txclk              (txclock),
57         .datain             (datain),
58         .WR                 (WR),
59         .have_space         (),
60         .dataout            (fifodata),
61         .packet_waiting     (pkt_waiting),
62         .RD                 (rdreq),
63         .WR_done            (WR_done),
64         .RD_done            (skip)
65     );
66    
67     strobe_gen strobe_generator (
68         .reset              (reset),
69         .enable             (1'b1),
70         .clock              (txclock),
71         .strobe_in          (1'b1),
72         .strobe             (tx_strobe),
73         .rate               (8'd3)
74     );
75
76     initial begin
77         // Setup the initial conditions
78         reset = 1;
79         adcclock = 0;
80         txclock = 0;
81         datain = 0;
82         WR = 0;
83         i = 0 ;
84         ttime = 0;
85         debug = 0;
86         WR_done = 0;
87         phase = 0 ;
88      
89         // Deassert the reset
90         #40 reset = 1'b0 ;
91
92         // Wait a few clocks
93         repeat (5) begin
94           @(posedge txclock)
95             reset = 1'b0 ;
96         end
97        
98         send_packet(9'd128, 2'd2, 32'h00000300) ;
99         send_packet(9'd128, 2'd0, 32'hFFFFFFFF) ;
100         send_packet(9'd128, 2'd1, 32'hFFFFFFFF) ;
101         send_packet(9'd128, 2'd3, 32'hFFFFFFFF) ;
102        
103     end
104    
105     always@(posedge adcclock) begin
106         ttime <= ttime + 1;
107     end
108    
109     always
110           #5 txclock = ~txclock ;
111    
112     always
113           #5 adcclock = ~adcclock ;
114    
115     task send_packet;
116         input [8:0]length;
117         input [1:0] flag;
118         input [31:0] timestamp;
119         reg [8:0] newlength ;
120         begin
121             i = 0 ;
122             newlength = 4*(length-2) ;
123             repeat (length) begin
124                 @(posedge txclock) begin
125                     WR = 1;
126                     if ( i == 0)
127                         datain = {3'd0, flag, 18'd0, newlength} ;
128                     else if ( i == 1)
129                         datain = timestamp;
130                     else begin
131                         siga = math.round(math.sin(4*phase*`MATH_DEG_TO_RAD)*(math.pow(2,15)-1)) ;
132                         sigb = math.round(math.cos(phase*`MATH_DEG_TO_RAD)*(math.pow(2,15)-1)) ;
133                         phase = phase + 1 ;
134                         datain = {siga,sigb} ;
135                     end
136                     i = i + 1 ;
137                 end
138             end
139            
140             if (length < 128) begin
141                 @(posedge txclock)
142                     WR_done = 1;
143                     WR = 0;
144                 @(posedge txclock)
145                     WR_done = 0;
146             end
147             else begin
148                 @(posedge txclock)
149                     WR = 0;
150             end
151         end
152     endtask
153
154 endmodule
Note: See TracBrowser for help on using the browser.