OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [hibi/] [3.0/] [tb/] [sad_tb/] [agent.hh] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Author: Lasse Lehtonen
3
 *
4
 * Agent for hibi. Sends packets when told to and checks that correct
5
 * packets are received. Wrapper types r3 and r4 have different interfaces and
6
 * infndefs are needed every now and then.
7
 *
8
 * $Id: agent.hh 2008 2011-10-06 13:49:53Z ege $
9
 *
10
 */
11
 
12
 
13
#ifndef SAD_HIBI_AGENT_HH
14
#define SAD_HIBI_AGENT_HH
15
 
16
#include "constants.hh"
17
#include "packet.hh"
18
 
19
#include 
20
#include 
21
#include 
22
#include 
23
#include 
24
#include 
25
using namespace std;
26
 
27
#include 
28
using namespace sc_core;
29
using namespace sc_dt;
30
 
31
 
32
template
33
         int data_width_g,
34
         int comm_width_g,
35
         int separate_addr_g>
36
class Agent : public sc_module
37
{
38
public:
39
   sc_in_clk                    clk;
40
   sc_in                  rst_n;
41
 
42
   sc_out > comm_out;
43
   sc_out > data_out;
44
#ifndef USE_R3_WRAPPERS
45
   sc_out                 av_out;
46
#else
47
   sc_out > addr_out;
48
#endif
49
   sc_out                 we_out;
50
   sc_out                 re_out;
51
   sc_in >  comm_in;
52
   sc_in >  data_in;
53
#ifndef USE_R3_WRAPPERS
54
   sc_in                  av_in;
55
#else
56
   sc_out > addr_in;
57
#endif
58
   sc_in                  full_in;
59
   sc_in                  one_p_in;
60
   sc_in                  empty_in;
61
   sc_in                  one_d_in;
62
 
63
#ifdef USE_R3_WRAPPERS
64
   sc_out > msg_comm_out;
65
   sc_out > msg_data_out;
66
   sc_out > msg_addr_out;
67
   sc_out                 msg_we_out;
68
   sc_out                 msg_re_out;
69
   sc_in >  msg_comm_in;
70
   sc_in >  msg_data_in;
71
   sc_in >  msg_addr_in;
72
   sc_in                  msg_full_in;
73
   sc_in                  msg_one_p_in;
74
   sc_in                  msg_empty_in;
75
   sc_in                  msg_one_d_in;
76
#endif
77
 
78
   SC_HAS_PROCESS(Agent);
79
 
80
 
81
   //* Constructor
82
   // Initalize ports to 0 and
83
   // tx and rx threads
84
   Agent(sc_module_name name, unsigned int id,
85
         vector
86
                      comm_width_c, separate_addr_c>* >& agents)
87
      : sc_module(name),
88
        clk("clk"),
89
        rst_n("rst_n"),
90
        comm_out("comm_out"),
91
        data_out("data_out"),
92
#ifndef USE_R3_WRAPPERS
93
        av_out("av_out"),
94
#else
95
        addr_out("addr_out"),
96
#endif
97
        we_out("we_out"),
98
        re_out("re_out"),
99
        comm_in("comm_in"),
100
        data_in("data_in"),
101
#ifndef USE_R3_WRAPPERS
102
        av_in("av_in"),
103
#else
104
        addr_in("addr_in"),
105
#endif
106
        full_in("full_in"),
107
        one_p_in("one_p_in"),
108
        empty_in("empty_in"),
109
        one_d_in("one_d_in"),
110
#ifdef USE_R3_WRAPPERS
111
        msg_comm_out("msg_comm_out"),
112
        msg_data_out("msg_data_out"),
113
        msg_addr_out("msg_addr_out"),
114
        msg_we_out("msg_we_out"),
115
        msg_re_out("msg_re_out"),
116
        msg_comm_in("msg_comm_in"),
117
        msg_data_in("msg_data_in"),
118
        msg_addr_in("msg_addr_in"),
119
        msg_full_in("msg_full_in"),
120
        msg_one_p_in("msg_one_p_in"),
121
        msg_empty_in("msg_empty_in"),
122
        msg_one_d_in("msg_one_d_in"),
123
#endif
124
        _id(id),
125
        _rxBusyChance(0),
126
        _txBusyChance(0),
127
        _agents(agents),
128
        _locked(false)
129
   {
130
      comm_out.initialize(0);
131
      data_out.initialize(0);
132
#ifndef USE_R3_WRAPPERS
133
      av_out.initialize(false);
134
#else
135
      addr_out.initialize(0);
136
#endif
137
      we_out.initialize(false);
138
      re_out.initialize(false);
139
#ifdef USE_R3_WRAPPERS
140
      msg_comm_out.initialize(0);
141
      msg_data_out.initialize(0);
142
      msg_addr_out.initialize(0);
143
      msg_we_out.initialize(false);
144
      msg_re_out.initialize(false);
145
#endif
146
 
147
 
148
 
149
      // Launch threads for tx and rx
150
      SC_THREAD(sender);
151
      SC_THREAD(receiver);
152
 
153
#ifdef USE_R3_WRAPPERS
154
      // Launch threads for message tx and rx
155
      SC_THREAD(msg_sender);
156
      SC_THREAD(msg_receiver);
157
#endif
158
 
159
   }
160
 
161
 
162
   //* Destructor
163
   ~Agent()
164
   {
165
      freePackets();
166
   }
167
 
168
 
169
   //* Adds packet for this agent to send
170
   void send(Packet* packet)
171
   {
172
#ifdef USE_R3_WRAPPERS
173
      if(packet->getHibiCommand() == DATA_WR ||
174
         packet->getHibiCommand() == DATA_RD ||
175
         packet->getHibiCommand() == DATA_RDL ||
176
         packet->getHibiCommand() == DATA_WRNP ||
177
         packet->getHibiCommand() == DATA_WRC)
178
      {
179
         _packetsOut.push(packet);
180
      }
181
      else
182
      {
183
         _msgPacketsOut.push(packet);
184
      }
185
#else
186
      _packetsOut.push(packet);
187
#endif
188
 
189
      /*
190
      cout << "At " << setprecision(10) << sc_time_stamp().to_double() << " : "
191
           << "Agent " << setfill(' ') << setw(3) << dec << _id << " queued   "
192
           << commmand2str(packet->getHibiCommand())
193
           << " packet: "
194
           << setw(5) << setfill(' ') << packet->getId() << " to   ";
195
      if(packet->getHibiCommand() == CFG_WR ||
196
         packet->getHibiCommand() == CFG_RD)
197
      {
198
         cout << "id: " << packet->getDstId() << endl;
199
      }
200
      else
201
      {
202
         cout << "address: 0x"
203
              << hex << setw(8) << setfill('0')
204
              << packet->getDstAddress().to_uint()
205
              << endl;
206
      }
207
 
208
      */
209
 
210
   }
211
 
212
   //* Tells agent to expect this packet
213
   void expect(Packet* packet)
214
   {
215
      //_packetsIn[packet->getId()] = packet;
216
      _packetsIn.insert(pair, Packet*>(packet->getId(), packet));
217
   }
218
 
219
   //* Tells agent to expect this packet, custom id
220
   void expect(Packet* packet, unsigned int id)
221
   {
222
      //_packetsIn[id] = packet;
223
      _packetsIn.insert(pair, Packet*>(id, packet));
224
   }
225
 
226
 
227
   //* True if all packets have been received
228
   bool allDone() const
229
   {
230
      return _packetsIn.empty();
231
   }
232
 
233
   //* Print unfinished packet ids
234
   void printExpected()
235
   {
236
      for(map, Packet*>::iterator iter = _packetsIn.begin();
237
          iter != _packetsIn.end(); ++iter)
238
      {
239
         cout << " +- packet "
240
              << dec << setw(5) << setfill(' ') << (*iter).second->getId()
241
              << " missing "
242
              << (*iter).second->getSize() - (*iter).second->getReceived()
243
              << " words"
244
              << endl;
245
      }
246
   }
247
 
248
   //* Sets RX change to be busy on any clock cycle (0-100)
249
   void setRxBusyChance(unsigned int chance)
250
   { _rxBusyChance = chance; }
251
 
252
   //* Sets TX change to be busy on any clock cycle (0-100)
253
   void setTxBusyChance(unsigned int chance)
254
   { _txBusyChance = chance; }
255
 
256
 
257
private:
258
 
259
 
260
   //* Frees all memory elements
261
   void freePackets()
262
   {
263
      while(!_packetsOut.empty())
264
      {
265
         // Only pointers on RX side will be deleted as they point
266
         // to the same object
267
         _packetsOut.pop();
268
      }
269
 
270
#ifdef USE_R3_WRAPPERS
271
      while(!_msgPacketsOut.empty())
272
      {
273
         // Only pointers on RX side will be deleted as they point
274
         // to the same object
275
         _msgPacketsOut.pop();
276
      }
277
#endif
278
 
279
      for(map, Packet*>::iterator iter = _packetsIn.begin();
280
          iter != _packetsIn.end(); ++iter )
281
      {
282
         delete (*iter).second;
283
      }
284
   }
285
 
286
 
287
   //* TX thread, handles pushing packets to hibi
288
   void sender()
289
   {
290
      while(true)
291
      {
292
         // Sync to pos edge
293
         wait(clk.posedge_event());
294
 
295
         // Handle reset
296
         if(rst_n.read() == false)
297
         {
298
            comm_out.write(0);
299
            data_out.write(0);
300
#ifndef USE_R3_WRAPPERS
301
            av_out.write(false);
302
#else
303
            addr_out.write(0);
304
#endif
305
            we_out.write(false);
306
            freePackets(); // Deletes all packets
307
            continue;
308
         }
309
 
310
 
311
 
312
         // No packets to send
313
         if(_packetsOut.empty()) continue;
314
 
315
 
316
 
317
         // There is data to send in the FIFO
318
         Packet* packet = _packetsOut.front();
319
         _packetsOut.pop();
320
 
321
#ifndef USE_R3_WRAPPERS
322
         // Put address before data flits in normal mode
323
         if(separate_addr_g == 0)
324
         {
325
            // Wait if NI is full
326
            while(full_in.read() == true) wait(clk.posedge_event());
327
 
328
            we_out.write(true);
329
            av_out.write(true);
330
            comm_out.write(packet->getCommand());
331
            data_out.write(packet->getDstAddress());
332
 
333
            wait(clk.posedge_event());
334
         }
335
#endif
336
 
337
 
338
 
339
         // Send all flits
340
         for(unsigned int i = 0; i < packet->getSize();)
341
         {
342
            // Occasionally, play dead and not send anything
343
            // This doesn't work, need second cycle wait, stupido we_out!
344
            // if((unsigned(rand()) % 100) < _txBusyChance)
345
            // {
346
            //    we_out.write(false);
347
            //    wait(clk.posedge_event());
348
            //    continue;
349
            // }
350
 
351
            // Wait if NI is full
352
            while(full_in.read() == true)
353
            {
354
               //we_out.write(true);
355
               wait(clk.posedge_event());
356
            }
357
 
358
            we_out.write(true);
359
 
360
#ifndef USE_R3_WRAPPERS
361
            if(separate_addr_g == 0)
362
            {
363
               av_out.write(false);
364
               comm_out.write(packet->getCommand());
365
               data_out.write(packet->getData());
366
            }
367
            else
368
            {
369
               // AV is high for the whole packet in SAD mode
370
               av_out.write(true);
371
               // Substitute address to MSBs of data_out
372
               data_out.write((packet->getDstAddress(),
373
                               packet->getData().
374
                               range(data_width_c-addr_width_c-1, 0)));
375
               comm_out.write(packet->getCommand());
376
            }
377
#else
378
            comm_out.write(packet->getCommand());
379
            data_out.write(packet->getData());
380
            addr_out.write(packet->getDstAddress());
381
#endif
382
 
383
            wait(clk.posedge_event());
384
            ++i;
385
         }
386
 
387
 
388
 
389
         // Wait if NI is full when last flit is being sent
390
         while(full_in.read() == true)
391
         {
392
            wait(clk.posedge_event());
393
         }
394
 
395
         cout << "At " << setprecision(10) << sc_time_stamp().to_double()
396
              << " : "
397
              << "Agent " << setfill(' ') << setw(3) << dec << _id
398
              << " sent     "
399
              << commmand2str(packet->getHibiCommand())
400
              << " packet: "
401
              << setw(5) << setfill(' ') <<  packet->getId() << " to   ";
402
         if(packet->getHibiCommand() == CFG_WR ||
403
            packet->getHibiCommand() == CFG_RD)
404
         {
405
            cout << "id: " << packet->getDstId() << endl;
406
         }
407
         else
408
         {
409
            cout << "address: 0x"
410
                 << hex << setw(8) << setfill('0')
411
                 << packet->getDstAddress().to_uint()
412
                 << endl;
413
         }
414
 
415
         we_out.write(false);
416
#ifndef USE_R3_WRAPPERS
417
         av_out.write(false);
418
#else
419
         addr_out.write(0);
420
#endif
421
         comm_out.write(commands_c[IDLE]);
422
         data_out.write(0);
423
         packet = 0;
424
      }
425
   }
426
 
427
 
428
   //* RX thread, handles receiving packets from hibitys
429
   void receiver()
430
   {
431
      sc_uint<16> packetId;
432
      bool reading = false;
433
 
434
      while(true)
435
      {
436
         // Sync to pos edge and handle reset
437
         wait(clk.posedge_event());
438
         re_out.write(false); // Default
439
         if(rst_n.read() == false)
440
         {
441
            continue;
442
         }
443
 
444
         if(reading)
445
         {
446
            reading = false;
447
 
448
            if(empty_in.read() == true)
449
            {
450
               // There's nothing to read
451
            }
452
#ifndef USE_R3_WRAPPERS
453
            else if(separate_addr_g == 0 && av_in.read() == true)
454
            {
455
               // Skip the address flit if in normal mode
456
            }
457
#endif
458
            else
459
            {
460
               // Check that we're expecting a packet with this ID
461
               packetId = (data_in.read().range(15, 0).to_uint());
462
               if(_packetsIn.find(packetId) == _packetsIn.end())
463
               {
464
                  ostringstream oss;
465
                  oss << "At " << setprecision(10)
466
                      << sc_time_stamp().to_double()
467
                      << " : " << "Agent " << setfill(' ') << setw(3) << _id
468
                      << " received unexpected flit with id: " << packetId;
469
                  SC_REPORT_WARNING("warning", oss.str().c_str());
470
                  re_out.write(true);
471
                  continue;
472
               }
473
 
474
               HibiCommand cmd = (*_packetsIn.find(packetId)).second->
475
                     getHibiCommand();
476
 
477
               // Check that we are not getting normal stuff while locked!
478
               if(_locked &&
479
                  cmd != EXCL_WR &&
480
                  cmd != EXCL_RD &&
481
                  cmd != EXCL_RELEASE)
482
               {
483
                  ostringstream oss;
484
                  oss << "At " << setprecision(10)
485
                      << sc_time_stamp().to_double()
486
                      << " : " << "Agent " << setfill(' ') << setw(3) << _id
487
                      << " received non-exclusive packet while locked, id: "
488
                      << packetId;
489
                  SC_REPORT_WARNING("warning", oss.str().c_str());
490
               }
491
 
492
 
493
               // Lock this agent when getting lock command
494
               if(cmd == EXCL_LOCK && !_locked)
495
               { _locked = true; }
496
 
497
               // Release the lock
498
               if(cmd == EXCL_RELEASE && _locked)
499
               { _locked = false; }
500
 
501
               //_packetsIn[packetId]->receiveWord();
502
               (*_packetsIn.find(packetId)).second->receiveWord();
503
 
504
               //if(_packetsIn[packetId]->complete())
505
               if((*_packetsIn.find(packetId)).second->complete())
506
               {
507
                  // Packet is fully received, remove it to save some memory
508
                  cout << "At "
509
                       << setprecision(10) << sc_time_stamp().to_double()
510
                       << " : " << "Agent " << setfill(' ') << setw(3) << dec
511
                       << _id << " received "
512
                       << commmand2str(comm_in.read().to_uint())
513
                       << " packet: "
514
                       << setw(5) << setfill(' ') << packetId << " from ";
515
                  cout << "address: 0x"
516
                       << hex << setw(8) << setfill('0')
517
                     //<< _packetsIn[packetId]->getSrcAddress().to_uint()
518
                       << (*_packetsIn.find(packetId)).second->getSrcAddress()
519
                     .to_uint()
520
                       << endl;
521
 
522
                  if(cmd == DATA_RD ||
523
                     cmd == MSG_RD ||
524
                     cmd == EXCL_RD ||
525
                     cmd == DATA_RDL ||
526
                     cmd == MSG_RDL)
527
                  {
528
                     // Generate response packet
529
                     Packet* packet = 0;
530
                     packet = new Packet((*_packetsIn.find(packetId)).second->
531
                                         getResponseSize(),
532
                                         addresses_c[_id],
533
                                         (*_packetsIn.find(packetId)).second->
534
                                         getSrcAddress(),
535
                                         DATA_WRNP);
536
                     this->send(packet);
537
                     for(unsigned int i = 0; i < _agents.size(); ++i)
538
                     {
539
                        if(addresses_c[i] ==
540
                           (*_packetsIn.find(packetId)).second->getSrcAddress())
541
                        {
542
                           _agents.at(i)->expect(packet);
543
                        }
544
                     }
545
                  }
546
 
547
                  //delete _packetsIn[packetId];
548
                  delete (*_packetsIn.find(packetId)).second;
549
                  //_packetsIn.erase(packetId);
550
                  _packetsIn.erase(_packetsIn.find(packetId));
551
               }
552
            }
553
         }
554
 
555
         // Do nothing if there's nothing to do...
556
         if(empty_in.read() == true) continue;
557
 
558
         // Chance to play dead for this cycle
559
         if((unsigned(rand()) % 100) < _rxBusyChance) continue;
560
 
561
 
562
         // Read the flit
563
         re_out.write(true);
564
         reading = true;
565
 
566
 
567
      }
568
   }
569
 
570
 
571
#ifdef USE_R3_WRAPPERS
572
 
573
   //* TX thread, handles pushing packets to hibitys
574
   void msg_sender()
575
   {
576
      while(true)
577
      {
578
         // Sync to pos edge
579
         wait(clk.posedge_event());
580
 
581
         // Handle reset
582
         if(rst_n.read() == false)
583
         {
584
            msg_comm_out.write(0);
585
            msg_data_out.write(0);
586
            msg_addr_out.write(0);
587
            msg_we_out.write(false);
588
            freePackets(); // Deletes all packets
589
            continue;
590
         }
591
 
592
         if(_msgPacketsOut.empty()) continue; // No packets to send
593
 
594
         // Take packets from the FIFO
595
         Packet* packet = _msgPacketsOut.front();
596
         _msgPacketsOut.pop();
597
 
598
 
599
         // Send all flits
600
         for(unsigned int i = 0; i < packet->getSize();)
601
         {
602
            // Chance to play dead for this cycle
603
            // This doesn't work, need second cycle wait, stupido we_out!
604
            // if((unsigned(rand()) % 100) < _txBusyChance)
605
            // {
606
            //    we_out.write(false);
607
            //    wait(clk.posedge_event());
608
            //    continue;
609
            // }
610
 
611
            // Wait if NI is full
612
            while(msg_full_in.read() == true)
613
            {
614
               //msg_we_out.write(true);
615
               wait(clk.posedge_event());
616
            }
617
 
618
            msg_we_out.write(true);
619
 
620
            msg_comm_out.write(packet->getCommand());
621
            msg_data_out.write(packet->getData());
622
            msg_addr_out.write(packet->getDstAddress());
623
 
624
 
625
            wait(clk.posedge_event());
626
            ++i;
627
         }
628
 
629
         // Wait if NI is full
630
         while(msg_full_in.read() == true)
631
         {
632
            wait(clk.posedge_event());
633
         }
634
 
635
         cout << "At " << setprecision(10) << sc_time_stamp().to_double()
636
              << " : "
637
              << "Agent " << setfill(' ') << setw(3) << dec << _id
638
              << " sent     "
639
              << commmand2str(packet->getHibiCommand())
640
              << " packet: "
641
              << setw(5) << setfill(' ') <<  packet->getId() << " to   ";
642
         if(packet->getHibiCommand() == CFG_WR ||
643
            packet->getHibiCommand() == CFG_RD)
644
         {
645
            cout << "id: " << packet->getDstId() << endl;
646
         }
647
         else
648
         {
649
            cout << "address: 0x"
650
                 << hex << setw(8) << setfill('0')
651
                 << packet->getDstAddress().to_uint()
652
                 << endl;
653
         }
654
 
655
         msg_we_out.write(false);
656
         msg_addr_out.write(0);
657
         msg_comm_out.write(commands_c[IDLE]);
658
         msg_data_out.write(0);
659
         packet = 0;
660
      }
661
   }
662
 
663
 
664
   //* RX thread, handles receiving packets from hibitys
665
   void msg_receiver()
666
   {
667
      sc_uint<16> packetId;
668
      bool reading = false;
669
 
670
      while(true)
671
      {
672
         // Sync to pos edge and handle reset
673
         wait(clk.posedge_event());
674
         msg_re_out.write(false); // Default
675
         if(rst_n.read() == false)
676
         {
677
            continue;
678
         }
679
 
680
         if(reading)
681
         {
682
            reading = false;
683
 
684
            if(msg_empty_in.read() == true)
685
            {
686
               // There's nothing to read
687
            }
688
            else
689
            {
690
               // Check that we're expecting a packet with this ID
691
               packetId = (msg_data_in.read().range(15, 0).to_uint());
692
               if(_packetsIn.find(packetId) == _packetsIn.end())
693
               {
694
                  ostringstream oss;
695
                  oss << "At " << setprecision(10)
696
                      << sc_time_stamp().to_double()
697
                      << " : " << "Agent " << setfill(' ') << setw(3) << _id
698
                      << " received unexpected flit with id: " << packetId;
699
                  SC_REPORT_WARNING("warning", oss.str().c_str());
700
                  msg_re_out.write(true);
701
                  continue;
702
               }
703
 
704
               HibiCommand cmd = (*_packetsIn.find(packetId)).second->
705
                     getHibiCommand();
706
 
707
               // Check that we are not getting normal stuff while locked!
708
               if(_locked &&
709
                  cmd != EXCL_WR &&
710
                  cmd != EXCL_RD &&
711
                  cmd != EXCL_RELEASE)
712
               {
713
                  ostringstream oss;
714
                  oss << "At " << setprecision(10)
715
                      << sc_time_stamp().to_double()
716
                      << " : " << "Agent " << setfill(' ') << setw(3) << _id
717
                      << " received non-exclusive packet while locked, id: "
718
                      << packetId;
719
                  SC_REPORT_WARNING("warning", oss.str().c_str());
720
               }
721
 
722
 
723
               // Lock this agent when getting lock command
724
               if(cmd == EXCL_LOCK && !_locked)
725
               { _locked = true; }
726
 
727
               // Release the lock
728
               if(cmd == EXCL_RELEASE && _locked)
729
               { _locked = false; }
730
 
731
               //_packetsIn[packetId]->receiveWord();
732
               (*_packetsIn.find(packetId)).second->receiveWord();
733
 
734
               //if(_packetsIn[packetId]->complete())
735
               if((*_packetsIn.find(packetId)).second->complete())
736
               {
737
                  // Packet is fully received, remove it to save some memory
738
                  cout << "At "
739
                       << setprecision(10) << sc_time_stamp().to_double()
740
                       << " : " << "Agent " << setfill(' ') << setw(3) << dec
741
                       << _id << " received "
742
                       << commmand2str(msg_comm_in.read().to_uint())
743
                       << " packet: "
744
                       << setw(5) << setfill(' ') << packetId << " from ";
745
                  cout << "address: 0x"
746
                       << hex << setw(8) << setfill('0')
747
                     //<< _packetsIn[packetId]->getSrcAddress().to_uint()
748
                       << (*_packetsIn.find(packetId)).second->getSrcAddress()
749
                     .to_uint()
750
                       << endl;
751
 
752
                  if(cmd == DATA_RD ||
753
                     cmd == MSG_RD ||
754
                     cmd == EXCL_RD ||
755
                     cmd == DATA_RDL ||
756
                     cmd == MSG_RDL)
757
                  {
758
                     // Generate response packet
759
                     Packet* packet = 0;
760
                     packet = new Packet((*_packetsIn.find(packetId)).second->
761
                                         getResponseSize(),
762
                                         addresses_c[_id],
763
                                         (*_packetsIn.find(packetId)).second->
764
                                         getSrcAddress(),
765
                                         DATA_WRNP);
766
                     this->send(packet);
767
                     for(unsigned int i = 0; i < _agents.size(); ++i)
768
                     {
769
                        if(addresses_c[i] ==
770
                           (*_packetsIn.find(packetId)).second->getSrcAddress())
771
                        {
772
                           _agents.at(i)->expect(packet);
773
                        }
774
                     }
775
                  }
776
 
777
                  //delete _packetsIn[packetId];
778
                  delete (*_packetsIn.find(packetId)).second;
779
                  //_packetsIn.erase(packetId);
780
                  _packetsIn.erase(_packetsIn.find(packetId));
781
               }
782
            }
783
         }
784
 
785
         // Do nothing if there's nothing to do...
786
         if(msg_empty_in.read() == true) continue;
787
 
788
         // Chance to play dead for this cycle
789
         if((unsigned(rand()) % 100) < _rxBusyChance) continue;
790
 
791
 
792
         // Read the flit
793
         msg_re_out.write(true);
794
         reading = true;
795
 
796
 
797
      }
798
   }
799
 
800
 
801
 
802
#endif
803
 
804
   //
805
   // Private members
806
   //
807
 
808
   // FIFO(s) for packets to be send
809
   queue            _packetsOut;
810
#ifdef USE_R3_WRAPPERS
811
   queue            _msgPacketsOut;
812
#endif
813
 
814
   // Expected packets by their ID
815
   multimap, Packet*> _packetsIn;
816
 
817
   // agent identifier
818
   unsigned int _id;
819
 
820
   // Agent might be busy doing other things occasionally
821
   // Hence, transfer do not necessarily happen at max speed
822
   unsigned int _rxBusyChance;
823
   unsigned int _txBusyChance;
824
 
825
   // List of all agents is needed to notify them about
826
   // new packets
827
   vector
828
                comm_width_c, separate_addr_c>* >& _agents;
829
 
830
   // True when agent is locked
831
   bool _locked;
832
 
833
};
834
 
835
#endif
836
 
837
// Local Variables:
838
// mode: c++
839
// c-file-style: "ellemtel"
840
// c-basic-offset: 3
841
// End:
842
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.