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

Subversion Repositories axi4_tlm_bfm

[/] [axi4_tlm_bfm/] [trunk/] [rtl/] [user.vhdl] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 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 3 daniel.kho
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all; use ieee.math_real.all;
38 9 daniel.kho
library tauhop; use tauhop.transactor.all, tauhop.axiTransactor.all;            --TODO just use axiTransactor here as transactor should already be wrapped up.
39 11 daniel.kho
 
40
/* TODO remove once generic packages are supported. */
41
--library tauhop; use tauhop.tlm.all, tauhop.axiTLM.all;
42
 
43 9 daniel.kho
/* synthesis translate_off */
44
library osvvm; use osvvm.RandomPkg.all; use osvvm.CoveragePkg.all;
45
/* synthesis translate_on */
46 2 daniel.kho
 
47
entity user is port(
48
        /* Comment-out for simulation. */
49 11 daniel.kho
--      clk,nReset:in std_ulogic;
50 2 daniel.kho
 
51
        /* AXI Master interface */
52 5 daniel.kho
--      axiMaster_in:in t_axi4StreamTransactor_s2m;
53
        axiMaster_out:buffer t_axi4StreamTransactor_m2s
54 2 daniel.kho
 
55
        /* Debug ports. */
56
);
57
end entity user;
58
 
59
architecture rtl of user is
60
        /* Global counters. */
61
        constant maxSymbols:positive:=2048;             --maximum number of symbols allowed to be transmitted in a frame. Each symbol's width equals tData's width. 
62
        signal symbolsPerTransfer:t_cnt;
63
        signal outstandingTransactions:t_cnt;
64
 
65
        /* BFM signalling. */
66 10 daniel.kho
        signal readRequest:t_bfm:=((others=>'0'),(others=>'0'),false);
67
        signal writeRequest:t_bfm:=((others=>'0'),(others=>'0'),false);
68
        signal readResponse:t_bfm;
69
        signal writeResponse:t_bfm;
70 2 daniel.kho
 
71 10 daniel.kho
        type txStates is (idle,transmitting);
72
        signal txFSM,i_txFSM:txStates;
73 2 daniel.kho
 
74
        /* Tester signals. */
75
        /* synthesis translate_off */
76 11 daniel.kho
        signal clk,nReset:std_ulogic:='0';
77 2 daniel.kho
        /* synthesis translate_on */
78
 
79 11 daniel.kho
        signal axiMaster_in:t_axi4StreamTransactor_s2m;
80 2 daniel.kho
        signal irq_write:std_ulogic;            -- clock gating.
81
 
82
begin
83
        /* Bus functional models. */
84
        axiMaster: entity work.axiBfmMaster(rtl)
85
                port map(
86 11 daniel.kho
                        aclk=>irq_write, n_areset=>nReset,
87 2 daniel.kho
 
88
                        readRequest=>readRequest,       writeRequest=>writeRequest,
89
                        readResponse=>readResponse,     writeResponse=>writeResponse,
90
                        axiMaster_in=>axiMaster_in,
91
                        axiMaster_out=>axiMaster_out,
92
 
93
                        symbolsPerTransfer=>symbolsPerTransfer,
94 8 daniel.kho
                        outstandingTransactions=>outstandingTransactions
95 2 daniel.kho
        );
96
 
97 9 daniel.kho
        /* Interrupt-request generator. */
98 11 daniel.kho
        irq_write<=clk when nReset else '0';
99 9 daniel.kho
 
100 2 daniel.kho
        /* Simulation Tester. */
101
        /* synthesis translate_off */
102
        clk<=not clk after 10 ps;
103
        process is begin
104 11 daniel.kho
                nReset<='1'; wait for 1 ps;
105
                nReset<='0'; wait for 500 ps;
106
                nReset<='1';
107 2 daniel.kho
                wait;
108
        end process;
109
        /* synthesis translate_on */
110
 
111
        /* Hardware tester. */
112
 
113
 
114 10 daniel.kho
        /* Stimuli sequencer. TODO move to tester/stimuli.
115
                This emulates the AXI4-Stream Slave.
116
        */
117 11 daniel.kho
        /* Simulation-only stimuli sequencer. */
118 10 daniel.kho
        /* synthesis translate_off */
119
        process is begin
120
                /* Fast read. */
121
                while not axiMaster_out.tLast loop
122
                        /* Wait for tValid to assert. */
123
                        while not axiMaster_out.tValid loop
124
                                wait until falling_edge(clk);
125
                        end loop;
126
 
127
                        axiMaster_in.tReady<=true;
128
 
129
                        wait until falling_edge(clk);
130
                        axiMaster_in.tReady<=false;
131
                end loop;
132
 
133
                wait until falling_edge(clk);
134
 
135
                /* Normal read. */
136
                while not axiMaster_out.tLast loop
137
                        /* Wait for tValid to assert. */
138
                        while not axiMaster_out.tValid loop
139
                                wait until falling_edge(clk);
140
                        end loop;
141
 
142
                        wait until falling_edge(clk);
143
                        axiMaster_in.tReady<=true;
144
 
145
                        wait until falling_edge(clk);
146
                        axiMaster_in.tReady<=false;
147
                end loop;
148
 
149
                for i in 0 to 10 loop
150
                        wait until falling_edge(clk);
151
                end loop;
152
 
153
                /* One-shot read. */
154
                axiMaster_in.tReady<=true;
155
 
156
                wait until falling_edge(clk);
157
                axiMaster_in.tReady<=false;
158
 
159
                wait;
160
        end process;
161
        /* synthesis translate_on */
162 9 daniel.kho
 
163 11 daniel.kho
        /* Synthesisable stimuli sequencer. */
164
 
165
 
166 10 daniel.kho
        /* Data transmitter. */
167 11 daniel.kho
        sequencer: process(nReset,irq_write) is
168 2 daniel.kho
                /* Local procedures to map BFM signals with the package procedure. */
169 8 daniel.kho
                procedure read(address:in t_addr) is begin
170 2 daniel.kho
                        read(readRequest,address);
171
                end procedure read;
172
 
173 8 daniel.kho
                procedure write(data:in t_msg) is begin
174
                        write(request=>writeRequest, address=>(others=>'-'), data=>data);
175 2 daniel.kho
                end procedure write;
176
 
177
                variable isPktError:boolean;
178
 
179 11 daniel.kho
                /* Tester variables. */
180
        /* Synthesis-only randomisation. */
181
 
182 2 daniel.kho
                /* Simulation-only randomisation. */
183 11 daniel.kho
                /* synthesis translate_off */
184 10 daniel.kho
                variable rv0:RandomPType;
185 11 daniel.kho
                /* synthesis translate_on */
186 2 daniel.kho
 
187
        begin
188 11 daniel.kho
                if not nReset then
189
                        /*simulation only. */
190
                        /* synthesis translate_off */
191 9 daniel.kho
                        rv0.InitSeed(rv0'instance_name);
192 11 daniel.kho
                        /* synthesis translate_on */
193
 
194 10 daniel.kho
                        txFSM<=idle;
195
                elsif falling_edge(irq_write) then
196
                        case txFSM is
197
                                when idle=>
198
                                        if outstandingTransactions>0 then
199 11 daniel.kho
                                                /* synthesis translate_off */
200 10 daniel.kho
                                                write(rv0.RandSigned(axiMaster_out.tData'length));
201 11 daniel.kho
                                                /* synthesis translate_on */
202 10 daniel.kho
                                                txFSM<=transmitting;
203
                                        end if;
204
                                when transmitting=>
205
                                        if writeResponse.trigger then
206 11 daniel.kho
                                                /* synthesis translate_off */
207 10 daniel.kho
                                                write(rv0.RandSigned(axiMaster_out.tData'length));
208 11 daniel.kho
                                                /* synthesis translate_on */
209 10 daniel.kho
                                        end if;
210
 
211
                                        if axiMaster_out.tLast then
212
                                                txFSM<=idle;
213
                                        end if;
214
                                when others=>null;
215
                        end case;
216
                end if;
217
        end process sequencer;
218
 
219
        /* Reset symbolsPerTransfer to new value (prepare for new transfer) after current transfer has been completed. */
220 11 daniel.kho
        process(nReset,irq_write) is
221
                /* synthesis translate_off */
222 10 daniel.kho
                variable rv0:RandomPType;
223 11 daniel.kho
                /* synthesis translate_on */
224 10 daniel.kho
        begin
225 11 daniel.kho
                if not nReset then
226
                        /* synthesis translate_off */
227 10 daniel.kho
                        rv0.InitSeed(rv0'instance_name);
228 9 daniel.kho
                        symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
229 10 daniel.kho
                        report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
230 11 daniel.kho
                        /* synthesis translate_on */
231 10 daniel.kho
                elsif rising_edge(irq_write) then
232
                        if axiMaster_out.tLast then
233 11 daniel.kho
                                /* synthesis translate_off */
234 9 daniel.kho
                                symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
235
                                report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
236 11 daniel.kho
                                /* synthesis translate_on */
237 2 daniel.kho
                        end if;
238
                end if;
239 10 daniel.kho
        end process;
240 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.