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 16

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 15 daniel.kho
        signal readRequest,writeRequest:i_transactor.t_bfm:=(address=>(others=>'X'),message=>(others=>'X'),trigger=>false);
67
        signal readResponse,writeResponse:i_transactor.t_bfm;
68 2 daniel.kho
 
69 10 daniel.kho
        type txStates is (idle,transmitting);
70
        signal txFSM,i_txFSM:txStates;
71 2 daniel.kho
 
72
        /* Tester signals. */
73
        /* synthesis translate_off */
74 11 daniel.kho
        signal clk,nReset:std_ulogic:='0';
75 2 daniel.kho
        /* synthesis translate_on */
76
 
77 11 daniel.kho
        signal axiMaster_in:t_axi4StreamTransactor_s2m;
78 2 daniel.kho
        signal irq_write:std_ulogic;            -- clock gating.
79
 
80
begin
81
        /* Bus functional models. */
82
        axiMaster: entity work.axiBfmMaster(rtl)
83
                port map(
84 11 daniel.kho
                        aclk=>irq_write, n_areset=>nReset,
85 2 daniel.kho
 
86
                        readRequest=>readRequest,       writeRequest=>writeRequest,
87
                        readResponse=>readResponse,     writeResponse=>writeResponse,
88
                        axiMaster_in=>axiMaster_in,
89
                        axiMaster_out=>axiMaster_out,
90
 
91
                        symbolsPerTransfer=>symbolsPerTransfer,
92 8 daniel.kho
                        outstandingTransactions=>outstandingTransactions
93 2 daniel.kho
        );
94
 
95 9 daniel.kho
        /* Interrupt-request generator. */
96 11 daniel.kho
        irq_write<=clk when nReset else '0';
97 9 daniel.kho
 
98 2 daniel.kho
        /* Simulation Tester. */
99
        /* synthesis translate_off */
100
        clk<=not clk after 10 ps;
101
        process is begin
102 11 daniel.kho
                nReset<='1'; wait for 1 ps;
103
                nReset<='0'; wait for 500 ps;
104
                nReset<='1';
105 2 daniel.kho
                wait;
106
        end process;
107
        /* synthesis translate_on */
108
 
109
        /* Hardware tester. */
110
 
111
 
112 10 daniel.kho
        /* Stimuli sequencer. TODO move to tester/stimuli.
113
                This emulates the AXI4-Stream Slave.
114
        */
115 11 daniel.kho
        /* Simulation-only stimuli sequencer. */
116 10 daniel.kho
        /* synthesis translate_off */
117
        process is begin
118
                /* Fast read. */
119
                while not axiMaster_out.tLast loop
120
                        /* Wait for tValid to assert. */
121
                        while not axiMaster_out.tValid loop
122
                                wait until falling_edge(clk);
123
                        end loop;
124
 
125
                        axiMaster_in.tReady<=true;
126
 
127
                        wait until falling_edge(clk);
128
                        axiMaster_in.tReady<=false;
129
                end loop;
130
 
131
                wait until falling_edge(clk);
132
 
133
                /* Normal read. */
134
                while not axiMaster_out.tLast loop
135
                        /* Wait for tValid to assert. */
136
                        while not axiMaster_out.tValid loop
137
                                wait until falling_edge(clk);
138
                        end loop;
139
 
140
                        wait until falling_edge(clk);
141
                        axiMaster_in.tReady<=true;
142
 
143
                        wait until falling_edge(clk);
144
                        axiMaster_in.tReady<=false;
145
                end loop;
146
 
147
                for i in 0 to 10 loop
148
                        wait until falling_edge(clk);
149
                end loop;
150
 
151
                /* One-shot read. */
152
                axiMaster_in.tReady<=true;
153
 
154
                wait until falling_edge(clk);
155
                axiMaster_in.tReady<=false;
156
 
157
                wait;
158
        end process;
159
        /* synthesis translate_on */
160 9 daniel.kho
 
161 11 daniel.kho
        /* Synthesisable stimuli sequencer. */
162
 
163
 
164 10 daniel.kho
        /* Data transmitter. */
165 13 daniel.kho
        sequencer_ns: process(all) is begin
166
                txFSM<=i_txFSM;
167
                if not nReset then txFSM<=idle;
168
                else
169
                        case i_txFSM is
170
                                when idle=>
171
                                        if outstandingTransactions>0 then txFSM<=transmitting; end if;
172
                                when transmitting=>
173
                                        if axiMaster_out.tLast then
174
                                                txFSM<=idle;
175
                                        end if;
176
                                when others=> null;
177
                        end case;
178
                end if;
179
        end process sequencer_ns;
180
 
181
        sequencer_op: process(nReset,irq_write) is
182 2 daniel.kho
                /* Local procedures to map BFM signals with the package procedure. */
183 12 daniel.kho
                procedure read(address:in i_transactor.t_addr) is begin
184
                        i_transactor.read(readRequest,address);
185 2 daniel.kho
                end procedure read;
186
 
187 12 daniel.kho
                procedure write(data:in i_transactor.t_msg) is begin
188
                        i_transactor.write(request=>writeRequest, address=>(others=>'-'), data=>data);
189 2 daniel.kho
                end procedure write;
190
 
191
                variable isPktError:boolean;
192
 
193 11 daniel.kho
                /* Tester variables. */
194
        /* Synthesis-only randomisation. */
195
 
196 2 daniel.kho
                /* Simulation-only randomisation. */
197 11 daniel.kho
                /* synthesis translate_off */
198 10 daniel.kho
                variable rv0:RandomPType;
199 11 daniel.kho
                /* synthesis translate_on */
200 2 daniel.kho
 
201
        begin
202 11 daniel.kho
                if not nReset then
203
                        /*simulation only. */
204
                        /* synthesis translate_off */
205 9 daniel.kho
                        rv0.InitSeed(rv0'instance_name);
206 11 daniel.kho
                        /* synthesis translate_on */
207 10 daniel.kho
                elsif falling_edge(irq_write) then
208
                        case txFSM is
209
                                when transmitting=>
210 13 daniel.kho
                                        if txFSM/=i_txFSM or writeResponse.trigger then
211 11 daniel.kho
                                                /* synthesis translate_off */
212 10 daniel.kho
                                                write(rv0.RandSigned(axiMaster_out.tData'length));
213 11 daniel.kho
                                                /* synthesis translate_on */
214 10 daniel.kho
                                        end if;
215
                                when others=>null;
216
                        end case;
217
                end if;
218 13 daniel.kho
        end process sequencer_op;
219 10 daniel.kho
 
220 13 daniel.kho
        sequencer_regs: process(irq_write) is begin
221
                if falling_edge(irq_write) then
222
                        i_txFSM<=txFSM;
223
                end if;
224
        end process sequencer_regs;
225
 
226 16 daniel.kho
        /* Transaction counter. */
227
    process(nReset,symbolsPerTransfer,irq_write) is begin
228
        if not nReset then outstandingTransactions<=symbolsPerTransfer;
229
        elsif falling_edge(irq_write) then
230
                        /* Use synchronous reset for outstandingTransactions to meet timing because it is a huge register set. */
231
                        if not nReset then outstandingTransactions<=symbolsPerTransfer;
232
            else
233
                                if outstandingTransactions<1 then
234
                                        outstandingTransactions<=symbolsPerTransfer;
235
                                        report "No more pending transactions." severity note;
236
                                elsif axiMaster_in.tReady then outstandingTransactions<=outstandingTransactions-1;
237
                                end if;
238
                        end if;
239
        end if;
240
    end process;
241
 
242 10 daniel.kho
        /* Reset symbolsPerTransfer to new value (prepare for new transfer) after current transfer has been completed. */
243 11 daniel.kho
        process(nReset,irq_write) is
244
                /* synthesis translate_off */
245 10 daniel.kho
                variable rv0:RandomPType;
246 11 daniel.kho
                /* synthesis translate_on */
247 10 daniel.kho
        begin
248 11 daniel.kho
                if not nReset then
249
                        /* synthesis translate_off */
250 10 daniel.kho
                        rv0.InitSeed(rv0'instance_name);
251 9 daniel.kho
                        symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
252 10 daniel.kho
                        report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
253 11 daniel.kho
                        /* synthesis translate_on */
254 10 daniel.kho
                elsif rising_edge(irq_write) then
255
                        if axiMaster_out.tLast then
256 11 daniel.kho
                                /* synthesis translate_off */
257 9 daniel.kho
                                symbolsPerTransfer<=120x"0" & rv0.RandUnsigned(8);
258
                                report "symbols per transfer = 0x" & ieee.numeric_std.to_hstring(rv0.RandUnsigned(axiMaster_out.tData'length));
259 11 daniel.kho
                                /* synthesis translate_on */
260 2 daniel.kho
                        end if;
261
                end if;
262 10 daniel.kho
        end process;
263 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.