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

Subversion Repositories async_sdm_noc

[/] [async_sdm_noc/] [branches/] [init/] [vc/] [tb/] [ni.cpp] - Blame information for rev 60

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 44 wsong0210
/*
2
 Asynchronous SDM NoC
3
 (C)2011 Wei Song
4
 Advanced Processor Technologies Group
5
 Computer Science, the Univ. of Manchester, UK
6
 
7
 Authors:
8
 Wei Song     wsong83@gmail.com
9
 
10
 License: LGPL 3.0 or later
11
 
12
 A SystemC network adapter/interface for NoC simulation.
13
 
14
 History:
15
 23/12/2008  Initial version. <wsong83@gmail.com>
16
 30/09/2010  Use template style packet definition. <wsong83@gmail.com>
17
 16/10/2010  Support SDM. <wsong83@gmail.com>
18
 05/06/2011  Clean up for opensource. <wsong83@gmail.com>
19
 
20
*/
21
 
22
#include "ni.h"
23
 
24
Network_Adapter::Network_Adapter(
25
         sc_module_name     name            // module name
26
        ,unsigned int       x               // location x
27
        ,unsigned int       y               // location y
28
    ):
29
         sc_module(name),
30
         frame_in("FrmIn"),
31
         frame_out("FrmOut"),
32
         IP("IP"),
33
         OP("OP"),
34
         loc_x(x),
35
         loc_y(y),
36
         oflit(1)
37
{
38
  sc_spawn_options opt;
39
 
40
  for(unsigned int i=0; i<SubChN; i++) {
41
    token[i] = BufDepth/2;
42
  }
43
 
44
  for(unsigned int i=0; i<SubChN; i++) {
45
    sc_spawn(sc_bind(&Network_Adapter::ibuffer_thread, this, i), NULL, &opt);
46
    sc_spawn(sc_bind(&Network_Adapter::obuffer_thread, this, i), NULL, &opt);
47
    sc_spawn(sc_bind(&Network_Adapter::credit_update, this, i), NULL, &opt);
48
  }
49
 
50
  SC_THREAD(oport);
51
  SC_THREAD(iport);
52
 
53
}
54
 
55
Network_Adapter::~Network_Adapter()
56
{
57
}
58
 
59
// read in the incoming frame
60
void Network_Adapter::ibuffer_thread(unsigned int ii){
61
  FRAME mframe;
62
  FLIT mflit;
63
 
64
  while(1){
65
    mframe.clear();
66
 
67
    while(1) {
68
      mflit = iflit[ii].read();
69
      mframe << mflit;
70
 
71
      if(mflit.ftype == F_TL)   break;
72
    }
73
 
74
    frame_out->write(mframe);
75
  }
76
}
77
 
78
// send out a frame
79
void Network_Adapter::obuffer_thread(unsigned int ii){
80
 
81
  FRAME mframe;
82
  FLIT mflit;
83
 
84
  while(1){
85
    mframe = frame_in->read();
86
 
87
    while(1) {
88
      mframe >> mflit;
89
      mflit.vcn = ii;
90
 
91
      //fetch a token
92
      if(token[ii] == 0)
93
        wait(token_arrive[ii]);
94
 
95
      token[ii]--;
96
 
97
      oflit.write(mflit);
98
 
99
      if(mflit.ftype == F_TL) break;
100
    }
101
  }
102
}
103
 
104
 
105
void Network_Adapter::oport() {
106
  FLIT mflit;
107
 
108
  while(1) {
109
    mflit = oflit.read();
110
    OP->write(mflit);
111
  }
112
}
113
 
114
void Network_Adapter::iport() {
115
  FLIT mflit;
116
 
117
  while(1) {
118
    mflit = IP->read();
119
    iflit[mflit.vcn].write(mflit);
120
  }
121
}
122
 
123
void Network_Adapter::credit_update(unsigned int ii) {
124
 
125
  CPa[ii].write(false);
126
  while(1) {
127
    if(!CP[ii].read())
128
      wait(CP[ii].posedge_event());
129
 
130
    token[ii]++;
131
    token_arrive[ii].notify();
132
    CPa[ii].write(true);
133
 
134
    wait(CP[ii].negedge_event());
135
    CPa[ii].write(false);
136
  }
137
}
138
 
139
bool Network_Adapter::check_frame(const FRAME& frame)
140
{
141
    // TODO: check the integerity, dummy right noe
142
    return true;
143
}
144
 
145
 
146
 
147
 

powered by: WebSVN 2.1.0

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