File: e310_io_tb.sv

package info (click to toggle)
uhd 4.9.0.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184,180 kB
  • sloc: cpp: 262,887; python: 112,011; ansic: 102,670; vhdl: 57,031; tcl: 19,924; xml: 8,581; makefile: 3,028; sh: 2,812; pascal: 230; javascript: 120; csh: 94; asm: 20; perl: 11
file content (230 lines) | stat: -rw-r--r-- 6,496 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// Copyright 2015 Ettus Research
//
// Test bench for E310 I/O interface to AD9361.

`timescale 1ns/1ps
`define SIM_TIMEOUT_US 20
`define NS_PER_TICK 1
`define NUM_TEST_CASES 6

`include "sim_clks_rsts.vh"
`include "sim_exec_report.vh"

module e310_io_tb();
  `TEST_BENCH_INIT("e310_io_tb",`NUM_TEST_CASES,`NS_PER_TICK)

  // Define all clocks and resets
  `DEFINE_CLK(rx_clk, 16.27, 50) // ~61.44 MHz clock from AD9361
  `DEFINE_RESET(areset, 0, 100)  // 100ns reset

  reg mimo;
  wire radio_clk, radio_rst;
  wire [11:0] rx_i0, rx_i1, rx_q0, rx_q1;
  wire rx_stb;
  reg [11:0] tx_i0, tx_i1, tx_q0, tx_q1;
  wire tx_stb;
  reg rx_frame;
  reg [11:0] rx_data;
  wire tx_clk;
  wire tx_frame;
  wire [11:0] tx_data;
  e310_io e310_io (
    .areset(areset),
    .mimo(mimo),
    .radio_clk(radio_clk),
    .radio_rst(radio_rst),
    .rx_i0(rx_i0),
    .rx_q0(rx_q0),
    .rx_i1(rx_i1),
    .rx_q1(rx_q1),
    .rx_stb(rx_stb),
    .tx_i0(tx_i0),
    .tx_q0(tx_q0),
    .tx_i1(tx_i1),
    .tx_q1(tx_q1),
    .tx_stb(tx_stb),
    .rx_clk(rx_clk),
    .rx_frame(rx_frame),
    .rx_data(rx_data),
    .tx_clk(tx_clk),
    .tx_frame(tx_frame),
    .tx_data(tx_data));

  /********************************************************
  ** Test Bench
  ********************************************************/
  initial begin : tb_main
    mimo     <= 1'b0;
    tx_i0    <= 'd0;
    tx_q0    <= 'd0;
    tx_i1    <= 'd0;
    tx_q1    <= 'd0;
    rx_data  <= 'd0;
    rx_frame <= 1'b0;
    `TEST_CASE_START("Wait for reset");
    while (areset) @(posedge radio_clk);
    `TEST_CASE_DONE((~areset));

    repeat (10) @(posedge radio_clk);

    `TEST_CASE_START("Test RX channel 0,1");
    mimo      <= 1'b0;
    rx_data   <= 'd0;
    repeat (10) @(posedge radio_clk);
    fork
      begin
        for (int i = 1; i < 64; i = i + 2) begin
          @(posedge radio_clk);
          rx_frame  <= 1'b1;
          rx_data   <= i;
          @(negedge radio_clk);
          rx_frame  <= 1'b0;
          rx_data   <= i+1;
        end
      end
      begin
        while ({rx_i0, rx_q0} == 24'd0) @(posedge radio_clk);
        for (int i = 1; i < 64; i = i + 2) begin
          // RX should be replicated across both ports
          `ASSERT_ERROR(rx_i0 == i,   "RX0 I incorrect!");
          `ASSERT_ERROR(rx_q0 == i+1, "RX0 Q incorrect!");
          `ASSERT_ERROR(rx_i1 == i,   "RX1 I incorrect!");
          `ASSERT_ERROR(rx_q1 == i+1, "RX1 Q incorrect!");
          @(posedge radio_clk);
        end
      end
    join
    `TEST_CASE_DONE(1);

    `TEST_CASE_START("Test RX channels 0 & 1 (MIMO mode)");
    mimo      <= 1'b1;
    rx_frame  <= 1'b0;
    rx_data   <= 'd0;
    repeat (10) @(posedge radio_clk);
    fork
      begin
        for (int i = 1; i < 64; i = i + 2) begin
          @(posedge radio_clk);
          rx_frame  <= ~rx_frame;
          rx_data   <= i;
          @(negedge radio_clk);
          rx_data   <= i+1;
        end
      end
      begin
        while ({rx_i0, rx_q0} == 24'd0) @(posedge radio_clk);
        for (int i = 1; i < 32; i = i + 4) begin
          // RX should be replicated across both ports
          `ASSERT_ERROR(rx_i0 == i,   "RX0 I incorrect!");
          `ASSERT_ERROR(rx_q0 == i+1, "RX0 Q incorrect!");
          @(posedge radio_clk);
          `ASSERT_ERROR(rx_i1 == i+2, "RX1 I incorrect!");
          `ASSERT_ERROR(rx_q1 == i+3, "RX1 Q incorrect!");
          @(posedge radio_clk);
        end
      end
    join
    `TEST_CASE_DONE(1);

    `TEST_CASE_START("Test TX channel 0");
    mimo  <= 1'b0;
    tx_i0 <= 'd0;
    tx_q0 <= 'd0;
    tx_i1 <= 'd0;
    tx_q1 <= 'd0;
    repeat (10) @(posedge radio_clk);
    // TX0
    fork
      begin
        for (int i = 1; i < 64; i = i + 2) begin
          tx_i0 <= i;
          tx_q0 <= i+1;
          @(posedge radio_clk);
        end
      end
      begin
        while (tx_data == 12'd0) @(posedge tx_clk);
        for (int i = 1; i < 64; i = i + 2) begin
          // RX should be replicated across both ports
          `ASSERT_ERROR(tx_data  == i, "TX0 I data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b1, "TX frame incorrect");
          @(negedge tx_clk);
          `ASSERT_ERROR(tx_data  == i+1, "TX0 Q data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b0, "TX frame incorrect");
          @(posedge tx_clk);
        end
      end
    join
    `TEST_CASE_DONE(1);

    `TEST_CASE_START("Test TX channel 1");
    mimo  <= 1'b0;
    tx_i0 <= 'd0;
    tx_q0 <= 'd0;
    tx_i1 <= 'd0;
    tx_q1 <= 'd0;
    repeat (10) @(posedge radio_clk);
    fork
      begin
        for (int i = 1; i < 64; i = i + 2) begin
          tx_i1 <= i;
          tx_q1 <= i+1;
          @(posedge radio_clk);
        end
      end
      begin
        while (tx_data == 12'd0) @(posedge tx_clk);
        for (int i = 1; i < 64; i = i + 2) begin
          `ASSERT_ERROR(tx_data  == i, "TX1 I data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b1, "TX frame incorrect");
          @(negedge tx_clk);
          `ASSERT_ERROR(tx_data  == i+1, "TX1 Q data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b0, "TX frame incorrect");
          @(posedge tx_clk);
        end
      end
    join
    `TEST_CASE_DONE(1);

    `TEST_CASE_START("Test TX channel 0 & 1 (MIMO)");
    mimo  <= 1'b1;
    tx_i0 <= 'd0;
    tx_q0 <= 'd0;
    tx_i1 <= 'd0;
    tx_q1 <= 'd0;
    repeat (10) @(posedge radio_clk);
    fork
      begin
        for (int i = 1; i < 32; i = i + 4) begin
          tx_i0 <= i;
          tx_q0 <= i+1;
          tx_i1 <= i+2;
          tx_q1 <= i+3;
          @(posedge radio_clk);
          while (tx_stb) @(posedge radio_clk);
        end
      end
      begin
        while (tx_data == 12'd0) @(posedge tx_clk);
        for (int i = 1; i < 32; i = i + 4) begin
          `ASSERT_ERROR(tx_data  == i, "TX0 I data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b1, "TX frame incorrect");
          @(negedge tx_clk);
          `ASSERT_ERROR(tx_data  == i+1, "TX0 Q data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b1, "TX frame incorrect");
          @(posedge tx_clk);
          `ASSERT_ERROR(tx_data  == i+2, "TX1 I data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b0, "TX frame incorrect");
          @(negedge tx_clk);
          `ASSERT_ERROR(tx_data  == i+3, "TX1 Q data incorrect!");
          `ASSERT_ERROR(tx_frame == 1'b0, "TX frame incorrect");
          @(posedge tx_clk);
        end
      end
    join
    `TEST_CASE_DONE(1);
    `TEST_BENCH_DONE;
  end

endmodule