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
RevLine 
[77]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
[78]30#include "../include/vci_synthetic_initiator.h"
[77]31
32
33
34namespace soclib { namespace caba {
35
36
[78]37#define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param>
[77]38
[78]39  //using soclib::common::uint32_log2; 
40 
[77]41  ////////////////////////////////
42  //    Constructor
43  ////////////////////////////////
44
[78]45  tmpl(/**/)::VciSyntheticInitiator( 
[77]46      sc_module_name name,
[98]47      const  soclib::common::MappingTable &mt,
48      const  soclib::common::IntTab       &vci_index,
[78]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,
[98]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
[78]59      )
[77]60
61    : soclib::caba::BaseModule(name),
62
63    p_clk("clk"),
64    p_resetn("resetn"),
65    p_vci("vci_ini"),
66
[98]67    m_srcid( mt.indexForId(vci_index) ),
68    m_coord(vci_index[1]),
[77]69    //  FIFOs
[81]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),
[78]82    m_date_fifo("m_date_fifo", depth),
[98]83    r_vci_fsm("r_vci_fsm"),
[77]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  /////////////////////////////////
[78]99  tmpl(/**/)::~VciSyntheticInitiator()
[77]100    /////////////////////////////////
101  {
102  }
103
[81]104  ///////////////////////////////////
[98]105  tmpl(size_t)::destAdress()
[81]106  ///////////////////////////////////
107  {
[98]108    size_t dest;
109    do{
110      dest = (size_t) (rand() % (m_xmesh * m_ymesh));
111    } while(dest == m_srcid);
112    return dest ;
[81]113  }
114
[98]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
[77]127  //////////////////////////////////
128  tmpl(void)::transition()
129    //////////////////////////////////
130  {
131    //  RESET         
132    if ( ! p_resetn.read() ) {
[98]133      // Initializing seed for random numbers generation
134      srand(time(NULL));
[77]135
[98]136      // Initializing FSMs
137      r_vci_fsm = VCI_IDLE;
[77]138
[98]139      // Initializing FIFOs
[78]140      m_date_fifo.init();
[77]141
142      // Activity counters
143      m_cpt_cycles              = 0;
[81]144      m_npackets                = 0;
[77]145
146      return;
147    }
148
[81]149    bool    date_fifo_put = false;
150    bool    date_fifo_get = false;
[77]151
[78]152    switch ( r_vci_fsm.read() ) {
[77]153
154      //////////////////
[78]155      case VCI_IDLE:
[77]156        {
[98]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          }
[77]166          break;
167        }
168        //////////////////
[78]169      case VCI_SINGLE_SEND:
[77]170        {
[98]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          }
[77]181          break;
182        }
183        //////////////////////
[78]184      case VCI_SINGLE_RECEIVE:
[77]185        {
[98]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;
[81]191            r_vci_fsm = VCI_IDLE ;
192          }
[77]193          break;
194        }
195        ///////////////////
[78]196      case VCI_BC_SEND:
[77]197        {
[98]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;
[77]205          break;
206        }
207        ////////////////////
[78]208      case VCI_BC_RECEIVE:
[77]209        {
[98]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          }
[77]219          break;
220        }
[78]221    } // end switch vci_fsm
[77]222
223
[81]224/////////////////// Filling fifo
[98]225    if( (rhos < m_rho) && (rand()/RAND_MAX) ){
[81]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);
[77]237      } else {
[81]238        m_date_fifo.simple_put(m_cpt_cycles);
[77]239      }
240    } else {
[81]241      if (date_fifo_get){
242        m_date_fifo.simple_get();
[77]243      }
244    }
[98]245   
246    m_rhos = (float) ((m_npackets * m_length) / m_cpt_cycles) ;
[77]247
248    m_cpt_cycles++;
249
[81]250    return;
251
[77]252  } // end transition()
253
254  /////////////////////////////
255  tmpl(void)::genMoore()
256    /////////////////////////////
257  {
258    ////////////////////////////////////////////////////////////
[98]259    // Command signals on the p_vci port
[77]260    ////////////////////////////////////////////////////////////
[98]261     p_vci.cmd        = vci_param::CMD_WRITE;   
[81]262     p_vci.be         = 0xF;                             
263     p_vci.pktid      = 0;     
[98]264     p_vci.srcid      = m_srcid;   
[81]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;           
[77]270
271
[78]272    switch ( r_vci_fsm.read() ) {
[77]273
[78]274      //////////////////
275      case VCI_IDLE:
276        {
[81]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;                                   
[98]283          p_vci.rspack  = false;
[78]284          break;
285        }
286        //////////////////
287      case VCI_SINGLE_SEND:
288        {
[98]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;
[78]300          break;
301        }
302        //////////////////////
303      case VCI_SINGLE_RECEIVE:
304        {
[98]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;
[78]313        }
314        ///////////////////
315      case VCI_BC_SEND:
316        {
[98]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;
[78]324          break;
325        }
326        ////////////////////
327      case VCI_BC_RECEIVE:
328        {
[98]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;
[78]336          break;
337        }
338    } // end switch vci_fsm
[77]339
340  } // end genMoore()
341
342}} // end name space
Note: See TracBrowser for help on using the repository browser.