OpenCores
URL https://opencores.org/ocsvn/dmt_tx/dmt_tx/trunk

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [const_encoder/] [tb/] [tb_const_enc.v] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 dannori
/* *****************************************************************
2
 *
3 16 dannori
 *  This file is part of the
4
 *
5
 *   Tone Order and Constellation Encoder Core.
6
 *
7 13 dannori
 *  Copyright (C) 2007 Guenter Dannoritzer
8
 *
9
 *   This source is free software; you can redistribute it
10
 *   and/or modify it under the terms of the
11
 *             GNU General Public License
12
 *   as published by the Free Software Foundation;
13
 *   either version 3 of the License,
14
 *   or (at your option) any later version.
15
 *
16
 *   This source is distributed in the hope
17
 *   that it will be useful, but WITHOUT ANY WARRANTY;
18
 *   without even the implied warranty of MERCHANTABILITY
19
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 *   GNU General Public License for more details.
21
 *
22
 *   You should have received a copy of the
23 16 dannori
 *   GNU General Public License along with this source.
24 13 dannori
 *   If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 * *****************************************************************/
27 12 dannori
 
28
module tb_const_encoder();
29
 
30 16 dannori
parameter TW              = 10;
31 12 dannori
 
32 16 dannori
`include "parameters.vh"
33 12 dannori
 
34 16 dannori
 
35
reg                 clk;
36
reg                 reset;
37
wire                fast_ready_o;
38
reg                 we_fast_data_i;
39
reg   [DW-1:0]      fast_data_i;
40
wire                inter_ready_o;
41
reg                 we_inter_data_i;
42
reg   [DW-1:0]      inter_data_i;
43
 
44
reg                 we_conf_i;
45
reg   [CONFAW-1:0]  addr_i;
46
reg   [CONFDW-1:0]  conf_data_i;
47
wire  [CNUMW-1:0]   carrier_num_o;
48 20 dannori
wire  signed [CONSTW-1:0]  x_o;
49
wire  signed [CONSTW-1:0]  y_o;
50 16 dannori
 
51 12 dannori
//
52
// instantiate the DUT
53
// 
54
const_encoder dut ( .clk(clk),
55
                    .reset(reset),
56 16 dannori
                    .fast_ready_o(fast_ready_o),
57
                    .we_fast_data_i(we_fast_data_i),
58
                    .fast_data_i(fast_data_i),
59
                    .inter_ready_o(inter_ready_o),
60
                    .we_inter_data_i(we_inter_data_i),
61
                    .inter_data_i(inter_data_i),
62 12 dannori
                    .addr_i(addr_i),
63
                    .we_conf_i(we_conf_i),
64
                    .conf_data_i(conf_data_i),
65
                    .xy_ready_o(xy_ready_o),
66 16 dannori
                    .carrier_num_o(carrier_num_o),
67 12 dannori
                    .x_o(x_o),
68
                    .y_o(y_o));
69
 
70 20 dannori
//
71
// instantiate test data modules
72
//
73
const_map_2bit cm_2bit();
74 22 dannori
const_map_3bit cm_3bit();
75
const_map_4bit cm_4bit();
76
const_map_5bit cm_5bit();
77 12 dannori
 
78 20 dannori
 
79 16 dannori
initial begin
80
  clk = 0;
81
  we_fast_data_i = 0;
82
  we_inter_data_i = 0;
83
  we_conf_i = 0;
84
  reset = 0;
85
end
86
 
87
always begin
88
  #TW clk = ~clk;
89
end
90
 
91
//
92
// dump signals
93
//
94
initial begin
95
  $dumpfile("tb_const_enc.vcd");
96
  $dumpvars;
97
end
98
 
99
 
100
//
101
// main test
102
// 
103 12 dannori
 
104
initial begin
105
 
106 16 dannori
  $monitor($time, " reset: ", reset);
107 12 dannori
 
108 16 dannori
  apply_reset;
109 12 dannori
 
110 16 dannori
  //
111
  // write configuration
112
  //
113
  write_config(BIT_LOAD_ST_ADR, 2);
114
  write_config(BIT_LOAD_ST_ADR+1, 3);
115
  write_config(BIT_LOAD_ST_ADR+2, 4);
116
  write_config(BIT_LOAD_ST_ADR+3, 5);
117 12 dannori
 
118 16 dannori
  write_config(C_NUM_ST_ADR,    48);
119
  write_config(C_NUM_ST_ADR+1,  49);
120
  write_config(C_NUM_ST_ADR+2,  50);
121
  write_config(C_NUM_ST_ADR+3,  51);
122
 
123
 
124
  write_config(USED_C_ADR, 4);
125
  write_config(F_BITS_ADR, 7);
126
 
127
  //
128
  // check written configuration
129
  //
130
  check_config(BIT_LOAD_ST_ADR,   2);
131
  check_config(BIT_LOAD_ST_ADR+1, 3);
132
  check_config(BIT_LOAD_ST_ADR+2, 4);
133
  check_config(BIT_LOAD_ST_ADR+3, 5);
134
 
135
  check_config(C_NUM_ST_ADR,    48);
136
  check_config(C_NUM_ST_ADR+1,  49);
137
  check_config(C_NUM_ST_ADR+2,  50);
138
  check_config(C_NUM_ST_ADR+3,  51);
139
 
140
  check_config(USED_C_ADR, 4);
141
  check_config(F_BITS_ADR, 7);
142 20 dannori
 
143
  //
144
  // checking the constellation map
145
  //
146
  check_const_map(2);
147 22 dannori
  check_const_map(3);
148
  check_const_map(4);
149
  check_const_map(5);
150 16 dannori
 
151 12 dannori
  #1000 $finish();
152
 
153 16 dannori
end // main test
154
 
155
 
156
// //////////////////////////////////////////////////////////////////// 
157
// 
158
// bus functional models
159
// 
160
// //////////////////////////////////////////////////////////////////// 
161
 
162
task apply_reset;
163
  begin
164
    reset = 0;
165
    #20
166
    reset = 1;
167
    @(posedge clk);
168
    reset = 0;
169
  end
170
endtask
171 12 dannori
 
172 16 dannori
//
173
// write data to the configuration registers
174
//
175
task write_config(input [CONFAW-1:0] addr, input[CONFDW-1:0] data);
176
  begin
177
 
178
    addr_i = addr;
179
    conf_data_i = data;
180
    @(negedge clk);
181
    we_conf_i = 1;
182
    @(negedge clk);
183
    we_conf_i = 0;
184
 
185
  end
186
endtask
187 12 dannori
 
188 16 dannori
//
189
// check the written configuration
190
//
191
task check_config(input [CONFAW-1:0] addr, input [CONFDW-1:0] exp_data);
192
  begin
193 12 dannori
 
194 16 dannori
    if(addr >= 0 && addr < C_NUM_ST_ADR) begin
195
 
196
      if(dut.BitLoading[addr] !== exp_data) begin
197
        $display("ERROR! => BitLoading does not match @ %x!", addr);
198
        $display("          Got: %d expected: %d",
199
                  dut.BitLoading[addr], exp_data);
200
      end
201
 
202
    end
203
    else if(addr >= C_NUM_ST_ADR && addr < USED_C_ADR) begin
204 12 dannori
 
205 16 dannori
      if(dut.CarrierNumber[addr-C_NUM_ST_ADR] !== exp_data) begin
206
        $display("ERROR! => CarrierNumber does not match @ %x!", addr);
207
        $display("          Got: %d expected: %d",
208
                  dut.CarrierNumber[addr-C_NUM_ST_ADR], exp_data);
209
      end
210
 
211
    end
212
    else if(addr == USED_C_ADR) begin
213
 
214
      if(dut.UsedCarrier !== exp_data) begin
215
        $display("ERROR! => UsedCarrier does not match @ %x!", addr);
216
        $display("          Got: %d expected: %d",
217
                  dut.UsedCarrier, exp_data);
218
      end
219
 
220
    end
221
    else if(addr == F_BITS_ADR) begin
222
 
223
      if(dut.FastBits !== exp_data) begin
224
        $display("ERROR! => FastBits does not match @ %x!", addr);
225
        $display("          Got: %d expected: %d",
226
                  dut.FastBits, exp_data);
227
      end
228
 
229
    end
230
  end
231
endtask
232
 
233
 
234 20 dannori
//
235
// check constellation map
236
//
237
// This task feeds in data direct to the constellation encoder module
238
// and checks the expected outcome.
239
//
240
// Given parameter is the bit size of the constellation map.
241
//
242
task check_const_map(input [3:0] bit);
243
  integer len;
244
  integer i;
245
  begin
246
   len = 1 << bit;
247
    for(i=0; i<len; i=i+1) begin
248
      $display("Testing %d bit constellation with input value %d", bit, i);
249
      // feed input data
250
      dut.bit_load <= bit;
251
      dut.cin <= i;
252
 
253
      @ (posedge clk);
254 22 dannori
      @ (posedge clk);
255 20 dannori
      @ (negedge clk);
256
      // compare output with expected result
257
      case (bit)
258
        1:  $display("%d bit is not support constellation size", bit);
259 22 dannori
 
260 20 dannori
        2:  begin
261
              if(cm_2bit.re[i] !== x_o) begin
262
                $display("Input: %d --> x_o expected: %d got: %d", i, cm_2bit.re[i], x_o);
263
              end
264
              if(cm_2bit.im[i] !== y_o) begin
265
                $display("Input: %d --> y_o expected: %d got: %d", i, cm_2bit.im[i], y_o);
266
              end
267
            end
268 22 dannori
 
269
        3:  begin
270
              if(cm_3bit.re[i] !== x_o) begin
271
                $display("Input: %d --> x_o expected: %d got: %d", i, cm_3bit.re[i], x_o);
272
              end
273
              if(cm_3bit.im[i] !== y_o) begin
274
                $display("Input: %d --> y_o expected: %d got: %d", i, cm_3bit.im[i], y_o);
275
              end
276
            end
277
 
278
        4:  begin
279
              if(cm_4bit.re[i] !== x_o) begin
280
                $display("Input: %d --> x_o expected: %d got: %d", i, cm_4bit.re[i], x_o);
281
              end
282
              if(cm_4bit.im[i] !== y_o) begin
283
                $display("Input: %d --> y_o expected: %d got: %d", i, cm_4bit.im[i], y_o);
284
              end
285
            end
286
 
287
        5:  begin
288
              if(cm_5bit.re[i] !== x_o) begin
289
                $display($time, " Input: %d --> x_o expected: %d got: %d", i, cm_5bit.re[i], x_o);
290
              end
291
              if(cm_5bit.im[i] !== y_o) begin
292
                $display($time, " Input: %d --> y_o expected: %d got: %d", i, cm_5bit.im[i], y_o);
293
              end
294
            end
295
 
296
 
297 20 dannori
        default: $display("%d is not an implemented bit size", bit);
298
      endcase
299
 
300
    end
301
 
302
  end
303
endtask
304
 
305
 
306 12 dannori
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.