source: trunk/modules/vci_synthetic_initator/caba/sources/src/vci_synthetic_initiator.cpp @ 98

Last change on this file since 98 was 98, checked in by choichil, 14 years ago

Correcting file names of vci_synthetic_initiator

File size: 8.9 KB
Line 
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
34namespace 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      const  soclib::common::MappingTable &mt,
48      const  soclib::common::IntTab       &vci_index,
49      size_t length,    // Packet length (flit numbers)
50      float  rho,       // Packets ratio on the network
51      size_t depth,     // Fifo depth
52      size_t xmesh,     
53      size_t ymesh,
54      size_t bc_period = 0, // Broadcast period, if no broadcast => 0
55      size_t xmin = 0, 
56      size_t xmax = 0,
57      size_t ymin = 0,
58      size_t ymax = 0
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( mt.indexForId(vci_index) ),
68    m_coord(vci_index[1]),
69    //  FIFOs
70    m_length(length),
71    m_rho(rho),
72    m_depth(depth),
73    m_x(x),
74    m_y(y),
75    m_xmesh(xmesh),
76    m_ymesh(ymesh),
77    m_bc_period(bc_period),
78    m_xmin(xmin),
79    m_xmax(xmax),
80    m_ymin(ymin),
81    m_ymax(ymax),
82    m_date_fifo("m_date_fifo", depth),
83    r_vci_fsm("r_vci_fsm"),
84    {
85
86
87      SC_METHOD(transition);
88      dont_initialize();
89      sensitive << p_clk.pos();
90
91      SC_METHOD(genMoore);
92      dont_initialize();
93      sensitive << p_clk.neg();
94
95    } // end constructor
96
97
98  /////////////////////////////////
99  tmpl(/**/)::~VciSyntheticInitiator()
100    /////////////////////////////////
101  {
102  }
103
104  ///////////////////////////////////
105  tmpl(size_t)::destAdress()
106  ///////////////////////////////////
107  {
108    size_t dest;
109    do{
110      dest = (size_t) (rand() % (m_xmesh * m_ymesh));
111    } while(dest == m_srcid);
112    return dest ;
113  }
114
115
116  ///////////////////////////////////
117//  tmpl(void)::destAdress(/*size_t X_local, size_t Y_local,*/ size_t &X_dest, size_t &Y_dest)
118  ///////////////////////////////////
119//  {
120//    size_t x_dest_calc, y_dest_calc;
121//    do{
122//      x_dest_calc = (rand()%m_xmesh);
123//      y_dest_calc = (rand()%m_ymesh);
124//    } while((x_dest_calc = m_x) && (y_dest_calc == m_y));
125//  }
126
127  //////////////////////////////////
128  tmpl(void)::transition()
129    //////////////////////////////////
130  {
131    //  RESET         
132    if ( ! p_resetn.read() ) {
133      // Initializing seed for random numbers generation
134      srand(time(NULL));
135
136      // Initializing FSMs
137      r_vci_fsm = VCI_IDLE;
138
139      // Initializing FIFOs
140      m_date_fifo.init();
141
142      // Activity counters
143      m_cpt_cycles              = 0;
144      m_npackets                = 0;
145
146      return;
147    }
148
149    bool    date_fifo_put = false;
150    bool    date_fifo_get = false;
151
152    switch ( r_vci_fsm.read() ) {
153
154      //////////////////
155      case VCI_IDLE:
156        {
157          if (m_date_fifo.rok()){
158            if (r_broadcast_req.read()){
159              r_vci_fsm = VCI_BC_SEND ;
160            } else {
161              r_vci_fsm = VCI_SINGLE_SEND ;
162              destAdress();
163              m_count = 0;
164            }
165          }
166          break;
167        }
168        //////////////////
169      case VCI_SINGLE_SEND:
170        {
171          if (p_vci.cmdack.read()){
172            m_count++;
173            if (m_count == m_length-1) {
174              m_start_latency1 = m_date_fifo.read();
175              m_start_latency2 = m_cpt_cycles;
176              r_vci_fsm = VCI_SINGLE_RECEIVE ;
177            } else {
178              r_vci_fsm = VCI_SINGLE_SEND ;
179            }
180          }
181          break;
182        }
183        //////////////////////
184      case VCI_SINGLE_RECEIVE:
185        {
186          if (p_vci.rspval.read()) {
187            m_start_latency1 = m_date_fifo.read();
188            m_start_latency2 = m_cpt_cycles;
189            m_npackets++;
190            date_fifo_get = true;
191            r_vci_fsm = VCI_IDLE ;
192          }
193          break;
194        }
195        ///////////////////
196      case VCI_BC_SEND:
197        {
198          m_address_to_send.broadcast_address.xmin = m_xmin;
199          m_address_to_send.broadcast_address.xmax = m_xmax;
200          m_address_to_send.broadcast_address.ymin = m_ymin;
201          m_address_to_send.broadcast_address.ymax = m_ymax;
202          m_address_to_send.broadcast_address.bc   = 0x3;
203          m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin);
204          r_vci_fsm = VCI_BC_SEND;
205          break;
206        }
207        ////////////////////
208      case VCI_BC_RECEIVE:
209        {
210          if (p_vci.rspval.read()){
211            if (m_bc_nrsp == 0) {
212              r_broadcast_req = false;
213              r_vci_fsm = VCI_IDLE ;
214            } else {
215              m_bc_nrsp--;
216              r_vci_fsm = VCI_BC_RECEIVE ;
217            }
218          }
219          break;
220        }
221    } // end switch vci_fsm
222
223
224/////////////////// Filling fifo
225    if( (rhos < m_rho) && (rand()/RAND_MAX) ){
226      if (m_date_fifo.wok()){
227        date_fifo_put = true ;
228      } 
229      if (!r_broadcast_req.read() && (m_cpt_cycles % bc_period)){
230        r_broadcast_req = true;
231      }
232    }
233
234    if (date_fifo_put){
235      if (date_fifo_get){
236        m_date_fifo.put_and_get(m_cpt_cycles);
237      } else {
238        m_date_fifo.simple_put(m_cpt_cycles);
239      }
240    } else {
241      if (date_fifo_get){
242        m_date_fifo.simple_get();
243      }
244    }
245   
246    m_rhos = (float) ((m_npackets * m_length) / m_cpt_cycles) ;
247
248    m_cpt_cycles++;
249
250    return;
251
252  } // end transition()
253
254  /////////////////////////////
255  tmpl(void)::genMoore()
256    /////////////////////////////
257  {
258    ////////////////////////////////////////////////////////////
259    // Command signals on the p_vci port
260    ////////////////////////////////////////////////////////////
261     p_vci.cmd        = vci_param::CMD_WRITE;   
262     p_vci.be         = 0xF;                             
263     p_vci.pktid      = 0;     
264     p_vci.srcid      = m_srcid;   
265     p_vci.cons       = false;       
266     p_vci.wrap       = false;       
267     p_vci.contig     = true;       
268     p_vci.clen       = 0;         
269     p_vci.cfixed     = false;           
270
271
272    switch ( r_vci_fsm.read() ) {
273
274      //////////////////
275      case VCI_IDLE:
276        {
277          p_vci.cmdval  = false;                 
278          p_vci.address = 0; 
279          p_vci.plen    = 0;                                         
280          p_vci.wdata   = 0;                                       
281          p_vci.trdid   = 0;                 
282          p_vci.eop     = false;                                   
283          p_vci.rspack  = false;
284          break;
285        }
286        //////////////////
287      case VCI_SINGLE_SEND:
288        {
289          p_vci.cmdval  = true;                 
290          p_vci.address = (typename vci_param::addr_t)(m_address_to_send+(m_count*4)); 
291          p_vci.plen    = m_length*4;                                         
292          p_vci.wdata   = 0;                                       
293          p_vci.trdid   = 0;                 
294          if (m_count == m_length - 1 ) {
295            p_vci.eop     = true;                                   
296          } else {
297            p_vci.eop     = false;                                   
298          }
299          p_vci.rspack  = false;
300          break;
301        }
302        //////////////////////
303      case VCI_SINGLE_RECEIVE:
304        {
305          p_vci.cmdval  = false;                 
306          p_vci.address = 0; 
307          p_vci.plen    = 0;                                         
308          p_vci.wdata   = 0;                                       
309          p_vci.trdid   = 0;                 
310          p_vci.eop     = false;                                   
311          p_vci.rspack  = true;
312          break;
313        }
314        ///////////////////
315      case VCI_BC_SEND:
316        {
317          p_vci.cmdval  = true;                 
318          p_vci.address = (typename vci_param::addr_t) m_address_to_send; 
319          p_vci.plen    = 4;                                         
320          p_vci.wdata   = 0;                                       
321          p_vci.trdid   = 0;                 
322          p_vci.eop     = true;                                   
323          p_vci.rspack  = false;
324          break;
325        }
326        ////////////////////
327      case VCI_BC_RECEIVE:
328        {
329          p_vci.cmdval  = false;                 
330          p_vci.address = 0; 
331          p_vci.plen    = 0;                                         
332          p_vci.wdata   = 0;                                       
333          p_vci.trdid   = 0;                 
334          p_vci.eop     = false;                                   
335          p_vci.rspack  = true;
336          break;
337        }
338    } // end switch vci_fsm
339
340  } // end genMoore()
341
342}} // end name space
Note: See TracBrowser for help on using the repository browser.