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

Subversion Repositories axi4_tlm_bfm

[/] [axi4_tlm_bfm/] [trunk/] [tester/] [tester.vhdl] - Blame information for rev 24

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

Line No. Rev Author Line
1 24 daniel.kho
/*
2
        This file is part of the AXI4 Transactor and Bus Functional Model
3
        (axi4_tlm_bfm) project:
4
                http://www.opencores.org/project,axi4_tlm_bfm
5
 
6
        Description
7
        Synthesisable use case for AXI4 on-chip messaging.
8
 
9
        To Do:
10
 
11
        Author(s):
12
        - Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
13
 
14
        Copyright (C) 2012-2013 Authors and OPENCORES.ORG
15
 
16
        This source file may be used and distributed without
17
        restriction provided that this copyright statement is not
18
        removed from the file and that any derivative work contains
19
        the original copyright notice and the associated disclaimer.
20
 
21
        This source file is free software; you can redistribute it
22
        and/or modify it under the terms of the GNU Lesser General
23
        Public License as published by the Free Software Foundation;
24
        either version 2.1 of the License, or (at your option) any
25
        later version.
26
 
27
        This source is distributed in the hope that it will be
28
        useful, but WITHOUT ANY WARRANTY; without even the implied
29
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
30
        PURPOSE. See the GNU Lesser General Public License for more
31
        details.
32
 
33
        You should have received a copy of the GNU Lesser General
34
        Public License along with this source; if not, download it
35
        from http://www.opencores.org/lgpl.shtml.
36
*/
37
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all; use ieee.math_real.all;
38
library tauhop; use tauhop.transactor.all, tauhop.axiTransactor.all;            --TODO just use axiTransactor here as transactor should already be wrapped up.
39
 
40
/* TODO remove once generic packages are supported. */
41
--library tauhop; use tauhop.tlm.all, tauhop.axiTLM.all;
42
 
43
/* synthesis translate_off */
44
library osvvm; use osvvm.RandomPkg.all; use osvvm.CoveragePkg.all;
45
/* synthesis translate_on */
46
 
47
--library altera; use altera.stp;
48
 
49
 
50
entity tester is port(
51
        /* Comment-out for simulation. */
52
        clk,reset:in std_ulogic;
53
 
54
        /* AXI Master interface */
55
        axiMaster_in:buffer t_axi4StreamTransactor_s2m;
56
        axiMaster_out:in t_axi4StreamTransactor_m2s;
57
 
58
        /* BFM signalling. */
59
--      readRequest,writeRequest:t_bfm:=(address=>(others=>'X'),message=>(others=>'X'),trigger=>false);
60
--      readResponse,writeResponse:t_bfm;
61
        readRequest,writeRequest:buffer t_bfm;
62
        readResponse,writeResponse:in t_bfm;
63
 
64
        irq_write:buffer std_ulogic;            -- clock gating.
65
 
66
        symbolsPerTransfer:buffer t_cnt;
67
        outstandingTransactions:buffer t_cnt;
68
 
69
        /* Debug ports. */
70
--      dataIn:in t_msg;
71
        selTxn:in unsigned(3 downto 0)
72
);
73
end entity tester;
74
 
75
architecture rtl of tester is
76
--      signal reset:std_ulogic:='0';
77
        signal locked:std_ulogic;
78
        signal porCnt:unsigned(3 downto 0);
79
        signal trigger:boolean;
80
 
81
        /* Global counters. */
82
        constant maxSymbols:positive:=2048;             --maximum number of symbols allowed to be transmitted in a frame. Each symbol's width equals tData's width. 
83
--      signal symbolsPerTransfer:t_cnt;
84
--      signal outstandingTransactions:t_cnt;
85
 
86
--      /* BFM signalling. */
87
--      signal readRequest,writeRequest:t_bfm:=(address=>(others=>'X'),message=>(others=>'X'),trigger=>false);
88
--      signal readResponse,writeResponse:t_bfm;
89
 
90
        type txStates is (idle,transmitting);
91
        signal txFSM,i_txFSM:txStates;
92
 
93
        /* Tester signals. */
94
        /* synthesis translate_off */
95
--      signal clk,nReset:std_ulogic:='0';
96
        attribute period:time; attribute period of clk:signal is 10 ps;
97
        /* synthesis translate_on */
98
 
99
        signal testerClk:std_ulogic;
100
        signal dbg_axiTxFSM:axiBfmStatesTx;
101
        signal anlysr_dataIn:std_logic_vector(127 downto 0);
102
        signal anlysr_trigger:std_ulogic;
103
 
104
--      signal axiMaster_in:t_axi4StreamTransactor_s2m;
105
--      signal irq_write:std_ulogic;            -- clock gating.
106
 
107
        signal prbs:t_msg;
108
 
109
begin
110
        /* PLL to generate tester's clock. */
111
/*    f100MHz: entity altera.pll(syn) port map(
112
        areset=>'0',    --not nReset,
113
        inclk0=>clk,
114
        c0=>testerClk,
115
        locked=>locked
116
    );
117
*/
118
        /* Interrupt-request generator. */
119
        trigger<=txFSM/=i_txFSM or writeResponse.trigger;
120
        irq_write<=clk when not reset else '0';
121
 
122
        /* SignalTap II embedded logic analyser. Included as part of BiST architecture. */
123
        --anlysr_trigger<='1' when writeRequest.trigger else '0';
124
        anlysr_trigger<='1' when reset else '0';
125
 
126
        /* Disable this for synthesis as this is not currently synthesisable.
127
                Pull the framerFSM statemachine signal from lower down the hierarchy to this level instead.
128
        */
129
        /* synthesis translate_off */
130
        --framerFSM<=to_unsigned(<<signal framers_txs(0).i_framer.framerFSM: framerFsmStates>>,framerFSM'length);
131
        /* synthesis translate_on */
132
 
133
        anlysr_dataIn(7 downto 0)<=std_logic_vector(symbolsPerTransfer(7 downto 0));
134
        anlysr_dataIn(15 downto 8)<=std_logic_vector(outstandingTransactions(7 downto 0));
135
        --anlysr_dataIn(2 downto 0) <= <<signal axiMaster.axiTxState:axiBfmStatesTx>>;
136
        anlysr_dataIn(17 downto 16)<=to_std_logic_vector(dbg_axiTxFSM);
137
        anlysr_dataIn(18)<='1' when clk else '0';
138
        anlysr_dataIn(19)<='1' when reset else '0';
139
        anlysr_dataIn(20)<='1' when irq_write else '0';
140
        anlysr_dataIn(21)<='1' when axiMaster_in.tReady else '0';
141
        anlysr_dataIn(22)<='1' when axiMaster_out.tValid else '0';
142
        anlysr_dataIn(54 downto 23)<=std_logic_vector(axiMaster_out.tData);
143
        anlysr_dataIn(86 downto 55)<=std_logic_vector(prbs);
144
        --anlysr_dataIn(90 downto 87)<=std_logic_vector(axiMaster_out.tStrb);
145
        --anlysr_dataIn(94 downto 91)<=std_logic_vector(axiMaster_out.tKeep);
146
        anlysr_dataIn(95)<='1' when axiMaster_out.tLast else '0';
147
        anlysr_dataIn(96)<='1' when writeRequest.trigger else '0';
148
        anlysr_dataIn(97)<='1' when writeResponse.trigger else '0';
149
        anlysr_dataIn(99 downto 98)<=to_std_logic_vector(dbg_axiTxFSM);
150
        anlysr_dataIn(101 downto 98)<=std_logic_vector(porCnt);
151
--      anlysr_dataIn(102)<='1' when locked else '0';
152
--      anlysr_dataIn(102)<=locked;
153
 
154
        anlysr_dataIn(anlysr_dataIn'high downto 102)<=(others=>'0');
155
 
156
 
157
        /* Simulate only if you have compiled Altera's simulation libraries. */
158
/*      i_bist_logicAnalyser: entity altera.stp(syn) port map(
159
                acq_clk=>testerClk,
160
                acq_data_in=>anlysr_dataIn,
161
                acq_trigger_in=>"1",
162
                trigger_in=>anlysr_trigger
163
        );
164
*/
165
 
166
 
167
        /* Stimuli sequencer. TODO move to tester/stimuli.
168
                This emulates the AXI4-Stream Slave.
169
        */
170
        /* Simulation-only stimuli sequencer. */
171
        /* synthesis translate_off */
172
        process is begin
173
                report "Performing fast read..." severity note;
174
 
175
                /* Fast read. */
176
                while not axiMaster_out.tLast loop
177
                        /* Wait for tValid to assert. */
178
                        while not axiMaster_out.tValid loop
179
                                wait until falling_edge(clk);
180
                        end loop;
181
 
182
                        axiMaster_in.tReady<=true;
183
 
184
                        wait until falling_edge(clk);
185
                        axiMaster_in.tReady<=false;
186
                end loop;
187
 
188
                wait until falling_edge(clk);
189
                report "Performing normal read..." severity note;
190
 
191
                /* Normal read. */
192
                while not axiMaster_out.tLast loop
193
                        /* Wait for tValid to assert. */
194
                        while not axiMaster_out.tValid loop
195
                                wait until falling_edge(clk);
196
                        end loop;
197
 
198
                        wait until falling_edge(clk);
199
                        wait until falling_edge(clk);
200
                        axiMaster_in.tReady<=true;
201
 
202
                        wait until falling_edge(clk);
203
                        axiMaster_in.tReady<=false;
204
 
205
                        wait until falling_edge(clk);
206
                end loop;
207
 
208
                report "Completed normal read." severity note;
209
 
210
                for i in 0 to 10 loop
211
                        wait until falling_edge(clk);
212
                end loop;
213
 
214
                /* One-shot read. */
215
                axiMaster_in.tReady<=true;
216
 
217
                wait until falling_edge(clk);
218
                axiMaster_in.tReady<=false;
219
 
220
                report "Completed one-shot read." severity note;
221
 
222
                wait;
223
        end process;
224
        /* synthesis translate_on */
225
 
226
        /* Synthesisable stimuli sequencer. */
227
/*      process(clk) is begin
228
                if falling_edge(clk) then
229
                        axiMaster_in.tReady<=false;
230
                        --if axiMaster_out.tValid and not axiMaster_out.tLast then
231
                        if not axiMaster_in.tReady and axiMaster_out.tValid and not axiMaster_out.tLast then
232
                                axiMaster_in.tReady<=true;
233
                        end if;
234
                end if;
235
        end process;
236
*/
237
 
238
        /* Data transmitter. */
239
        i_prbs: entity tauhop.prbs31(rtl)
240
                generic map(
241
                        isParallelLoad=>true,
242
                        tapVector=>(
243
                                /* Example polynomial from Wikipedia:
244
                                        http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
245
                                */
246
                                0|3|31=>true, 1|2|30 downto 4=>false
247
                        )
248
                )
249
                port map(
250
                        /* Comment-out for simulation. */
251
                        clk=>irq_write, reset=>reset,
252
                        en=>trigger,
253
                        seed=>32x"ace1",        --9x"57",
254
                        prbs=>prbs
255
                );
256
 
257
        sequencer_ns: process(all) is begin
258
                txFSM<=i_txFSM;
259
                if reset then txFSM<=idle;
260
                else
261
                        case i_txFSM is
262
                                when idle=>
263
                                        if outstandingTransactions>0 then txFSM<=transmitting; end if;
264
                                when transmitting=>
265
                                        if axiMaster_out.tLast then
266
                                                txFSM<=idle;
267
                                        end if;
268
                                when others=> null;
269
                        end case;
270
                end if;
271
        end process sequencer_ns;
272
 
273
        sequencer_op: process(reset,irq_write) is
274
                /* Local procedures to map BFM signals with the package procedure. */
275
                procedure read(address:in t_addr) is begin
276
                        read(readRequest,address);
277
                end procedure read;
278
 
279
                procedure write(data:in t_msg) is begin
280
                        write(request=>writeRequest, address=>(others=>'-'), data=>data);
281
                end procedure write;
282
 
283
                variable isPktError:boolean;
284
 
285
                /* Tester variables. */
286
                /* Synthesis-only randomisation. */
287
 
288
                /* Simulation-only randomisation. */
289
                /* synthesis translate_off */
290
                variable rv0:RandomPType;
291
                /* synthesis translate_on */
292
 
293
--              variable trigger:boolean;
294
        begin
295
--              if reset then
296
                        /* simulation only. */
297
                        /* synthesis translate_off */
298
--                      rv0.InitSeed(rv0'instance_name);
299
                        /* synthesis translate_on */
300
                if falling_edge(irq_write) then
301
                        case txFSM is
302
                                when transmitting=>
303
                                        if trigger then
304
                                                /* Pseudorandom stimuli generation using OS-VVM. */
305
                                                /* synthesis translate_off */
306
                                                write(rv0.RandSigned(axiMaster_out.tData'length));
307
                                                /* synthesis translate_on */
308
 
309
                                                /* Pseudorandom stimuli generation using LFSR. */
310
                                                /*
311
                                                case selTxn is
312
                                                        when x"1"=> write(32x"12ab34cd");
313
                                                        when x"2"=> write(32x"12345678");
314
                                                        when x"3"=> write(32x"87654321");
315
                                                        when x"4"=> write(32x"abcd1234");
316
                                                        when others=> write(prbs);
317
                                                end case;
318
                                                */
319
                                        end if;
320
                                when others=>null;
321
                        end case;
322
                end if;
323
        end process sequencer_op;
324
 
325
        sequencer_regs: process(irq_write) is begin
326
        if falling_edge(irq_write) then
327
            i_txFSM<=txFSM;
328
        end if;
329
    end process sequencer_regs;
330
 
331
    /* Transaction counter. */
332
        process(reset,symbolsPerTransfer,irq_write) is begin
333
                /* TODO close timing for asynchronous reset. */
334
                if reset then outstandingTransactions<=symbolsPerTransfer;
335
                elsif rising_edge(irq_write) then
336
                        if not axiMaster_out.tLast then
337
                                if outstandingTransactions<1 then
338
                                        outstandingTransactions<=symbolsPerTransfer;
339
                                        report "No more pending transactions." severity note;
340
                                elsif axiMaster_in.tReady then outstandingTransactions<=outstandingTransactions-1;
341
                                end if;
342
                        end if;
343
 
344
                        /* Use synchronous reset for outstandingTransactions to meet timing because it is a huge register set. */
345
                        if reset then outstandingTransactions<=symbolsPerTransfer; end if;
346
                end if;
347
        end process;
348
 
349
        /* Reset symbolsPerTransfer to new value (prepare for new transfer) after current transfer has been completed. */
350
        process(reset,irq_write) is
351
                /* synthesis translate_off */
352
                variable rv0:RandomPType;
353
                /* synthesis translate_on */
354
        begin
355
                if reset then
356
                        /* synthesis translate_off */
357
                        rv0.InitSeed(rv0'instance_name);
358
                        symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
359
                        report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length)) severity note;
360
                        /* synthesis translate_on */
361
 
362
                        symbolsPerTransfer<=128x"fc";
363
                elsif rising_edge(irq_write) then
364
                        if axiMaster_out.tLast then
365
                                /* synthesis only. */
366
                                /* Testcase 1: number of symbols per transfer becomes 0 after first stream transfer. */
367
                                --symbolsPerTransfer<=(others=>'0');
368
 
369
                                /* Testcase 2: number of symbols per transfer is randomised. */
370
                                --uniform(seed0,seed1,rand0);
371
                                --symbolsPerTransfer<=120x"0" & to_unsigned(integer(rand0 * 2.0**8),8);  --symbolsPerTransfer'length
372
                                --report "symbols per transfer = " & ieee.numeric_std.to_hstring(to_unsigned(integer(rand0 * 2.0**8),8));       --axiMaster_out.tData'length));
373
 
374
 
375
                                /* synthesis translate_off */
376
                                symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
377
                                report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length)) severity note;
378
                                /* synthesis translate_on */
379
 
380
                                symbolsPerTransfer<=128x"0f";           --128x"ffffffff_ffffffff_ffffffff_ffffffff";
381
                        end if;
382
                end if;
383
        end process;
384
 
385
--    outstandingTransactions<=128x"fc";      --symbolsPerTransfer;
386
end architecture rtl;

powered by: WebSVN 2.1.0

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