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

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

Synthetic initiator that compiles

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