1 |
76 |
diegovalve |
`timescale 1ns / 1ps
|
2 |
|
|
`include "aDefinitions.v"
|
3 |
|
|
|
4 |
|
|
//---------------------------------------------------------------------------
|
5 |
|
|
module THEIA
|
6 |
|
|
(
|
7 |
109 |
diegovalve |
|
8 |
|
|
input wire CLK_I, //Input clock
|
9 |
|
|
input wire RST_I, //Input reset
|
10 |
|
|
//Theia Interfaces
|
11 |
|
|
input wire MST_I, //Master signal, THEIA enters configuration mode
|
12 |
|
|
//when this gets asserted (see documentation)
|
13 |
|
|
//Wish Bone Interface
|
14 |
|
|
input wire [`WB_WIDTH-1:0] DAT_I, //Input data bus (Wishbone)
|
15 |
|
|
//output wire [`WB_WIDTH-1:0] DAT_O, //Output data bus (Wishbone)
|
16 |
|
|
input wire ACK_I, //Input ack
|
17 |
|
|
output wire ACK_O, //Output ack
|
18 |
|
|
//output wire [`WB_WIDTH-1:0] ADR_O, //Output address
|
19 |
|
|
input wire [`WB_WIDTH-1:0] ADR_I, //Input address
|
20 |
|
|
//output wire WE_O, //Output write enable
|
21 |
|
|
input wire WE_I, //Input write enable
|
22 |
|
|
//output wire STB_O, //Strobe signal, see wishbone documentation
|
23 |
|
|
input wire STB_I, //Strobe signal, see wishbone documentation
|
24 |
|
|
//output wire CYC_O, //Bus cycle signal, see wishbone documentation
|
25 |
|
|
input wire CYC_I, //Bus cycle signal, see wishbone documentation
|
26 |
|
|
//output wire [1:0] TGC_O, //Bus cycle tag, see THEAI documentation
|
27 |
|
|
input wire [1:0] TGA_I, //Input address tag, see THEAI documentation
|
28 |
|
|
//output wire [1:0] TGA_O, //Output address tag, see THEAI documentation
|
29 |
|
|
//input wire [1:0] TGC_I, //Bus cycle tag, see THEAI documentation
|
30 |
76 |
diegovalve |
input wire [`MAX_CORES-1:0] SEL_I, //The WishBone Master uses this signal to configure a specific core (TBD, not sure is needed)
|
31 |
109 |
diegovalve |
input wire [`MAX_CORES-1:0] RENDREN_I,
|
32 |
|
|
|
33 |
|
|
input wire [`MAX_CORE_BITS-1:0] OMBSEL_I, //Output memory bank select
|
34 |
|
|
input wire [`WB_WIDTH-1:0] OMADR_I, //Output adress (relative to current bank)
|
35 |
|
|
output wire [`WB_WIDTH-1:0] OMEM_O, //Output data bus (Wishbone)
|
36 |
|
|
|
37 |
|
|
input wire [`WB_WIDTH-1:0] TMDAT_I,
|
38 |
|
|
input wire [`WB_WIDTH-1:0] TMADR_I,
|
39 |
|
|
input wire TMWE_I,
|
40 |
|
|
input wire [`MAX_TMEM_BANKS-1:0] TMSEL_I,
|
41 |
|
|
//Control Register
|
42 |
76 |
diegovalve |
input wire [15:0] CREG_I,
|
43 |
109 |
diegovalve |
output wire GRDY_O,
|
44 |
|
|
input wire STDONE_I,
|
45 |
|
|
input wire HDA_I,
|
46 |
|
|
input wire GACK_I,
|
47 |
|
|
output wire RCOMMIT_O,
|
48 |
|
|
output wire DONE_O
|
49 |
16 |
diegovalve |
|
50 |
76 |
diegovalve |
);
|
51 |
16 |
diegovalve |
|
52 |
|
|
|
53 |
|
|
|
54 |
76 |
diegovalve |
|
55 |
109 |
diegovalve |
wire [`MAX_TMEM_BANKS-1:0] wTMemWriteEnable;
|
56 |
|
|
SELECT_1_TO_N # ( `MAX_TMEM_BANKS, `MAX_TMEM_BANKS ) TMWE_SEL
|
57 |
|
|
(
|
58 |
|
|
.Sel(TMSEL_I),
|
59 |
|
|
.En(TMWE_I),
|
60 |
|
|
.O(wTMemWriteEnable)
|
61 |
|
|
);
|
62 |
|
|
|
63 |
|
|
|
64 |
76 |
diegovalve |
wire [`MAX_CORES-1:0] wDone;
|
65 |
|
|
wire [`MAX_CORES-1:0] wBusGranted,wBusRequest;
|
66 |
109 |
diegovalve |
//wire [`WB_WIDTH-1:0] wDAT_O[`MAX_CORES-1:0];
|
67 |
|
|
//wire [`WB_WIDTH-1:0] wADR_O[`MAX_CORES-1:0];
|
68 |
|
|
//wire [1:0] wTGA_O[`MAX_CORES-1:0];
|
69 |
|
|
wire [`MAX_CORE_BITS-1:0] wBusSelect;
|
70 |
76 |
diegovalve |
|
71 |
|
|
|
72 |
109 |
diegovalve |
//wire [`MAX_CORES-1:0] wSTB_O;
|
73 |
|
|
//wire [`MAX_CORES-1:0] wWE_O;
|
74 |
|
|
wire [`MAX_CORES-1:0]wACK_O;
|
75 |
76 |
diegovalve |
|
76 |
|
|
|
77 |
109 |
diegovalve |
wire wOMem_WE[`MAX_CORES-1:0];
|
78 |
|
|
wire [`WB_WIDTH-1:0] wOMEM_Address[`MAX_CORES-1:0];
|
79 |
|
|
wire [`WB_WIDTH-1:0] wOMEM_Dat[`MAX_CORES-1:0];
|
80 |
|
|
|
81 |
76 |
diegovalve |
wire [`MAX_CORES-1:0] wSTB_I;
|
82 |
|
|
wire [`MAX_CORES-1:0] wMST_I;
|
83 |
|
|
wire [`MAX_CORES-1:0] wACK_I;
|
84 |
|
|
wire [`MAX_CORES-1:0] wCYC_I;
|
85 |
|
|
wire [1:0] wTGA_I[`MAX_CORES-1:0];
|
86 |
|
|
|
87 |
|
|
|
88 |
109 |
diegovalve |
//wire [`MAX_CORES-1:0] wTMEM_ACK_I;
|
89 |
|
|
wire [`WB_WIDTH-1:0] wTMEM_Data;
|
90 |
|
|
wire [`WB_WIDTH-1:0] wTMEM_Address[`MAX_CORES-1:0];
|
91 |
|
|
wire [`WB_WIDTH-1:0] wTMEM_ReadAddr;
|
92 |
|
|
//wire [`MAX_CORES-1:0] wTMEM_STB_O;
|
93 |
|
|
wire [`MAX_CORES-1:0] wTMEM_Resquest;
|
94 |
|
|
wire [`MAX_CORES-1:0] wTMEM_Granted;
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
//CROSS-BAR cables
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
wire [`WB_WIDTH-1:0] wCrossBarDataRow[`MAX_TMEM_BANKS-1:0]; //Horizontal grid Buses comming from each bank
|
103 |
|
|
wire [`WB_WIDTH-1:0] wCrossBarDataCollumn[`MAX_CORES-1:0]; //Vertical grid buses comming from each core.
|
104 |
|
|
wire [`WB_WIDTH-1:0] wTMemReadAdr[`MAX_CORES-1:0]; //Horizontal grid Buses comming from each core (virtual addr).
|
105 |
|
|
wire [`WB_WIDTH-1:0] wCrossBarAdressCollumn[`MAX_CORES-1:0]; //Vertical grid buses comming from each core. (physical addr).
|
106 |
|
|
wire [`WB_WIDTH-1:0] wCrossBarAddressRow[`MAX_TMEM_BANKS-1:0]; //Horizontal grid Buses comming from each bank.
|
107 |
|
|
|
108 |
|
|
wire wCORE_2_TMEM__Req[`MAX_CORES-1:0];
|
109 |
|
|
wire [`MAX_TMEM_BANKS -1:0] wBankReadRequest[`MAX_CORES-1:0];
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
wire [`MAX_CORES-1:0] wBankReadGranted[`MAX_TMEM_BANKS-1:0];
|
113 |
|
|
wire wTMEM_2_Core__Grant[`MAX_CORES-1:0];
|
114 |
|
|
|
115 |
|
|
wire[`MAX_CORE_BITS-1:0] wCurrentCoreSelected[`MAX_TMEM_BANKS-1:0];
|
116 |
|
|
//wire [`WB_WIDTH-1:0] wTMEM_2_Core_Data[`MAX_CORES-1:0]; //Vertical grid Buses going to each core.
|
117 |
|
|
wire[7:0] wCoreBankSelect[`MAX_CORES-1:0];
|
118 |
|
|
wire [`MAX_CORES-1:0] wGRDY_O;
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
wire [`MAX_CORES-1:0] wGReady;
|
122 |
|
|
wire [`MAX_CORES-1:0] wRCOMMIT_O;
|
123 |
|
|
wire [`MAX_CORES-1:0] wRCommited;
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
assign RCOMMIT_O = wRCommited[0] & wRCommited[1] & wRCommited[2] & wRCommited[3];
|
127 |
|
|
assign GRDY_O = wGReady[0] & wGReady[1] & wGReady[2] & wGReady[3];
|
128 |
76 |
diegovalve |
//----------------------------------------------------------------
|
129 |
109 |
diegovalve |
//The next secuencial logic just AND all the wDone signals
|
130 |
|
|
//I know that it would be much more elgant to just do parallel:
|
131 |
|
|
//assign DONE_O = wDone[0] & wDone[1] & ... & wDone[MAX_CORES-1];
|
132 |
|
|
//However, I don't know how to achieve this with 'generate' statements
|
133 |
|
|
//So coding a simple loop instead
|
134 |
|
|
|
135 |
|
|
/*
|
136 |
|
|
always @ (posedge CLK_I)
|
137 |
|
|
begin : AND_DONE_SIGNALS
|
138 |
|
|
integer k;
|
139 |
|
|
DONE_O = wDone[0];
|
140 |
|
|
for (k=0;k<=`MAX_CORES;k=k+1)
|
141 |
|
|
DONE_O=DONE_O & wDone[k+1];
|
142 |
|
|
end
|
143 |
|
|
*/
|
144 |
|
|
assign DONE_O = wDone[0] & wDone[1] & wDone[2] & wDone[3]; //Replace this by a counter??
|
145 |
|
|
//----------------------------------------------------------------
|
146 |
|
|
|
147 |
76 |
diegovalve |
Module_BusArbitrer ARB1
|
148 |
|
|
(
|
149 |
|
|
.Clock( CLK_I ),
|
150 |
|
|
.Reset( RST_I ),
|
151 |
|
|
.iRequest( wBusRequest ),
|
152 |
|
|
.oGrant( wBusGranted ),
|
153 |
|
|
.oBusSelect( wBusSelect )
|
154 |
|
|
|
155 |
|
|
);
|
156 |
|
|
//----------------------------------------------------------------
|
157 |
|
|
|
158 |
109 |
diegovalve |
// assign DAT_O = wDAT_O[ wBusSelect ];
|
159 |
|
|
// assign TGA_O = wTGA_O[ wBusSelect ];
|
160 |
|
|
// assign ADR_O = wADR_O[ wBusSelect ];
|
161 |
|
|
// assign STB_O = wSTB_O[ wBusSelect ];
|
162 |
|
|
// assign WE_O = wWE_O[ wBusSelect ];
|
163 |
|
|
assign ACK_O = wACK_O[ wBusSelect];
|
164 |
76 |
diegovalve |
|
165 |
109 |
diegovalve |
wire [`WB_WIDTH-1:0] wDataOut[`MAX_CORES-1:0];
|
166 |
|
|
assign OMEM_O = wDataOut[ OMBSEL_I ];
|
167 |
76 |
diegovalve |
|
168 |
109 |
diegovalve |
genvar i;
|
169 |
|
|
generate
|
170 |
|
|
for (i = 0; i < `MAX_CORES; i = i +1)
|
171 |
|
|
begin : CORE
|
172 |
|
|
assign wMST_I[i] = (SEL_I[i]) ? MST_I : 0;
|
173 |
|
|
assign wSTB_I[i] = (SEL_I[i]) ? STB_I : 0;
|
174 |
|
|
assign wCYC_I[i] = (SEL_I[i]) ? CYC_I : 0;
|
175 |
|
|
assign wTGA_I[i] = (SEL_I[i]) ? TGA_I : 0;
|
176 |
76 |
diegovalve |
|
177 |
109 |
diegovalve |
|
178 |
|
|
THEIACORE CTHEIA
|
179 |
|
|
(
|
180 |
|
|
.CLK_I( CLK_I ),
|
181 |
76 |
diegovalve |
.RST_I( RST_I ),
|
182 |
109 |
diegovalve |
.RENDREN_I( RENDREN_I[i] ),
|
183 |
76 |
diegovalve |
|
184 |
|
|
//Slave signals
|
185 |
109 |
diegovalve |
.ADR_I( ADR_I ),
|
186 |
76 |
diegovalve |
.WE_I( WE_I ),
|
187 |
109 |
diegovalve |
.STB_I( wSTB_I[i] ),
|
188 |
82 |
diegovalve |
.ACK_I( ACK_I ),
|
189 |
109 |
diegovalve |
.CYC_I( wCYC_I[i] ),
|
190 |
|
|
.MST_I( wMST_I[i] ),
|
191 |
|
|
.TGA_I( wTGA_I[i] ),
|
192 |
76 |
diegovalve |
.CREG_I( CREG_I ),
|
193 |
|
|
|
194 |
109 |
diegovalve |
//Master Signals
|
195 |
|
|
//.WE_O ( wWE_O[i] ),
|
196 |
|
|
//.STB_O( wSTB_O[i] ),
|
197 |
|
|
.ACK_O( wACK_O[i] ),
|
198 |
|
|
// .DAT_O( wDAT_O[i] ),
|
199 |
|
|
//.ADR_O( wADR_O[i] ),
|
200 |
|
|
.CYC_O( wBusRequest[i] ),
|
201 |
|
|
.GNT_I( wBusGranted[i] ),
|
202 |
|
|
//.TGA_O( wTGA_O[i] ),
|
203 |
76 |
diegovalve |
`ifdef DEBUG
|
204 |
109 |
diegovalve |
.iDebug_CoreID( i ),
|
205 |
76 |
diegovalve |
`endif
|
206 |
|
|
|
207 |
109 |
diegovalve |
.OMEM_WE_O( wOMem_WE[i] ),
|
208 |
|
|
.OMEM_ADR_O( wOMEM_Address[i] ),
|
209 |
|
|
.OMEM_DAT_O( wOMEM_Dat[i] ),
|
210 |
76 |
diegovalve |
|
211 |
109 |
diegovalve |
|
212 |
82 |
diegovalve |
|
213 |
109 |
diegovalve |
.TMEM_DAT_I( wCrossBarDataCollumn[i] ),
|
214 |
|
|
.TMEM_ADR_O( wTMemReadAdr[i] ),
|
215 |
|
|
.TMEM_CYC_O( wCORE_2_TMEM__Req[i] ),
|
216 |
|
|
.TMEM_GNT_I( wTMEM_2_Core__Grant[i] ),
|
217 |
82 |
diegovalve |
|
218 |
109 |
diegovalve |
.GRDY_O( wGRDY_O[i] ),
|
219 |
|
|
.STDONE_I( STDONE_I ),
|
220 |
|
|
.RCOMMIT_O( wRCOMMIT_O[i] ),
|
221 |
|
|
.HDA_I( HDA_I ),
|
222 |
82 |
diegovalve |
|
223 |
|
|
//Other
|
224 |
|
|
.DAT_I( DAT_I ),
|
225 |
109 |
diegovalve |
.DONE_O( wDone[i] )
|
226 |
|
|
|
227 |
82 |
diegovalve |
);
|
228 |
109 |
diegovalve |
|
229 |
|
|
UPCOUNTER_POSEDGE # (1) UP_RCOMMIT
|
230 |
|
|
(
|
231 |
|
|
.Clock( CLK_I ),
|
232 |
|
|
.Reset( RST_I | GACK_I ),
|
233 |
|
|
.Initial( 1'b0 ),
|
234 |
|
|
.Enable( wRCOMMIT_O[i] ),
|
235 |
|
|
.Q(wRCommited[i])
|
236 |
|
|
);
|
237 |
|
|
|
238 |
|
|
UPCOUNTER_POSEDGE # (1) UP_GREADY
|
239 |
|
|
(
|
240 |
|
|
.Clock( CLK_I ),
|
241 |
|
|
.Reset( RST_I | GACK_I ),
|
242 |
|
|
.Initial( 1'b0 ),
|
243 |
|
|
.Enable( wGRDY_O[i] ),
|
244 |
|
|
.Q(wGReady[i])
|
245 |
|
|
);
|
246 |
|
|
|
247 |
|
|
RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 500000 ) OMEM //10k mem
|
248 |
|
|
(
|
249 |
|
|
.Clock( CLK_I ),
|
250 |
|
|
.iWriteEnable( wOMem_WE[i] ),
|
251 |
|
|
.iWriteAddress( wOMEM_Address[i] ),
|
252 |
|
|
.iDataIn( wOMEM_Dat[i] ),
|
253 |
|
|
.iReadAddress0( OMADR_I ),
|
254 |
|
|
.oDataOut0( wDataOut[i] )
|
255 |
|
|
|
256 |
|
|
);
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
//If there are "n" banks, memory location "X" would reside in bank number X mod n.
|
260 |
|
|
//X mod 2^n == X & (2^n - 1)
|
261 |
|
|
assign wCoreBankSelect[i] = (wTMemReadAdr[i] & (`MAX_TMEM_BANKS-1));
|
262 |
|
|
|
263 |
|
|
//Each core has 1 bank request slot
|
264 |
|
|
//Each slot has MAX_TMEM_BANKS bits. Only 1 bit can
|
265 |
|
|
//be 1 at any given point in time. All bits zero means,
|
266 |
|
|
//we are not requesting to read from any memory bank.
|
267 |
|
|
SELECT_1_TO_N # ( 8, 4 ) READDRQ
|
268 |
|
|
(
|
269 |
|
|
.Sel(wCoreBankSelect[ i]),
|
270 |
|
|
.En(wCORE_2_TMEM__Req[i]),
|
271 |
|
|
.O(wBankReadRequest[i])
|
272 |
|
|
);
|
273 |
|
|
|
274 |
|
|
//The address coming from the core is virtual adress, meaning it assumes linear
|
275 |
|
|
//address space, however, since memory is interleaved in a n-way memory we transform
|
276 |
|
|
//virtual adress into physical adress (relative to the bank) like this
|
277 |
|
|
//fadr = vadr / n = vadr >> log2(n)
|
278 |
|
|
|
279 |
|
|
assign wCrossBarAdressCollumn[i] = (wTMemReadAdr[i] >> ((`MAX_TMEM_BANKS)/2));
|
280 |
|
|
|
281 |
|
|
//Connect the granted signal to Arbiter of the Bank we want to read from
|
282 |
|
|
assign wTMEM_2_Core__Grant[i] = wBankReadGranted[wCoreBankSelect[i]][i];
|
283 |
|
|
|
284 |
|
|
//Connect the request signal to Arbiter of the Bank we want to read from
|
285 |
|
|
//assign wBankReadRequest[wCoreBankSelect[i]][i] = wCORE_2_TMEM__Req[i];
|
286 |
|
|
|
287 |
|
|
end
|
288 |
|
|
endgenerate
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
////////////// CROSS-BAR INTERCONECTION//////////////////////////
|
292 |
|
|
|
293 |
|
|
genvar Core,Bank;
|
294 |
|
|
generate
|
295 |
|
|
for (Bank = 0; Bank < `MAX_TMEM_BANKS; Bank = Bank + 1)
|
296 |
|
|
begin : BANK
|
297 |
|
|
|
298 |
|
|
//The memory bank itself
|
299 |
|
|
RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 50000 ) TMEM
|
300 |
|
|
(
|
301 |
|
|
.Clock( CLK_I ),
|
302 |
|
|
.iWriteEnable( wTMemWriteEnable[Bank] ),
|
303 |
|
|
.iWriteAddress( TMADR_I ),
|
304 |
|
|
.iDataIn( TMDAT_I ),
|
305 |
|
|
.iReadAddress0( wCrossBarAddressRow[Bank] ), //Connect to the Row of the grid
|
306 |
|
|
.oDataOut0( wCrossBarDataRow[Bank] ) //Connect to the Row of the grid
|
307 |
|
|
|
308 |
|
|
);
|
309 |
|
|
|
310 |
|
|
//Arbiter will Round-Robin Cores attempting to read from the same Bank
|
311 |
|
|
//at a given point in time
|
312 |
|
|
wire [`MAX_CORES-1:0] wBankReadGrantedDelay[`MAX_TMEM_BANKS-1:0];
|
313 |
|
|
Module_BusArbitrer ARB_TMEM
|
314 |
|
|
(
|
315 |
|
|
.Clock( CLK_I ),
|
316 |
|
|
.Reset( RST_I ),
|
317 |
|
|
.iRequest( {wBankReadRequest[3][Bank],wBankReadRequest[2][Bank],wBankReadRequest[1][Bank],wBankReadRequest[0][Bank]}),//wBankReadRequest[Bank] ), //The cores requesting to read from this Bank
|
318 |
|
|
.oGrant( wBankReadGrantedDelay[Bank] ), //The bit of the core granted to read from this Bank
|
319 |
|
|
.oBusSelect( wCurrentCoreSelected[Bank] ) //The index of the core granted to read from this Bank
|
320 |
|
|
|
321 |
|
|
);
|
322 |
|
|
|
323 |
|
|
FFD_POSEDGE_SYNCRONOUS_RESET # ( `MAX_CORES ) FFD_GNT
|
324 |
|
|
(
|
325 |
|
|
.Clock(CLK_I),
|
326 |
|
|
.Reset(RST_I),
|
327 |
|
|
.Enable( 1'b1 ),
|
328 |
|
|
.D(wBankReadGrantedDelay[Bank]),
|
329 |
|
|
.Q(wBankReadGranted[Bank])
|
330 |
|
|
);
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
//Create the Cross-Bar interconnection grid now, rows are coonected to the memory banks,
|
334 |
|
|
//while collumns are connected to the cores, 2 or more cores can not read from the same
|
335 |
|
|
//bank at any given point in time
|
336 |
|
|
for (Core = 0; Core < `MAX_CORES; Core = Core + 1)
|
337 |
|
|
begin: CORE_CONNECT
|
338 |
|
|
//Connect the Data Collum of this core to the Data Row of current bank, only if the Core is looking for data stored in this bank
|
339 |
|
|
assign wCrossBarDataCollumn[ Core ] = ( wCoreBankSelect[ Core ] == Bank ) ? wCrossBarDataRow[ Bank ] : `WB_WIDTH'bz;
|
340 |
|
|
//Connect the Address Row of this Bank to the Address Column of the core, only if the Arbiter selected this core for reading
|
341 |
|
|
assign wCrossBarAddressRow[ Bank ] = ( wCurrentCoreSelected[ Bank ] == Core ) ? wCrossBarAdressCollumn[Core]: `WB_WIDTH'bz;
|
342 |
|
|
|
343 |
|
|
end
|
344 |
|
|
|
345 |
|
|
end
|
346 |
|
|
endgenerate
|
347 |
|
|
|
348 |
|
|
////////////// CROSS-BAR INTERCONECTION//////////////////////////
|
349 |
82 |
diegovalve |
//----------------------------------------------------------------
|
350 |
109 |
diegovalve |
|
351 |
76 |
diegovalve |
endmodule
|
352 |
|
|
//---------------------------------------------------------------------------
|