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

Subversion Repositories axi4_tlm_bfm

[/] [axi4_tlm_bfm/] [trunk/] [rtl/] [quartus-synthesis/] [user.vhdl] - Blame information for rev 15

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

Line No. Rev Author Line
1 9 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 user is port(
51
        /* Comment-out for simulation. */
52
        clk,nReset:in std_ulogic;
53
 
54
        /* AXI Master interface */
55
--      axiMaster_in:in t_axi4StreamTransactor_s2m;
56
        axiMaster_out:buffer t_axi4StreamTransactor_m2s
57
 
58
        /* Debug ports. */
59
);
60
end entity user;
61
 
62
architecture rtl of user is
63
        /* Global counters. */
64
        constant maxSymbols:positive:=2048;             --maximum number of symbols allowed to be transmitted in a frame. Each symbol's width equals tData's width. 
65
        signal symbolsPerTransfer:t_cnt;
66
        signal outstandingTransactions:t_cnt;
67
 
68
        /* BFM signalling. */
69 11 daniel.kho
        signal readRequest:t_bfm:=((others=>'0'),(others=>'0'),false);
70
        signal writeRequest:t_bfm:=((others=>'0'),(others=>'0'),false);
71
        signal readResponse:t_bfm;
72
        signal writeResponse:t_bfm;
73 9 daniel.kho
 
74 11 daniel.kho
        type txStates is (idle,transmitting);
75
        signal txFSM,i_txFSM:txStates;
76 9 daniel.kho
 
77
        /* Tester signals. */
78
        /* synthesis translate_off */
79 14 daniel.kho
        signal clk,reset:std_ulogic:='0';
80 9 daniel.kho
        /* synthesis translate_on */
81 13 daniel.kho
 
82 14 daniel.kho
        signal cnt:unsigned(3 downto 0);
83
        signal reset:std_ulogic:='0';
84 13 daniel.kho
        signal testerClk:std_ulogic;
85 11 daniel.kho
        --signal trigger:boolean;
86 13 daniel.kho
        signal dbg_axiTxFSM:axiBfmStatesTx;
87 9 daniel.kho
        signal anlysr_dataIn:std_logic_vector(127 downto 0);
88
        signal anlysr_trigger:std_ulogic;
89
 
90
        signal axiMaster_in:t_axi4StreamTransactor_s2m;
91
        signal irq_write:std_ulogic;            -- clock gating.
92
 
93
begin
94
        /* Bus functional models. */
95 15 daniel.kho
        axiMaster: entity tauhop.axiBfmMaster(rtl)
96 9 daniel.kho
                port map(
97 14 daniel.kho
                        aclk=>irq_write, n_areset=>not reset,
98 9 daniel.kho
 
99
                        readRequest=>readRequest,       writeRequest=>writeRequest,
100
                        readResponse=>readResponse,     writeResponse=>writeResponse,
101
                        axiMaster_in=>axiMaster_in,
102
                        axiMaster_out=>axiMaster_out,
103
 
104
                        symbolsPerTransfer=>symbolsPerTransfer,
105 13 daniel.kho
                        outstandingTransactions=>outstandingTransactions,
106
                        dbg_axiTxFSM=>dbg_axiTxFSM
107 9 daniel.kho
        );
108
 
109
        /* Interrupt-request generator. */
110 14 daniel.kho
        irq_write<=clk when not reset else '0';
111 9 daniel.kho
 
112
        /* Simulation Tester. */
113 13 daniel.kho
        /* PLL to generate tester's clock. */
114
        f100MHz: entity altera.pll(syn) port map(
115 15 daniel.kho
                areset=>'0',     --not nReset,
116 13 daniel.kho
                inclk0=>clk,
117
                c0=>testerClk,
118
                locked=>open
119
        );
120
 
121 9 daniel.kho
        /* synthesis translate_off */
122
        clk<=not clk after 10 ps;
123
        process is begin
124
                nReset<='1'; wait for 1 ps;
125
                nReset<='0'; wait for 500 ps;
126
                nReset<='1';
127
                wait;
128
        end process;
129
        /* synthesis translate_on */
130
 
131 13 daniel.kho
 
132 9 daniel.kho
        /* Hardware tester. */
133 14 daniel.kho
        por: process(nReset,clk) is
134
                --variable cnt:unsigned(7 downto 0):=(others=>'1');
135 13 daniel.kho
        begin
136 14 daniel.kho
                if not nReset then cnt<=(others=>'1');
137 13 daniel.kho
                elsif rising_edge(clk) then
138 14 daniel.kho
                        reset<='0';
139 13 daniel.kho
 
140 14 daniel.kho
                        if cnt>0 then reset<='1'; cnt<=cnt-1; end if;
141 13 daniel.kho
                end if;
142
        end process por;
143 9 daniel.kho
 
144
        /* SignalTap II embedded logic analyser. Included as part of BiST architecture. */
145 15 daniel.kho
        --anlysr_trigger<='1' when writeRequest.trigger else '0';
146
        anlysr_trigger<='1' when reset else '0';
147 9 daniel.kho
 
148
        /* Disable this for synthesis as this is not currently synthesisable.
149
                Pull the framerFSM statemachine signal from lower down the hierarchy to this level instead.
150
        */
151
        /* synthesis translate_off */
152
        --framerFSM<=to_unsigned(<<signal framers_txs(0).i_framer.framerFSM: framerFsmStates>>,framerFSM'length);
153
        /* synthesis translate_on */
154
 
155 13 daniel.kho
        anlysr_dataIn(7 downto 0)<=std_logic_vector(symbolsPerTransfer(7 downto 0));
156
        anlysr_dataIn(15 downto 8)<=std_logic_vector(outstandingTransactions(7 downto 0));
157
        --anlysr_dataIn(2 downto 0) <= <<signal axiMaster.axiTxState:axiBfmStatesTx>>;
158
        anlysr_dataIn(17 downto 16)<=to_std_logic_vector(dbg_axiTxFSM);
159
        anlysr_dataIn(18)<='1' when clk else '0';
160 14 daniel.kho
        anlysr_dataIn(19)<='1' when reset else '0';
161 13 daniel.kho
        anlysr_dataIn(20)<='1' when irq_write else '0';
162
        anlysr_dataIn(21)<='1' when axiMaster_in.tReady else '0';
163
        anlysr_dataIn(22)<='1' when axiMaster_out.tValid else '0';
164
        anlysr_dataIn(86 downto 23)<=std_logic_vector(axiMaster_out.tData);
165
        anlysr_dataIn(90 downto 87)<=std_logic_vector(axiMaster_out.tStrb);
166
        anlysr_dataIn(94 downto 91)<=std_logic_vector(axiMaster_out.tKeep);
167
        anlysr_dataIn(95)<='1' when axiMaster_out.tLast else '0';
168
        anlysr_dataIn(96)<='1' when writeRequest.trigger else '0';
169
        anlysr_dataIn(97)<='1' when writeResponse.trigger else '0';
170
        --anlysr_dataIn(99 downto 98)<=to_std_logic_vector(txFSM);
171 14 daniel.kho
        anlysr_dataIn(101 downto 98)<=std_logic_vector(cnt);
172 9 daniel.kho
 
173 13 daniel.kho
        anlysr_dataIn(anlysr_dataIn'high downto 106)<=(others=>'0');
174 9 daniel.kho
 
175
 
176
        /* Simulate only if you have compiled Altera's simulation libraries. */
177 15 daniel.kho
        i_bist_logicAnalyser: entity altera.stp(syn) port map(
178 13 daniel.kho
                acq_clk=>testerClk,
179 9 daniel.kho
                acq_data_in=>anlysr_dataIn,
180
                acq_trigger_in=>"1",
181
                trigger_in=>anlysr_trigger
182
        );
183
 
184
 
185
 
186 11 daniel.kho
        /* Stimuli sequencer. TODO move to tester/stimuli.
187
                This emulates the AXI4-Stream Slave.
188
        */
189
        /* Simulation-only stimuli sequencer. */
190
        /* synthesis translate_off */
191
        process is begin
192
                /* Fast read. */
193
                while not axiMaster_out.tLast loop
194
                        /* Wait for tValid to assert. */
195
                        while not axiMaster_out.tValid loop
196
                                wait until falling_edge(clk);
197
                        end loop;
198
 
199
                        axiMaster_in.tReady<=true;
200
 
201
                        wait until falling_edge(clk);
202
                        axiMaster_in.tReady<=false;
203
                end loop;
204
 
205
                wait until falling_edge(clk);
206
 
207
                /* Normal read. */
208
                while not axiMaster_out.tLast loop
209
                        /* Wait for tValid to assert. */
210
                        while not axiMaster_out.tValid loop
211
                                wait until falling_edge(clk);
212
                        end loop;
213
 
214
                        wait until falling_edge(clk);
215
                        axiMaster_in.tReady<=true;
216
 
217
                        wait until falling_edge(clk);
218
                        axiMaster_in.tReady<=false;
219
                end loop;
220
 
221
                for i in 0 to 10 loop
222
                        wait until falling_edge(clk);
223
                end loop;
224
 
225
                /* One-shot read. */
226
                axiMaster_in.tReady<=true;
227
 
228
                wait until falling_edge(clk);
229
                axiMaster_in.tReady<=false;
230
 
231
                wait;
232
        end process;
233
        /* synthesis translate_on */
234
 
235
        /* Synthesisable stimuli sequencer. */
236 13 daniel.kho
        process(clk) is begin
237
                if falling_edge(clk) then
238
                        axiMaster_in.tReady<=false;
239
                        --if axiMaster_out.tValid and not axiMaster_out.tLast then
240
                        if not axiMaster_in.tReady and axiMaster_out.tValid and not axiMaster_out.tLast then
241
                                axiMaster_in.tReady<=true;
242
                        end if;
243
                end if;
244
        end process;
245 9 daniel.kho
 
246 13 daniel.kho
 
247 11 daniel.kho
        /* Data transmitter. */
248 13 daniel.kho
        sequencer_ns: process(all) is begin
249
                txFSM<=i_txFSM;
250 14 daniel.kho
                if reset then txFSM<=idle;
251 13 daniel.kho
                else
252
                        case i_txFSM is
253
                                when idle=>
254
                                        if outstandingTransactions>0 then txFSM<=transmitting; end if;
255
                                when transmitting=>
256
                                        if axiMaster_out.tLast then
257
                                                txFSM<=idle;
258
                                        end if;
259
                                when others=> null;
260
                        end case;
261
                end if;
262
        end process sequencer_ns;
263
 
264
        /* Data transmitter. */
265 14 daniel.kho
        sequencer_op: process(reset,irq_write) is
266 9 daniel.kho
                /* Local procedures to map BFM signals with the package procedure. */
267
                procedure read(address:in t_addr) is begin
268
                        read(readRequest,address);
269
                end procedure read;
270
 
271
                procedure write(data:in t_msg) is begin
272
                        write(request=>writeRequest, address=>(others=>'-'), data=>data);
273
                end procedure write;
274
 
275
                variable isPktError:boolean;
276
 
277
                /* Tester variables. */
278
                /* Synthesis-only randomisation. */
279
                variable rand0:signed(63 downto 0);
280
                /* Simulation-only randomisation. */
281
                /* synthesis translate_off */
282 11 daniel.kho
                variable rv0:RandomPType;
283 9 daniel.kho
                /* synthesis translate_on */
284
 
285
        begin
286 14 daniel.kho
                if reset then
287 9 daniel.kho
                        /* synthesis only. */
288
                        rand0:=(others=>'0');
289
 
290
                        /* simulation only. */
291
                        /* synthesis translate_off */
292
                        rv0.InitSeed(rv0'instance_name);
293 11 daniel.kho
                        /* synthesis translate_on */
294
 
295 13 daniel.kho
                        --txFSM<=idle;
296 11 daniel.kho
                elsif falling_edge(irq_write) then
297
                        case txFSM is
298
                                when transmitting=>
299 13 daniel.kho
                                        if txFSM/=i_txFSM or writeResponse.trigger then
300 11 daniel.kho
                                                /* synthesis translate_off */
301
                                                write(rv0.RandSigned(axiMaster_out.tData'length));
302
                                                /* synthesis translate_on */
303
                                                write(rand0);
304
                                                rand0:=rand0+1;
305
                                        end if;
306
                                when others=>null;
307
                        end case;
308
                end if;
309 13 daniel.kho
        end process sequencer_op;
310 11 daniel.kho
 
311 13 daniel.kho
        sequencer_regs: process(irq_write) is begin
312
                if falling_edge(irq_write) then
313
                        i_txFSM<=txFSM;
314
                end if;
315
        end process sequencer_regs;
316
 
317
 
318 11 daniel.kho
        /* Reset symbolsPerTransfer to new value (prepare for new transfer) after current transfer has been completed. */
319 14 daniel.kho
        process(reset,irq_write) is
320 11 daniel.kho
                /* synthesis translate_off */
321
                variable rv0:RandomPType;
322
                /* synthesis translate_on */
323
        begin
324 14 daniel.kho
                if reset then
325 11 daniel.kho
                        /* synthesis translate_off */
326
                        rv0.InitSeed(rv0'instance_name);
327 9 daniel.kho
                        symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
328 11 daniel.kho
                        report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
329 9 daniel.kho
                        /* synthesis translate_on */
330 11 daniel.kho
 
331
                        symbolsPerTransfer<=128x"8";
332
                elsif rising_edge(irq_write) then
333
                        if axiMaster_out.tLast then
334 9 daniel.kho
                                /* synthesis only. */
335
                                /* Testcase 1: number of symbols per transfer becomes 0 after first stream transfer. */
336
                                --symbolsPerTransfer<=(others=>'0');
337
 
338
                                /* Testcase 2: number of symbols per transfer is randomised. */
339
                                --uniform(seed0,seed1,rand0);
340
                                --symbolsPerTransfer<=120x"0" & to_unsigned(integer(rand0 * 2.0**8),8);  --symbolsPerTransfer'length
341
                                --report "symbols per transfer = " & ieee.numeric_std.to_hstring(to_unsigned(integer(rand0 * 2.0**8),8));       --axiMaster_out.tData'length));
342
 
343 11 daniel.kho
 
344 9 daniel.kho
                                /* synthesis translate_off */
345 11 daniel.kho
                                symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
346 9 daniel.kho
                                report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
347
                                /* synthesis translate_on */
348 11 daniel.kho
 
349 13 daniel.kho
                                symbolsPerTransfer<=128x"0f";           --128x"ffffffff_ffffffff_ffffffff_ffffffff";
350 9 daniel.kho
                        end if;
351
                end if;
352 11 daniel.kho
        end process;
353 9 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.