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 13

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 12 daniel.kho
library tauhop; use tauhop.axiTransactor.all;
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 12 daniel.kho
        signal symbolsPerTransfer:i_transactor.t_cnt;
63
        signal outstandingTransactions:i_transactor.t_cnt;
64 2 daniel.kho
 
65
        /* BFM signalling. */
66 12 daniel.kho
        signal readRequest:i_transactor.t_bfm:=((others=>'0'),(others=>'0'),false);
67
        signal writeRequest:i_transactor.t_bfm:=((others=>'0'),(others=>'0'),false);
68
        signal readResponse:i_transactor.t_bfm;
69
        signal writeResponse:i_transactor.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 13 daniel.kho
        sequencer_ns: process(all) is begin
168
                txFSM<=i_txFSM;
169
                if not nReset then txFSM<=idle;
170
                else
171
                        case i_txFSM is
172
                                when idle=>
173
                                        if outstandingTransactions>0 then txFSM<=transmitting; end if;
174
                                when transmitting=>
175
                                        if axiMaster_out.tLast then
176
                                                txFSM<=idle;
177
                                        end if;
178
                                when others=> null;
179
                        end case;
180
                end if;
181
        end process sequencer_ns;
182
 
183
        sequencer_op: process(nReset,irq_write) is
184 2 daniel.kho
                /* Local procedures to map BFM signals with the package procedure. */
185 12 daniel.kho
                procedure read(address:in i_transactor.t_addr) is begin
186
                        i_transactor.read(readRequest,address);
187 2 daniel.kho
                end procedure read;
188
 
189 12 daniel.kho
                procedure write(data:in i_transactor.t_msg) is begin
190
                        i_transactor.write(request=>writeRequest, address=>(others=>'-'), data=>data);
191 2 daniel.kho
                end procedure write;
192
 
193
                variable isPktError:boolean;
194
 
195 11 daniel.kho
                /* Tester variables. */
196
        /* Synthesis-only randomisation. */
197
 
198 2 daniel.kho
                /* Simulation-only randomisation. */
199 11 daniel.kho
                /* synthesis translate_off */
200 10 daniel.kho
                variable rv0:RandomPType;
201 11 daniel.kho
                /* synthesis translate_on */
202 2 daniel.kho
 
203
        begin
204 11 daniel.kho
                if not nReset then
205
                        /*simulation only. */
206
                        /* synthesis translate_off */
207 9 daniel.kho
                        rv0.InitSeed(rv0'instance_name);
208 11 daniel.kho
                        /* synthesis translate_on */
209 10 daniel.kho
                elsif falling_edge(irq_write) then
210
                        case txFSM is
211
                                when transmitting=>
212 13 daniel.kho
                                        if txFSM/=i_txFSM or writeResponse.trigger then
213 11 daniel.kho
                                                /* synthesis translate_off */
214 10 daniel.kho
                                                write(rv0.RandSigned(axiMaster_out.tData'length));
215 11 daniel.kho
                                                /* synthesis translate_on */
216 10 daniel.kho
                                        end if;
217
                                when others=>null;
218
                        end case;
219
                end if;
220 13 daniel.kho
        end process sequencer_op;
221 10 daniel.kho
 
222 13 daniel.kho
        sequencer_regs: process(irq_write) is begin
223
                if falling_edge(irq_write) then
224
                        i_txFSM<=txFSM;
225
                end if;
226
        end process sequencer_regs;
227
 
228 10 daniel.kho
        /* Reset symbolsPerTransfer to new value (prepare for new transfer) after current transfer has been completed. */
229 11 daniel.kho
        process(nReset,irq_write) is
230
                /* synthesis translate_off */
231 10 daniel.kho
                variable rv0:RandomPType;
232 11 daniel.kho
                /* synthesis translate_on */
233 10 daniel.kho
        begin
234 11 daniel.kho
                if not nReset then
235
                        /* synthesis translate_off */
236 10 daniel.kho
                        rv0.InitSeed(rv0'instance_name);
237 9 daniel.kho
                        symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
238 10 daniel.kho
                        report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
239 11 daniel.kho
                        /* synthesis translate_on */
240 10 daniel.kho
                elsif rising_edge(irq_write) then
241
                        if axiMaster_out.tLast then
242 11 daniel.kho
                                /* synthesis translate_off */
243 9 daniel.kho
                                symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
244
                                report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
245 11 daniel.kho
                                /* synthesis translate_on */
246 2 daniel.kho
                        end if;
247
                end if;
248 10 daniel.kho
        end process;
249 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.