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 42

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 38 daniel.kho
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all, ieee.math_real.all;
38 24 daniel.kho
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 38 daniel.kho
library osvvm; use osvvm.RandomPkg.all, osvvm.CoveragePkg.all;
45 24 daniel.kho
/* synthesis translate_on */
46
 
47
--library altera; use altera.stp;
48
 
49
 
50
entity tester is port(
51
        clk,reset:in std_ulogic;
52
 
53
        /* AXI Master interface */
54
        axiMaster_in:buffer t_axi4StreamTransactor_s2m;
55
        axiMaster_out:in t_axi4StreamTransactor_m2s;
56
 
57
        /* BFM signalling. */
58
        readRequest,writeRequest:buffer t_bfm;
59
        readResponse,writeResponse:in t_bfm;
60
 
61
        irq_write:buffer std_ulogic;            -- clock gating.
62
 
63 38 daniel.kho
        lastTransaction:out boolean;
64 24 daniel.kho
 
65
        /* Debug ports. */
66
        selTxn:in unsigned(3 downto 0)
67
);
68
end entity tester;
69
 
70
architecture rtl of tester is
71
        signal locked:std_ulogic;
72
        signal porCnt:unsigned(3 downto 0);
73
        signal trigger:boolean;
74
 
75
        /* Global counters. */
76
        constant maxSymbols:positive:=2048;             --maximum number of symbols allowed to be transmitted in a frame. Each symbol's width equals tData's width. 
77
--      signal symbolsPerTransfer:t_cnt;
78
--      signal outstandingTransactions:t_cnt;
79
 
80
--      /* BFM signalling. */
81
--      signal readRequest,writeRequest:t_bfm:=(address=>(others=>'X'),message=>(others=>'X'),trigger=>false);
82
--      signal readResponse,writeResponse:t_bfm;
83
 
84
        type txStates is (idle,transmitting);
85
        signal txFSM,i_txFSM:txStates;
86
 
87
        /* Tester signals. */
88
        /* synthesis translate_off */
89
        attribute period:time; attribute period of clk:signal is 10 ps;
90
        /* synthesis translate_on */
91
 
92
        signal testerClk:std_ulogic;
93
        signal dbg_axiTxFSM:axiBfmStatesTx;
94
        signal anlysr_dataIn:std_logic_vector(127 downto 0);
95
        signal anlysr_trigger:std_ulogic;
96
 
97
--      signal axiMaster_in:t_axi4StreamTransactor_s2m;
98
--      signal irq_write:std_ulogic;            -- clock gating.
99
 
100
        signal prbs:t_msg;
101
 
102 38 daniel.kho
        /* Coverage-driven randomisation. */
103 42 daniel.kho
        /* synthesis translate_off */
104 38 daniel.kho
        shared variable rv0:covPType;
105 42 daniel.kho
        /* synthesis translate_on */
106 38 daniel.kho
        signal rv:integer;
107
        signal pctCovered:real;
108
        signal isCovered,i_isCovered:boolean;
109
 
110 24 daniel.kho
begin
111
        /* PLL to generate tester's clock. */
112
/*    f100MHz: entity altera.pll(syn) port map(
113
        areset=>'0',    --not nReset,
114
        inclk0=>clk,
115
        c0=>testerClk,
116
        locked=>locked
117
    );
118
*/
119
        /* Interrupt-request generator. */
120
        trigger<=txFSM/=i_txFSM or writeResponse.trigger;
121 42 daniel.kho
--      trigger<=(txFSM/=i_txFSM and txFSM=transmitting) or writeResponse.trigger;      -- fixes bug when multiple transactions occur during endOfTx (this should be illegal).
122 24 daniel.kho
        irq_write<=clk when not reset else '0';
123
 
124
        /* SignalTap II embedded logic analyser. Included as part of BiST architecture. */
125
        --anlysr_trigger<='1' when writeRequest.trigger else '0';
126
        anlysr_trigger<='1' when reset else '0';
127
 
128
        /* Disable this for synthesis as this is not currently synthesisable.
129
                Pull the framerFSM statemachine signal from lower down the hierarchy to this level instead.
130
        */
131
        /* synthesis translate_off */
132
        --framerFSM<=to_unsigned(<<signal framers_txs(0).i_framer.framerFSM: framerFsmStates>>,framerFSM'length);
133
        /* synthesis translate_on */
134
 
135 38 daniel.kho
--      anlysr_dataIn(7 downto 0)<=std_logic_vector(symbolsPerTransfer(7 downto 0));
136
--      anlysr_dataIn(15 downto 8)<=std_logic_vector(outstandingTransactions(7 downto 0));
137 24 daniel.kho
        --anlysr_dataIn(2 downto 0) <= <<signal axiMaster.axiTxState:axiBfmStatesTx>>;
138
        anlysr_dataIn(17 downto 16)<=to_std_logic_vector(dbg_axiTxFSM);
139
        anlysr_dataIn(18)<='1' when clk else '0';
140
        anlysr_dataIn(19)<='1' when reset else '0';
141
        anlysr_dataIn(20)<='1' when irq_write else '0';
142
        anlysr_dataIn(21)<='1' when axiMaster_in.tReady else '0';
143
        anlysr_dataIn(22)<='1' when axiMaster_out.tValid else '0';
144
        anlysr_dataIn(54 downto 23)<=std_logic_vector(axiMaster_out.tData);
145
        anlysr_dataIn(86 downto 55)<=std_logic_vector(prbs);
146
        --anlysr_dataIn(90 downto 87)<=std_logic_vector(axiMaster_out.tStrb);
147
        --anlysr_dataIn(94 downto 91)<=std_logic_vector(axiMaster_out.tKeep);
148
        anlysr_dataIn(95)<='1' when axiMaster_out.tLast else '0';
149
        anlysr_dataIn(96)<='1' when writeRequest.trigger else '0';
150
        anlysr_dataIn(97)<='1' when writeResponse.trigger else '0';
151
        anlysr_dataIn(99 downto 98)<=to_std_logic_vector(dbg_axiTxFSM);
152
        anlysr_dataIn(101 downto 98)<=std_logic_vector(porCnt);
153
--      anlysr_dataIn(102)<='1' when locked else '0';
154
--      anlysr_dataIn(102)<=locked;
155
 
156
        anlysr_dataIn(anlysr_dataIn'high downto 102)<=(others=>'0');
157
 
158
 
159
        /* Simulate only if you have compiled Altera's simulation libraries. */
160
/*      i_bist_logicAnalyser: entity altera.stp(syn) port map(
161
                acq_clk=>testerClk,
162
                acq_data_in=>anlysr_dataIn,
163
                acq_trigger_in=>"1",
164
                trigger_in=>anlysr_trigger
165
        );
166
*/
167
 
168
 
169
        /* Stimuli sequencer. TODO move to tester/stimuli.
170
                This emulates the AXI4-Stream Slave.
171
        */
172
        /* Simulation-only stimuli sequencer. */
173
        /* synthesis translate_off */
174
        process is begin
175 38 daniel.kho
                /* Fast read. */
176 24 daniel.kho
                report "Performing fast read..." severity note;
177
                while not axiMaster_out.tLast loop
178
                        /* Wait for tValid to assert. */
179
                        while not axiMaster_out.tValid loop
180
                                wait until falling_edge(clk);
181
                        end loop;
182
 
183
                        axiMaster_in.tReady<=true;
184
 
185
                        wait until falling_edge(clk);
186
                        axiMaster_in.tReady<=false;
187 38 daniel.kho
 
188
                        report "coverage: " & to_string(pctCovered) severity note;
189 24 daniel.kho
                end loop;
190 38 daniel.kho
                report "coverage: " & to_string(pctCovered) severity note;
191
                report "Completed fast read." severity note;
192 24 daniel.kho
 
193
                wait until falling_edge(clk);
194
 
195
                /* Normal read. */
196 38 daniel.kho
                report "Performing normal read..." severity note;
197 24 daniel.kho
                while not axiMaster_out.tLast loop
198 38 daniel.kho
                        wait until falling_edge(clk);
199
 
200 24 daniel.kho
                        /* Wait for tValid to assert. */
201
                        while not axiMaster_out.tValid loop
202
                                wait until falling_edge(clk);
203
                        end loop;
204
 
205
                        wait until falling_edge(clk);
206
                        wait until falling_edge(clk);
207
                        axiMaster_in.tReady<=true;
208
 
209
                        wait until falling_edge(clk);
210
                        axiMaster_in.tReady<=false;
211
 
212 42 daniel.kho
                        wait until falling_edge(clk);
213 38 daniel.kho
 
214
                        report "coverage: " & to_string(pctCovered) severity note;
215 24 daniel.kho
                end loop;
216 38 daniel.kho
                report "coverage: " & to_string(pctCovered) severity note;
217 24 daniel.kho
                report "Completed normal read." severity note;
218
 
219
                for i in 0 to 10 loop
220
                        wait until falling_edge(clk);
221
                end loop;
222
 
223
                /* One-shot read. */
224 38 daniel.kho
                report "Performing one-shot read..." severity note;
225 24 daniel.kho
                axiMaster_in.tReady<=true;
226
 
227
                wait until falling_edge(clk);
228
                axiMaster_in.tReady<=false;
229
 
230 38 daniel.kho
                report "coverage: " & to_string(pctCovered) severity note;
231 24 daniel.kho
                report "Completed one-shot read." severity note;
232
 
233
                wait;
234
        end process;
235
        /* synthesis translate_on */
236
 
237
        /* Synthesisable stimuli sequencer. */
238
/*      process(clk) is begin
239
                if falling_edge(clk) then
240
                        axiMaster_in.tReady<=false;
241
                        --if axiMaster_out.tValid and not axiMaster_out.tLast then
242
                        if not axiMaster_in.tReady and axiMaster_out.tValid and not axiMaster_out.tLast then
243
                                axiMaster_in.tReady<=true;
244
                        end if;
245
                end if;
246
        end process;
247
*/
248
 
249
        /* Data transmitter. */
250 38 daniel.kho
        /* Use either PRBS (LFSR) stimuli, or OSVVM randomisation stimuli, not both. */
251 24 daniel.kho
        i_prbs: entity tauhop.prbs31(rtl)
252
                generic map(
253
                        isParallelLoad=>true,
254
                        tapVector=>(
255
                                /* Example polynomial from Wikipedia:
256
                                        http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
257
                                */
258
                                0|3|31=>true, 1|2|30 downto 4=>false
259
                        )
260
                )
261
                port map(
262
                        /* Comment-out for simulation. */
263
                        clk=>irq_write, reset=>reset,
264
                        en=>trigger,
265 38 daniel.kho
                        seed=>32x"ace1",
266 24 daniel.kho
                        prbs=>prbs
267
                );
268
 
269 42 daniel.kho
        sequencer_ns: process(all) is
270
                variable last:boolean;
271
        begin
272 24 daniel.kho
                txFSM<=i_txFSM;
273 42 daniel.kho
 
274 24 daniel.kho
                if reset then txFSM<=idle;
275
                else
276
                        case i_txFSM is
277
                                when idle=>
278 38 daniel.kho
                                        if not lastTransaction then txFSM<=transmitting; end if;
279 42 daniel.kho
                                        last:=false;
280 24 daniel.kho
                                when transmitting=>
281 42 daniel.kho
                                        --if axiMaster_out.tLast then
282
                                        --      txFSM<=idle;
283
                                        --end if;
284
 
285
                                        /* Fixes multiple transactions when axiTxState=endOfTx. Do not allow
286
                                                txFSM to enter idle until a tReady has been received after the
287
                                                last transaction.
288
                                        */
289
                                        if lastTransaction then last:=true; end if;
290
                                        if axiMaster_in.tReady and last then txFSM<=idle; end if;
291 24 daniel.kho
                                when others=> null;
292
                        end case;
293
                end if;
294
        end process sequencer_ns;
295
 
296
        sequencer_op: process(reset,irq_write) is
297
                /* Local procedures to map BFM signals with the package procedure. */
298
                procedure read(address:in t_addr) is begin
299
                        read(readRequest,address);
300
                end procedure read;
301
 
302
                procedure write(data:in t_msg) is begin
303
                        write(request=>writeRequest, address=>(others=>'-'), data=>data);
304
                end procedure write;
305
 
306
                variable isPktError:boolean;
307
 
308
        begin
309 38 daniel.kho
                /* Asynchronous reset. */
310 40 daniel.kho
                if reset then rv<=rv0.randCovPoint; rv0.iCover(rv);
311
                elsif falling_edge(irq_write) then
312
                        if reset then
313
                                rv<=rv0.randCovPoint;
314
                                rv0.iCover(rv);
315
                        end if;
316
 
317 24 daniel.kho
                        case txFSM is
318
                                when transmitting=>
319 38 daniel.kho
                                        if trigger and not isCovered then
320 24 daniel.kho
                                                /* Pseudorandom stimuli generation using OS-VVM. */
321
                                                /* synthesis translate_off */
322 38 daniel.kho
                                                rv<=rv0.randCovPoint;
323
                                                rv0.iCover(rv);
324
 
325
                                                write(to_signed(rv, axiMaster_out.tData'length));
326 24 daniel.kho
                                                /* synthesis translate_on */
327
 
328
                                                /* Pseudorandom stimuli generation using LFSR. */
329
                                                /*
330
                                                case selTxn is
331
                                                        when x"1"=> write(32x"12ab34cd");
332
                                                        when x"2"=> write(32x"12345678");
333
                                                        when x"3"=> write(32x"87654321");
334
                                                        when x"4"=> write(32x"abcd1234");
335
                                                        when others=> write(prbs);
336
                                                end case;
337
                                                */
338
                                        end if;
339
                                when others=>null;
340
                        end case;
341
                end if;
342
        end process sequencer_op;
343
 
344 42 daniel.kho
 
345
        /* simulation only. */
346
        /* synthesis translate_off */
347 38 daniel.kho
        coverageMonitor: process is
348
                procedure initialise is begin
349
                        rv0.deallocate;                 --destroy rv0 and all bins.
350
                        rv0.initSeed(rv0'instance_name);
351
                end procedure initialise;
352
 
353
        begin
354
                /* Fast- and normal-reads. */
355
                for i in 0 to 1 loop
356
                        initialise;
357
                        rv0.addBins(genBin(integer'low,integer'high,512));
358
 
359
                        wait until isCovered;
360
--                      rv0.writeBin;
361
                        rv0.setCovZero;         -- reset all coverage counts to zero.
362
                end loop;
363
 
364
                /* One-shot read. */
365
                initialise;
366
                rv0.addBins(genBin(integer'low,integer'high,1));
367
 
368
                wait until isCovered;
369
--              rv0.writeBin;
370
                rv0.setCovZero;
371
 
372
        wait for 500 ps;
373
        std.env.stop;
374
    end process coverageMonitor;
375
 
376
        process(irq_write) is begin
377
                if falling_edge(irq_write) then
378
                        pctCovered<=rv0.getCov;
379
                        isCovered<=rv0.isCovered;
380
                        i_isCovered<=isCovered;
381
                end if;
382
        end process;
383 42 daniel.kho
        /* synthesis translate_on */
384 38 daniel.kho
 
385 42 daniel.kho
 
386 24 daniel.kho
        sequencer_regs: process(irq_write) is begin
387
        if falling_edge(irq_write) then
388
            i_txFSM<=txFSM;
389
        end if;
390
    end process sequencer_regs;
391
 
392 38 daniel.kho
        lastTransaction<=true when isCovered else false;
393 24 daniel.kho
 
394 38 daniel.kho
        checker: process(clk) is begin
395
                if rising_edge(clk) then
396
                        if axiMaster_in.tReady then
397
                                assert axiMaster_out.tData/="ZZZZZZZZ"
398
                                        report "[Error]: tData must be valid when tReady is asserted at the rising edge of the clock." severity error;
399 24 daniel.kho
                        end if;
400
                end if;
401 38 daniel.kho
        end process checker;
402 24 daniel.kho
end architecture rtl;

powered by: WebSVN 2.1.0

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