OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_verilator/] [topology/] [tree.h] - Blame information for rev 48

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

Line No. Rev Author Line
1 48 alirezamon
#ifndef BINTREE_H
2
        #define BINTREE_H
3
 
4
 
5
 
6
 
7
#define ROOT_L  (L-1) 
8
#define ROOT_ID  0
9
 
10
 
11
 
12
unsigned int    Lw;
13
unsigned int    Kw;
14
unsigned int    LKw;
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
unsigned int bintree_addrencode( unsigned int pos, unsigned int k, unsigned int l){
26
        unsigned int pow,i,tmp=0;
27
        unsigned int addrencode=0;
28
        unsigned int kw=0;
29
        while((0x1<<kw) < k)kw++;
30
        pow=1;
31
        for (i = 0; i <l; i=i+1 ) {
32
                tmp=(pos/pow);
33
                tmp=tmp%k;
34
                tmp=tmp<<(i)*kw;
35
                addrencode=addrencode | tmp;
36
                pow=pow * k;
37
        }
38
         return addrencode;
39
}
40
 
41
 
42
unsigned int bintree_addrdecode(unsigned int addrencode , unsigned int k, unsigned int l){
43
        unsigned int kw=0;
44
        unsigned int mask=0;
45
        unsigned int pow,i,tmp;
46
        unsigned int pos=0;
47
        while((0x1<<kw) < k){
48
                kw++;
49
                mask<<=1;
50
                mask|=0x1;
51
        }
52
        pow=1;
53
        for (i = 0; i <l; i=i+1 ) {
54
                tmp = addrencode & mask;
55
                tmp=(tmp*pow);
56
                pos= pos + tmp;
57
                pow=pow * k;
58
                addrencode>>=kw;
59
        }
60
        return pos;
61
}
62
 
63
 
64
 
65
unsigned int endp_addr_encoder ( unsigned int id){
66
                        return bintree_addrencode(id, T1, T2);
67
}
68
 
69
unsigned int endp_addr_decoder (unsigned int code){
70
                return bintree_addrdecode(code, T1, T2);
71
}
72
 
73
 
74
 
75
void topology_init (void){
76
 
77
        Lw=Log2(L);
78
        Kw=Log2(K);
79
        LKw=L*Kw;
80
 
81
 
82
        //assign current_layer_addr [ROOT_ID] = ROOT_L;
83
        //assign current_pos_addr [ROOT_ID] = {LKw{1'b0}}; 
84
        unsigned int addr = ROOT_L << LKw;
85
        router1[ROOT_ID]->current_r_addr = addr;
86
 
87
        unsigned int pos,level;
88
        unsigned int num = 0;
89
        //connect all up connections
90
        for (level = 1; level<L; level=level+1) { // : level_c          
91
                unsigned int L1 = L-1-level;
92
                unsigned int level2= level - 1;
93
                unsigned int L2 = L-1-level2;
94
                unsigned int NPOS = powi(K,level); // number of routers in this level
95
                for ( pos = 0; pos < NPOS; pos=pos+1 ) { // : pos_c
96
 
97
                        unsigned int ID1 = sum_powi ( K,level) + pos;
98
                        unsigned int BINTREE_EQ_POS1 = pos* powi(K,L1);
99
                        unsigned int ADR_CODE1=bintree_addrencode(BINTREE_EQ_POS1,K,L);
100
                        unsigned int POS2 = pos /K ;
101
                        unsigned int ID2 = sum_powi ( K,level-1) + (pos/K);
102
                        unsigned int PORT2= pos % K;
103
                        unsigned int BINTREE_EQ_POS2 = POS2*powi(K,L2);
104
                        unsigned int ADR_CODE2=bintree_addrencode(BINTREE_EQ_POS2,K,L);
105
 
106
 
107
 
108
                        // node_connection('Router[id1][k] to router[id2][pos%k];  
109
                        //assign  router_chan_out [ID1][K] = router_chan_in [ID2][PORT2];
110
                        //assign  router_chan_out [ID2][PORT2]= router_chan_in[ID1][K];  
111
                        //bintree_connect(Ti(ID1),Ri(ID1),port,Ti(ID2),Ri(ID2),PORT2);
112
                    r2r_cnt_all[num] =(r2r_cnt_table_t){.t1=Ti(ID1), .r1=Ri(ID1), .p1=K, .t2=Ti(ID2), .r2=Ri(ID2), .p2=PORT2 };
113
 
114
 
115
 
116
 
117
                        unsigned int current_layer_addr  = L1;
118
                        unsigned int current_pos_addr    = ADR_CODE1;
119
                        //assign current_r_addr [ID1] = {current_layer_addr [ID1],current_pos_addr[ID1]};
120
                        unsigned int addr = (current_layer_addr << LKw)| current_pos_addr;
121
 
122
                        router2[Ri(ID1)]->current_r_addr = addr;
123
                        //printf( "[%u] =(addr=%x), t1=%u, r1=%u, p1=%u, t2=%u, r2=%u, p2=%u \n",  num,addr, r2r_cnt_all[num].t1, r2r_cnt_all[num].r1, r2r_cnt_all[num].p1, r2r_cnt_all[num].t2, r2r_cnt_all[num].r2, r2r_cnt_all[num].p2 );
124
 
125
 
126
 
127
 
128
 
129
 
130
 
131
                 num++;
132
                        }// pos
133
 
134
                } //level
135
 
136
 
137
                // connect }points 
138
 
139
                for ( pos = 0; pos <  NE; pos=pos+1 ) { // : }points
140
                        //  node_connection T[pos] R[rid][pos %k];
141
                        unsigned int RID= sum_powi(K,L-1)+(pos/K);
142
                        unsigned int RPORT = pos%K;
143
                unsigned int CURRENTPOS=   bintree_addrencode(pos/K,K,L);
144
 
145
                        //assign router_chan_out [RID][RPORT] =    chan_in_all [pos];                     
146
                        //assign chan_out_all [pos] = router_chan_in [RID][RPORT];
147
                        r2e_cnt_all[pos].r1=Ri(RID);
148
                        r2e_cnt_all[pos].p1=RPORT;
149
 
150
                        er_addr [pos] = CURRENTPOS;
151
 
152
                } //pos    
153
 
154
}
155
 
156
 
157
void topology_connect_all_nodes (void){
158
        unsigned int pos,level;
159
        unsigned int num=0;
160
        //connect all up connections
161
        for (level = 1; level<L; level=level+1) { // : level_c
162
                unsigned int NPOS = powi(K,level); // number of routers in this level
163
                for ( pos = 0; pos < NPOS; pos=pos+1 ) { // : pos_c
164
 
165
                          fattree_connect(r2r_cnt_all[num]);
166
                          num++;
167
 
168
                }// pos
169
 
170
        } //level
171
 
172
 
173
        // connect }points 
174
 
175
        for ( pos = 0; pos <  NE; pos=pos+1 ) { // : }points
176
 
177
                        connect_r2e(2,r2e_cnt_all[pos].r1,r2e_cnt_all[pos].p1,pos);
178
 
179
 
180
        }
181
}
182
 
183
 
184
 
185
unsigned int get_mah_distance ( unsigned int id1, unsigned int id2){
186
 
187
        unsigned int k =T1;
188
        unsigned int l =T2;
189
 
190
        unsigned int pow,tmp1,tmp2;
191
        unsigned int distance=0;
192
        pow=1;
193
        for (unsigned int i = 0; i <l; i=i+1 ) {
194
                tmp1=(id1/pow);
195
                tmp2=(id2/pow);
196
                tmp1=tmp1 % k;
197
                tmp2=tmp2 % k;
198
                pow=pow * k;
199
                if(tmp1!=tmp2) distance= (i+1)*2-1; //distance obtained based on the highest level index which differ
200
 
201
        }
202
         return distance;
203
}
204
 
205
 
206
 
207
 
208
#endif
209
 
210
 
211
 

powered by: WebSVN 2.1.0

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