1 | /* -*- c++ -*- |
---|
2 | * File : vci_traffic_generator.cpp |
---|
3 | * Date : 26/08/2010 |
---|
4 | * Copyright : UPMC / LIP6 |
---|
5 | * Authors : Christophe Choichillon |
---|
6 | * |
---|
7 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
8 | * |
---|
9 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
10 | * |
---|
11 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU Lesser General Public License as published |
---|
13 | * by the Free Software Foundation; version 2.1 of the License. |
---|
14 | * |
---|
15 | * SoCLib is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * Lesser General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Lesser General Public |
---|
21 | * License along with SoCLib; if not, write to the Free Software |
---|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
23 | * 02110-1301 USA |
---|
24 | * |
---|
25 | * SOCLIB_LGPL_HEADER_END |
---|
26 | * |
---|
27 | * Maintainers: christophe.choichillon@lip6.fr |
---|
28 | */ |
---|
29 | |
---|
30 | #include "../include/vci_synthetic_initiator.h" |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | namespace soclib { namespace caba { |
---|
35 | |
---|
36 | |
---|
37 | #define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param> |
---|
38 | |
---|
39 | //using soclib::common::uint32_log2; |
---|
40 | |
---|
41 | //////////////////////////////// |
---|
42 | // Constructor |
---|
43 | //////////////////////////////// |
---|
44 | |
---|
45 | tmpl(/**/)::VciSyntheticInitiator( |
---|
46 | sc_module_name name, |
---|
47 | size_t length, // Packet length (flit numbers) |
---|
48 | float rho, // Packets ratio on the network |
---|
49 | size_t depth, // Fifo depth |
---|
50 | size_t x, // |
---|
51 | size_t y, // |
---|
52 | size_t xmesh, |
---|
53 | size_t ymesh, |
---|
54 | size_t bc_period, // Broadcast period, if no broadcast => 0 |
---|
55 | size_t xmin, |
---|
56 | size_t xmax, |
---|
57 | size_t ymin, |
---|
58 | size_t ymax |
---|
59 | ) |
---|
60 | |
---|
61 | : soclib::caba::BaseModule(name), |
---|
62 | |
---|
63 | p_clk("clk"), |
---|
64 | p_resetn("resetn"), |
---|
65 | p_vci("vci_ini"), |
---|
66 | |
---|
67 | m_srcid_ini( mtc.indexForId(vci_ini_index) ), |
---|
68 | // FIFOs |
---|
69 | m_length(length), |
---|
70 | m_rho(rho), |
---|
71 | m_depth(depth), |
---|
72 | m_x(x), |
---|
73 | m_y(y), |
---|
74 | m_xmesh(xmesh), |
---|
75 | m_ymesh(ymesh), |
---|
76 | m_bc_period(bc_period), |
---|
77 | m_xmin(xmin), |
---|
78 | m_xmax(xmax), |
---|
79 | m_ymin(ymin), |
---|
80 | m_ymax(ymax), |
---|
81 | m_date_fifo("m_date_fifo", depth), |
---|
82 | r_tgt_cmd_fsm("r_tgt_cmd_fsm"), |
---|
83 | { |
---|
84 | |
---|
85 | |
---|
86 | SC_METHOD(transition); |
---|
87 | dont_initialize(); |
---|
88 | sensitive << p_clk.pos(); |
---|
89 | |
---|
90 | SC_METHOD(genMoore); |
---|
91 | dont_initialize(); |
---|
92 | sensitive << p_clk.neg(); |
---|
93 | |
---|
94 | } // end constructor |
---|
95 | |
---|
96 | |
---|
97 | ///////////////////////////////// |
---|
98 | tmpl(/**/)::~VciSyntheticInitiator() |
---|
99 | ///////////////////////////////// |
---|
100 | { |
---|
101 | } |
---|
102 | |
---|
103 | /////////////////////////////////// |
---|
104 | tmpl(void)::destAdress(size_t X_local, size_t Y_local, size_t &X_dest, size_t &Y_dest) |
---|
105 | /////////////////////////////////// |
---|
106 | { |
---|
107 | X_dest = (size_t) ((rand())%m_xmesh); |
---|
108 | Y_dest = (size_t) ((rand())%m_ymesh); |
---|
109 | } |
---|
110 | |
---|
111 | ////////////////////////////////// |
---|
112 | tmpl(void)::transition() |
---|
113 | ////////////////////////////////// |
---|
114 | { |
---|
115 | //using soclib::common::uint32_log2; |
---|
116 | // RESET |
---|
117 | if ( ! p_resetn.read() ) { |
---|
118 | //srand(time(NULL)); |
---|
119 | // Initializing FSMs |
---|
120 | r_tgt_cmd_fsm = TGT_CMD_IDLE; |
---|
121 | |
---|
122 | // initializing FIFOs and communication Buffers |
---|
123 | |
---|
124 | m_date_fifo.init(); |
---|
125 | |
---|
126 | // Activity counters |
---|
127 | m_cpt_cycles = 0; |
---|
128 | m_npackets = 0; |
---|
129 | |
---|
130 | return; |
---|
131 | } |
---|
132 | |
---|
133 | bool date_fifo_put = false; |
---|
134 | bool date_fifo_get = false; |
---|
135 | |
---|
136 | switch ( r_vci_fsm.read() ) { |
---|
137 | |
---|
138 | ////////////////// |
---|
139 | case VCI_IDLE: |
---|
140 | { |
---|
141 | break; |
---|
142 | } |
---|
143 | ////////////////// |
---|
144 | case VCI_SINGLE_SEND: |
---|
145 | { |
---|
146 | break; |
---|
147 | } |
---|
148 | ////////////////////// |
---|
149 | case VCI_SINGLE_RECEIVE: |
---|
150 | { |
---|
151 | if (p_vci.cmdack.read()) { |
---|
152 | // LATENCY |
---|
153 | r_vci_fsm = VCI_IDLE ; |
---|
154 | } |
---|
155 | break; |
---|
156 | } |
---|
157 | /////////////////// |
---|
158 | case VCI_BC_SEND: |
---|
159 | { |
---|
160 | break; |
---|
161 | } |
---|
162 | //////////////////// |
---|
163 | case VCI_BC_RECEIVE: |
---|
164 | { |
---|
165 | r_broadcast_req = false; |
---|
166 | break; |
---|
167 | } |
---|
168 | } // end switch vci_fsm |
---|
169 | |
---|
170 | |
---|
171 | /////////////////// Filling fifo |
---|
172 | if(){ |
---|
173 | if (m_date_fifo.wok()){ |
---|
174 | date_fifo_put = true ; |
---|
175 | } |
---|
176 | if (!r_broadcast_req.read() && (m_cpt_cycles % bc_period)){ |
---|
177 | r_broadcast_req = true; |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | if (date_fifo_put){ |
---|
182 | if (date_fifo_get){ |
---|
183 | m_date_fifo.put_and_get(m_cpt_cycles); |
---|
184 | } else { |
---|
185 | m_date_fifo.simple_put(m_cpt_cycles); |
---|
186 | } |
---|
187 | } else { |
---|
188 | if (date_fifo_get){ |
---|
189 | m_date_fifo.simple_get(); |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | m_cpt_cycles++; |
---|
195 | |
---|
196 | return; |
---|
197 | |
---|
198 | } // end transition() |
---|
199 | |
---|
200 | ///////////////////////////// |
---|
201 | tmpl(void)::genMoore() |
---|
202 | ///////////////////////////// |
---|
203 | { |
---|
204 | //////////////////////////////////////////////////////////// |
---|
205 | // Command signals on the p_vci_ixr port |
---|
206 | //////////////////////////////////////////////////////////// |
---|
207 | p_vci.cmd = vci_param::CMD_READ; |
---|
208 | p_vci.be = 0xF; |
---|
209 | p_vci.pktid = 0; |
---|
210 | p_vci.srcid = m_srcid_ixr; |
---|
211 | p_vci.cons = false; |
---|
212 | p_vci.wrap = false; |
---|
213 | p_vci.contig = true; |
---|
214 | p_vci.clen = 0; |
---|
215 | p_vci.cfixed = false; |
---|
216 | |
---|
217 | |
---|
218 | switch ( r_vci_fsm.read() ) { |
---|
219 | |
---|
220 | ////////////////// |
---|
221 | case VCI_IDLE: |
---|
222 | { |
---|
223 | p_vci.cmdval = false; |
---|
224 | p_vci.address = 0; |
---|
225 | p_vci.plen = 0; |
---|
226 | p_vci.wdata = 0; |
---|
227 | p_vci.trdid = 0; |
---|
228 | p_vci.eop = false; |
---|
229 | break; |
---|
230 | } |
---|
231 | ////////////////// |
---|
232 | case VCI_SINGLE_SEND: |
---|
233 | { |
---|
234 | p_vci.cmdval = true ; |
---|
235 | break; |
---|
236 | } |
---|
237 | ////////////////////// |
---|
238 | case VCI_SINGLE_RECEIVE: |
---|
239 | { |
---|
240 | break; |
---|
241 | } |
---|
242 | /////////////////// |
---|
243 | case VCI_BC_SEND: |
---|
244 | { |
---|
245 | break; |
---|
246 | } |
---|
247 | //////////////////// |
---|
248 | case VCI_BC_RECEIVE: |
---|
249 | { |
---|
250 | break; |
---|
251 | } |
---|
252 | } // end switch vci_fsm |
---|
253 | |
---|
254 | } // end genMoore() |
---|
255 | |
---|
256 | }} // end name space |
---|