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 10

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