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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [trunk/] [test_bench/] [TestBench_THEIA.v] - Blame information for rev 77

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

Line No. Rev Author Line
1 13 diegovalve
 
2
/**********************************************************************************
3
Theia, Ray Cast Programable graphic Processing Unit.
4
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
5
 
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 
20
***********************************************************************************/
21
 
22
 
23
/*******************************************************************************
24
Module Description:
25
 
26
This is the Main test bench of the GPU. It simulates the behavior of
27
an external control unit or CPU that sends configuration information into DUT.
28
It also implements a second processs that simulates a Wishbone slave that sends
29
data from an external memory. These blocks are just behavioral CTE and therefore
30
are not meant to be synthethized.
31
 
32
*******************************************************************************/
33 61 diegovalve
 
34
 
35 13 diegovalve
`timescale 1ns / 1ps
36
`include "aDefinitions.v"
37
`define CONFIGURATION_PHASE                                             0
38
`define CTE_INITIAL_STATE                                                       0
39
`define CTE_IDLE                                                                                1
40
`define CTE_START_EU_CONFIGURATION_SEQUENCE     2
41
`define CTE_SEND_CONFIGURATION_PACKET                   3
42
`define CTE_ACK_CONFIGURATION_PACKET                    8
43
`define CTE_SEND_LIGHT_PACKET                                           13
44
`define CTE_ACK_LIGTH_PACKET                                            14
45
`define CTE_SEND_RAY_I_TASK                                             15
46
`define CTE_WAIT_FOR_TASK_ACK                                           16
47
`define WAIT_FOR_TASK_COMPLETE                                  17
48
`define CTE_PREPARE_NEW_TASK                                            18
49
`define CTE_RENDER_DONE                                                         19
50
`define CTE_READ_COLOR_DATA                                             20
51
`define CTE_GRANT_BUS_WRITE_PERMISION                   21
52
`define CTE_ACK_GRANT_BUS_PERMISION                             22
53
`define CTE_ACK_READ_COLOR_DATA                                 23
54
`define CTE_SEND_TEXTURE_DIMENSIONS                             24
55
`define CTE_ACK_TEXTURE_DIMENSIONS                              25
56
 
57
 
58
 
59
 
60
`define RESOLUTION_WIDTH                                                        (rSceneParameters[12] >> `SCALE)
61
`define RESOLUTION_HEIGHT                                                       (rSceneParameters[13] >> `SCALE)
62
`define RAYI_TASK                                                                               1
63
`define DELTA_ROW                                                                       (32'h1 << `SCALE)
64
`define DELTA_COL                                                                       (32'h1 << `SCALE)
65 77 diegovalve
 
66
`define SELECT_ALL_CORES `MAX_CORES'b0011;
67 13 diegovalve
module TestBench_Theia;
68
 
69
 
70
        //------------------------------------------------------------------------
71
        //**WARNING: Declare all of your varaibles at the begining
72
        //of the file. I hve noticed that sometimes the verilog
73
        //simulator allows you to use some regs even if they have not been 
74
        //previously declared, leadeing to crahses or unexpected behavior
75
        // Inputs
76
        reg Clock;
77
        reg Reset;
78
        reg ExternalBus_DataReady;
79
 
80
        // Outputs
81
        wire ExternalBus_Acknowledge;
82
        wire TaskCompleted;
83
 
84
        //CTE state machin logic
85
 
86
        reg[31:0] CurrentState,NextState;
87
        reg[3:0]  LightCount;
88
        reg[31:0] rLaneA,rLaneB,rLaneC,rLaneD;
89
        reg[16:0] CurrentTaskId;
90
        reg[31:0] CurrentPixelRow, CurrentPixelCol,CurrentRayType;
91
 
92
        reg CTE_WriteEnable;
93
        wire [`WB_WIDTH-1:0] DAT_O;
94
 
95
        reg                                             ACK_O;
96
        wire                                            ACK_I;
97
        wire [`WB_WIDTH-1:0] ADR_I,ADR_O;
98 77 diegovalve
        wire                                            WE_I,STB_I;
99 13 diegovalve
        reg CYC_O,WE_O,TGC_O,STB_O;
100
        wire [1:0] TGC_I;
101
        reg [1:0] TGA_O;
102
        wire [1:0] TGA_I;
103
        wire [31:0] DAT_I;
104
        integer ucode_file;
105
 
106
 
107
        reg [31:0] rInitialCol,rInitialRow;
108
        reg [31:0]       rControlRegister[2:0];
109
 
110
 
111
        integer file, log, r, a, b;
112
 
113
 
114
        reg [31:0]  rSceneParameters[31:0];
115
        reg [31:0]       rVertexBuffer[6000:0];
116 61 diegovalve
        reg [31:0]       rInstructionBuffer[512:0];
117 13 diegovalve
        `define TEXTURE_BUFFER_SIZE (256*256*3)
118 77 diegovalve
        reg [31:0]  rTextures[`TEXTURE_BUFFER_SIZE:0];            //Lets asume we use 256*256 textures
119
 
120
        integer i,j;
121
        `define MAX_WIDTH 200
122
        `define MAX_SCREENBUFFER (`MAX_WIDTH*`MAX_WIDTH*3)
123
        reg [7:0] rScreen[`MAX_SCREENBUFFER-1:0];
124 13 diegovalve
 
125
        //------------------------------------------------------------------------
126
        //Debug registers
127 69 diegovalve
        `define TASK_TIMEOUTMAX 150000//50000
128 13 diegovalve
 
129
 
130
 
131
        //------------------------------------------------------------------------
132
 
133
 
134
 
135
                reg MST_O;
136 77 diegovalve
//---------------------------------------------------------------       
137
 
138
wire [3:0] CYC_I,GNT_O;
139
wire wDone;
140
reg [`MAX_CORES-1:0] rCoreSelect,rRenderEnable;
141
 
142
THEIA GPU
143 13 diegovalve
                (
144
                .CLK_I( Clock ),
145 77 diegovalve
                .RST_I( Reset ),
146
                .RENDREN_I( rRenderEnable ),
147 13 diegovalve
                .DAT_I( DAT_O ),
148
                .ADR_O( ADR_I ),
149
                .ACK_I( ACK_O ),
150
                .WE_O ( WE_I ),
151
                .STB_O( STB_I ),
152 77 diegovalve
 
153 13 diegovalve
                .CYC_I( CYC_O ),
154
                .TGC_O( TGC_I ),
155
                .MST_I( MST_O ),
156
                .TGA_I( TGA_O ),
157
                .ACK_O( ACK_I ),
158
                .ADR_I( ADR_O ),
159
                .DAT_O( DAT_I ),
160 77 diegovalve
                .WE_I(  WE_O  ),
161
                .SEL_I( rCoreSelect ),//4'b0001 ),
162 13 diegovalve
                .STB_I( STB_O ),
163
                .TGA_O(TGA_I),
164
 
165
                //Control register
166 77 diegovalve
                .CREG_I( rControlRegister[0][15:0] ),
167
                //Other stuff
168
                .DONE_O( wDone )
169 13 diegovalve
 
170
        );
171 77 diegovalve
 
172
 
173
 
174
 
175 13 diegovalve
        //---------------------------------------------
176
        //generate the clock signal here
177
        always begin
178 61 diegovalve
                #`CLOCK_CYCLE  Clock =  ! Clock;
179 13 diegovalve
 
180
        end
181
        //---------------------------------------------
182
 
183
reg [15:0] rTimeOut;
184
 
185
                `define MAX_INSTRUCTIONS 2
186
 
187
        initial begin
188
                // Initialize Inputs
189
 
190
 
191
                Clock                                   = 0;
192
                Reset                                   = 0;
193
                CTE_WriteEnable                 = 0;
194
                rLaneA                                  = 32'b0;
195
                rLaneB                                  = 32'b0;
196
                rLaneC                                  = 32'b0;
197
                rLaneD                                  = 32'b0;
198
                ExternalBus_DataReady = 0;
199
                rTimeOut              = 0;
200 77 diegovalve
 
201
 
202
 
203 13 diegovalve
        `ifdef DUMP_CODE
204 69 diegovalve
                $write("Opening TestBench.log.... ");
205 13 diegovalve
                ucode_file = $fopen("TestBench.log","w");
206 69 diegovalve
                $display("Done");
207 13 diegovalve
        `endif
208
 
209
                //Read Config register values
210 69 diegovalve
                $write("Loading control register.... ");
211 13 diegovalve
                $readmemh("Creg.mem",rControlRegister);
212 69 diegovalve
                $display("Done");
213 13 diegovalve
 
214
 
215 69 diegovalve
 
216 13 diegovalve
                //Read configuration Data
217 69 diegovalve
                $write("Loading scene parameters.... ");
218 13 diegovalve
                $readmemh("Params.mem", rSceneParameters        );
219 69 diegovalve
                $display("Done");
220
 
221
                rInitialRow = rSceneParameters[18];
222
                rInitialCol = rSceneParameters[19];
223
 
224 13 diegovalve
                //Read Scene Data
225 69 diegovalve
                $write("Loading scene geometry.... ");
226 13 diegovalve
                $readmemh("Vertex.mem",rVertexBuffer);
227 69 diegovalve
                $display("Done");
228
 
229 13 diegovalve
                //Read Texture Data
230 69 diegovalve
                $write("Loading scene texture.... ");
231 13 diegovalve
                $readmemh("Textures.mem",rTextures);
232 69 diegovalve
                $display("Done");
233
 
234
 
235 13 diegovalve
                //Read instruction data
236 69 diegovalve
                $write("Loading code allocation table and user shaders.... ");
237 13 diegovalve
                $readmemh("Instructions.mem",rInstructionBuffer);
238 69 diegovalve
                $display("Done");
239 13 diegovalve
 
240 69 diegovalve
                $display("Control Register : %b",rControlRegister[0]);
241
                $display("Initial Row      : %h",rInitialRow);
242
                $display("Initial Column   : %h",rInitialCol);
243
                $display("Resolution       : %d X %d",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
244
 
245 13 diegovalve
                //Open output file
246
                file = $fopen("Output.ppm");
247
                log  = $fopen("Simulation.log");
248
                $fwrite(log, "Simulation start time : %dns\n",$time);
249
                $fwrite(log, "Width : %d\n",`RESOLUTION_WIDTH);
250
                $fwrite(log, "Height : %d\n",`RESOLUTION_HEIGHT);
251
 
252
                $fwrite(file,"P3\n");
253
                $fwrite(file,"#This file was generated by Theia's RTL simulation\n");
254
                $fwrite(file,"%d %d\n",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
255
                $fwrite(file,"255\n");
256
 
257
                CurrentPixelRow = 0;
258
                CurrentPixelCol = 0;
259
                #10
260
                Reset = 1;
261
                ExternalBus_DataReady = 0;
262
 
263
                // Wait 100 ns for global reset to finish
264
                #100  Reset = 0;
265
 
266
        end
267
 
268
        reg [5:0] DataIndex;
269
        reg [31:0] ConfigurationPacketSize;
270
 
271
        reg [7:0] R,G,B;
272
 
273
 
274
//---------------------------------------------
275
 
276
always @ (posedge Clock)
277
begin
278
        rTimeOut = rTimeOut+1'b1;
279
        if (rTimeOut > `TASK_TIMEOUTMAX)
280
        begin
281
                 $display("%dns ERROR: THEIA Timed out after %d of inactivity\n",
282
                 $time(),rTimeOut);
283
                 $stop();
284
        end
285
end
286
 
287
reg [31:0] rSlaveData_O;
288
//reg [31:0] rOutputFrameBuffer[39000:0];
289
reg [31:0] rColor;
290
 
291
reg [7:0] Thingy;
292
//Wish-Bone Slave logic.
293
//
294
//This logic represents a WBS FSM. It will provide
295
//the memory for Vertex and Texture data.
296
//Vertex/Tetxure data is stored in a 4GB RAM.
297
//Vertex data starts at address 0 and ends at address 0x80_000_000.
298
//Texture data starts at address 0x80_000_000 and ends at address
299
//0xFFFFFFFF.
300
//The Bit 31, indcates wheather we look for vertex (b=0)
301
//or texture (b=1)
302
 
303
`define WBS_AFTER_RESET                                 0
304
`define WBS_MOINTOR_STB_I                               1
305
`define WBS_ACK_O                                                       2
306
`define WBS_MOINTOR_STB_I_NEG                   3
307
`define WBS_DONE                    4
308
 
309
        reg [7:0]                        WBSCurrentState,WBSNextState;
310
        reg [31:0]                       rAddress;
311
 
312
        always @(negedge Clock)
313
        begin
314
        if( Reset!=1 )
315
           WBSCurrentState = WBSNextState;
316
                  else
317
                          WBSCurrentState = `WBS_AFTER_RESET;
318
        end
319
 
320
 
321
 
322
        reg [31:0] rConvertedTextureAddress;
323
        //----------------------------------------------------------    
324
        always @(posedge Clock)
325
        begin
326
                case (WBSCurrentState)
327
                //----------------------------------------
328
                `WBS_AFTER_RESET:
329
                begin
330
                        ACK_O = 0;
331
                        rSlaveData_O = 32'b0;
332
 
333
                        WBSNextState = `WBS_MOINTOR_STB_I;
334
                end
335
                //----------------------------------------
336
                `WBS_MOINTOR_STB_I:
337
                begin
338 77 diegovalve
                                if ( STB_I == 1 && wDone == 0)
339
                                WBSNextState = `WBS_ACK_O;
340
                        else if (STB_I == 0 && wDone == 0)
341
                                WBSNextState = `WBS_MOINTOR_STB_I;
342 13 diegovalve
                        else
343 77 diegovalve
                                WBSNextState = `WBS_DONE;
344 13 diegovalve
                end
345
                //----------------------------------------
346
                `WBS_ACK_O:
347
                begin
348
                        if (WE_I == 0)
349
                        begin
350
 
351
                                rAddress = ADR_I;
352
                                if (TGA_I == 2'b01) //replace this by TGA_I
353
                                begin
354
                                 //Multiply pithc (3), Add 2 because the first 2 bytes are text Width, Height
355
                                rConvertedTextureAddress = {1'b0,rAddress[30:0]} + 2;
356
                                if (rConvertedTextureAddress >= `TEXTURE_BUFFER_SIZE)
357
                                        rConvertedTextureAddress = `TEXTURE_BUFFER_SIZE-1;
358
 
359
 
360
                                        rSlaveData_O = rTextures[  rConvertedTextureAddress ];
361
                                        `ifdef DEBUG
362
 
363
                                        `LOGME"WB SLAVE: MASTER Requested read from texture address: %h (%d)Data = %h \n",rAddress, rConvertedTextureAddress,DAT_O );
364
                                        `endif
365
                                end
366
                                else
367
                                begin
368 77 diegovalve
                        //              Thingy = 0;  //THIS IS NOT RE-ENTRANT!!!
369 13 diegovalve
                                        rSlaveData_O = rVertexBuffer[ rAddress ];
370
                                        `ifdef DEBUG
371
                                        `LOGME"WB SLAVE: MASTER Requested read from vertex address: %h Data = %h\n",rAddress,DAT_O);
372
                                        `endif
373
                                end
374
 
375
                        end
376
                        else
377
                        begin
378 77 diegovalve
                        //      $display("%d Theia Writes value: %h @ %d (Time to process pixel %d Clock cycle)",$time, DAT_I,ADR_I,rTimeOut);
379 13 diegovalve
 
380
 
381 77 diegovalve
                //      if (Thingy == 0)
382
                //      begin
383
 
384
                //      end     
385 13 diegovalve
 
386 77 diegovalve
                //      Thingy = Thingy + 1;
387
                        if (CurrentPixelCol >=  (`RESOLUTION_WIDTH*3))
388 13 diegovalve
                        begin
389 77 diegovalve
                                CurrentPixelCol = 0;
390
                                CurrentPixelRow = CurrentPixelRow + 1;
391
                                $display("]- %d (%d)",CurrentPixelRow,ADR_I);
392 13 diegovalve
                                $write("[");
393
                        end
394
 
395 77 diegovalve
                //      if (Thingy == 3)
396
                //      begin
397
                                CurrentPixelCol = CurrentPixelCol + 1;
398
                                if ( CurrentPixelCol % 3  == 0)
399
                                begin
400
                        //      $fwrite(file,"\n# %d %d\n",CurrentPixelRow,CurrentPixelCol);
401
                                $write(".");
402
                                end
403
                                //Thingy = 0;
404
                //      end     
405 13 diegovalve
                                rTimeOut = 0;
406 77 diegovalve
                                R = ((DAT_I >> (`SCALE-8)) > 255) ? 255 : (DAT_I >>  (`SCALE-8));
407
                                rScreen[ ADR_I ] = R;
408
                        //      $fwrite(file,"%d " , R );
409 13 diegovalve
 
410
                        end
411
 
412
 
413
                        ACK_O = 1;
414 61 diegovalve
 
415 77 diegovalve
                //      if (CurrentPixelRow >= `RESOLUTION_HEIGHT)
416
                if (wDone)
417 13 diegovalve
                                WBSNextState = `WBS_DONE;
418
                        else
419
                                WBSNextState = `WBS_MOINTOR_STB_I_NEG;
420
                end
421
                //----------------------------------------
422
                `WBS_MOINTOR_STB_I_NEG:
423
                begin
424
                        if ( STB_I == 0 )
425
                        begin
426
                                ACK_O = 0;
427
                                WBSNextState = `WBS_MOINTOR_STB_I;
428
                        end
429
                        else
430
                                WBSNextState = `WBS_MOINTOR_STB_I_NEG;
431
                end
432
                //----------------------------------------
433 77 diegovalve
                `WBS_DONE:
434
                begin
435
                for (j = 0; j < `RESOLUTION_WIDTH; j = j+1)
436
                begin
437
 
438
                        for (i = 0; i < `RESOLUTION_HEIGHT*3; i = i +1)
439
                        begin
440
 
441
                        $fwrite(file,"%d " , rScreen[i+j*`RESOLUTION_WIDTH*3] );
442
                                if ((i %3) == 0)
443
                                                $fwrite(file,"\n# %d %d\n",i,j);
444
 
445
                        end
446
                end
447 13 diegovalve
                $display("RESOLUTION_WIDTH = %d,RESOLUTION_HEIGHT= %d",
448
                `RESOLUTION_WIDTH,`RESOLUTION_HEIGHT);
449
                $display("ADR_I = %d\n",ADR_I);
450
                        `LOGME"RENDER COMPLETE");
451
                        `LOGME"Closing File");
452
                        $fclose(file);
453
                        $fwrite(log, "Simulation end time : %dns\n",$time);
454
                        $fclose(log);
455
                        `LOGME"File Closed");
456
                        $stop();
457
                        $fclose(ucode_file);
458
                end
459
                //----------------------------------------
460
                default:
461
                begin
462 61 diegovalve
                $display("WBS Undefined state");
463 13 diegovalve
                end
464
                endcase
465
        end     //end always
466
        //----------------------------------------------------------    
467
 
468
 
469
 
470
 
471
`define TAG_BLOCK_WRITE_CYCLE    2'b01
472
`define TAG_INSTRUCTION_ADDRESS_TYPE 2'b01
473
`define TAG_DATA_ADDRESS_TYPE        2'b10
474
 
475
`define WBM_AFTER_RESET                                                 0
476
`define WBM_WRITE_INSTRUCTION_PHASE1            1
477
`define WBM_ACK_INSTRUCTION_PHASE1                      2
478
`define WBM_WRITE_INSTRUCTION_PHASE2            3
479
`define WBM_ACK_INSTRUCTION_PHASE2                      4
480
`define WBM_END_INSTRUCTION_WRITE_CYCLE   5
481
`define WBM_SEND_DATA_PHASE1                          6
482
`define WBM_ACK_DATA_PHASE1                           7
483
`define WBM_SEND_DATA_PHASE2                          8
484
`define WBM_ACK_DATA_PHASE2                           9
485
`define WBM_SEND_DATA_PHASE3                          10
486
`define WBM_ACK_DATA_PHASE3                           11
487
`define WBM_END_DATA_WRITE_CYCLE          12
488 77 diegovalve
`define WBM_DONE                          13
489
`define WBM_CONFIGURE_CORE0_PHASE1        14
490
`define WBM_ACK_CONFIGURE_CORE0_PHASE1    15
491
`define WBM_CONFIGURE_CORE0_PHASE2        16
492
`define WBM_ACK_CONFIGURE_CORE0_PHASE2    17
493
`define WBM_CONFIGURE_CORE0_PHASE3        18
494
`define WBM_ACK_CONFIGURE_CORE0_PHASE3    19
495
`define WBM_CONFIGURE_CORE1_PHASE1        20
496
`define WBM_ACK_CONFIGURE_CORE1_PHASE1    21
497
`define WBM_CONFIGURE_CORE1_PHASE2        22
498
`define WBM_ACK_CONFIGURE_CORE1_PHASE2    23
499
`define WBM_CONFIGURE_CORE1_PHASE3        24
500
`define WBM_ACK_CONFIGURE_CORE1_PHASE3    25
501
`define WBM_END_CORE0_WRITE_CYCLE         26
502
`define WBM_END_CORE1_WRITE_CYCLE         27
503 13 diegovalve
 
504 77 diegovalve
 
505 13 diegovalve
reg[31:0] rInstructionPointer;
506
reg[31:0] rAddressToSend;
507
reg[31:0] rDataAddress;
508
reg[31:0] rDataPointer;
509
 
510 77 diegovalve
reg IncIP,IncIA,IncDP;
511
reg rPrepateWriteAddressForNextCore;
512 13 diegovalve
reg rClearOutAddress;
513
//-----------------------------------------------------
514
always @ (posedge Clock or posedge rClearOutAddress)
515
begin
516
 
517
        if ( IncIA && ~rClearOutAddress)
518
                rAddressToSend = rAddressToSend + 1;
519
        else if (rClearOutAddress)
520
        begin
521
                if (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE)
522
                        rAddressToSend =  {16'd1,16'd0};
523 77 diegovalve
                else if (rPrepateWriteAddressForNextCore)
524
                        rAddressToSend = `CREG_PIXEL_2D_INITIAL_POSITION;
525 13 diegovalve
                else
526
                        rAddressToSend = 0;
527
        end
528
 
529
 
530
end
531
//-----------------------------------------------------
532
always @ (posedge ACK_I or posedge Reset )
533
begin
534
 
535
        if ( ACK_I && ~Reset)
536
                rInstructionPointer = rInstructionPointer + 1;
537
        else if (Reset)
538
                rInstructionPointer = 0;
539
 
540
 
541
 
542
end
543
//-----------------------------------------------------
544
reg rResetDp;
545
 
546
always @ (posedge Clock or posedge rResetDp )
547
begin
548
 
549
        if ( ACK_I && ~rResetDp)//IncDP && ~Reset)
550
                rDataPointer = rDataPointer + 1;
551
        else if (rResetDp)
552
                rDataPointer =  32'b0;
553
 
554
 
555
end
556
//-----------------------------------------------------
557
 
558
 
559
 
560
 
561
assign DAT_O = ( MST_O == 1'b1 ) ? wMasteData_O : rSlaveData_O;
562
 
563
wire[31:0] wMasteData_O;
564
 
565 61 diegovalve
 
566
 
567
assign wMasteData_O = (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE) ? rInstructionBuffer[rInstructionPointer+1] : rSceneParameters[ rDataPointer  ];
568
 
569
 
570
always @ (posedge STB_O)
571
begin
572
        if (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE)
573
        begin
574 69 diegovalve
                //$display("-- %x\n",wMasteData_O);
575 61 diegovalve
        end
576
end
577 13 diegovalve
assign ADR_O = rAddressToSend;
578
 
579
        reg [7:0]                        WBMCurrentState,WBMNextState;
580
        reg [31:0]                       rWriteAddress;
581
 
582
        always @(posedge Clock or posedge Reset)
583
        begin
584
        if( Reset!=1 )
585
           WBMCurrentState = WBMNextState;
586
                  else
587
                          WBMCurrentState = `WBM_AFTER_RESET;
588
        end
589
 
590
                wire[31:0] wConfigurationPacketSize;
591
                assign wConfigurationPacketSize = rSceneParameters[2];
592
 
593
   reg [31:0]  InstructionIndex;
594
        reg [31:0]  InstructionWriteAddress;
595
        //Send the instructions now...
596
        //----------------------------------------------------------    
597
        always @(posedge Clock)
598
        begin
599
                case (WBMCurrentState)
600
                //----------------------------------------
601 61 diegovalve
 
602
                //Wait until the reset secuence is complete to
603
                //begin sending stuff.
604
 
605 13 diegovalve
                `WBM_AFTER_RESET:
606
                begin
607
                        WE_O <=  0;
608
                        CYC_O <= 0;
609
                        TGC_O <= 0;
610
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
611
                        STB_O <= 0;
612
                //      IncIP <= 0;
613
                        IncIA <= 0;
614
                        MST_O   <= 0;
615
                        IncDP <= 0;
616
                        rResetDp <= 1;
617 77 diegovalve
                        rClearOutAddress <= 1;
618
                        rCoreSelect <= `SELECT_ALL_CORES;
619
                        rRenderEnable <= 0;
620
                        rPrepateWriteAddressForNextCore <= 0;
621 13 diegovalve
 
622
                        if (Reset == 0)
623
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
624
                        else
625
                                WBMNextState <= `WBM_AFTER_RESET;
626
                end
627
                //----------------------------------------
628 61 diegovalve
 
629
                //CLOCK EDGE 0: MASTER presents a valid address on [ADR_O()]
630
                //MASTER presents valid data on [DAT_O()]
631
                //MASTER asserts [WE_O] to indicate a WRITE cycle.
632
                //MASTER asserts [CYC_O] and [TGC_O()] to indicate the start of the cycle.
633
                //MASTER asserts [STB_O] to indicate the start of the phase.
634
 
635 13 diegovalve
                `WBM_WRITE_INSTRUCTION_PHASE1:
636
                begin
637
                        WE_O <=  1;                                                                                                     //Indicate write cycle
638
                        CYC_O <= 1;                                                                                                     //Start of the cycle
639
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
640
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;                 //TAG Address: 01 means instruction address type.
641
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
642
                //      IncIP <= 0;
643
                        IncIA <= 0;
644
                        MST_O   <= 1;
645
                        IncDP <= 0;
646
                        rResetDp <= 1;
647
                        rClearOutAddress <= 0;
648 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
649
                        rRenderEnable <= 0;
650
                        rPrepateWriteAddressForNextCore <= 0;
651 13 diegovalve
 
652
 
653
                        if ( ACK_I )
654
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE1;
655
                        else
656
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
657
 
658
                end
659
                //----------------------------------------
660
                `WBM_ACK_INSTRUCTION_PHASE1:
661
                begin
662
                        WE_O <=  1;
663
                        CYC_O <= 1;
664
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
665
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
666
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
667
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
668
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
669
                        MST_O   <= 1;
670
                        IncDP <= 0;
671
                        rResetDp <= 1;
672
                        rClearOutAddress <= 0;
673 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
674
                        rRenderEnable <= 0;
675
                        rPrepateWriteAddressForNextCore <= 0;
676 13 diegovalve
 
677
                        if (ACK_I == 0)
678
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE2;
679
                        else
680
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE1;
681
                end
682
                //----------------------------------------
683
                `WBM_WRITE_INSTRUCTION_PHASE2:
684
                begin
685
                        WE_O <=  1;
686
                        CYC_O <= 1;
687
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
688
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
689
                        STB_O <= ~ACK_I;
690
                //      IncIP <= 0;
691
                        IncIA <= 0;
692
                        MST_O   <= 1;
693
                        IncDP <= 0;
694
                        rResetDp <= 1;
695
                        rClearOutAddress <= 0;
696 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
697
                        rRenderEnable <= 0;
698
                        rPrepateWriteAddressForNextCore <= 0;
699
 
700 13 diegovalve
 
701
                        if ( ACK_I )
702
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE2;
703
                        else
704
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE2;
705
 
706
                end
707
                //----------------------------------------
708
                `WBM_ACK_INSTRUCTION_PHASE2:
709
                begin
710
                        WE_O <=  1;
711
                        CYC_O <= 0;
712
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
713
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
714
                        STB_O <= 0;      //*
715
 
716
                        MST_O   <= 1;
717
                        IncDP <= 0;
718
                        rResetDp <= 1;
719 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
720
                        rRenderEnable <= 0;
721
                        rPrepateWriteAddressForNextCore <= 0;
722 13 diegovalve
 
723 61 diegovalve
                if (rInstructionPointer >= rInstructionBuffer[0])
724 13 diegovalve
                begin
725
                                IncIA <= 0;//*   
726
                                rClearOutAddress <= 1;
727
                                WBMNextState    <= `WBM_SEND_DATA_PHASE1;
728
                end
729
                else
730
                begin
731
                                IncIA <= 1;//*  
732
                                rClearOutAddress <= 0;
733
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
734
                end
735
 
736
                end
737
        //****************************************
738
        `WBM_SEND_DATA_PHASE1:
739
                begin
740
                        WE_O <=  1;                                                                                                     //Indicate write cycle
741
                        CYC_O <= 1;                                                                                                     //Start of the cycle
742
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
743
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                //TAG Address: 01 means instruction address type.
744
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
745
                //      IncIP <= 0;
746
                        IncIA <= 0;
747
                        MST_O   <= 1;
748
                        IncDP <= 0;
749
                        rResetDp <= 0;
750
                        rClearOutAddress <= 0;
751 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
752
                        rRenderEnable <= 0;
753
                        rPrepateWriteAddressForNextCore <= 0;
754 13 diegovalve
 
755
                        if ( ACK_I )
756
                                WBMNextState <= `WBM_ACK_DATA_PHASE1;
757
                        else
758
                                WBMNextState <= `WBM_SEND_DATA_PHASE1;
759
 
760
                end
761
                //----------------------------------------
762
                `WBM_ACK_DATA_PHASE1:
763
                begin
764
                        WE_O <=  1;
765
                        CYC_O <= 1;
766
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
767
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
768
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
769
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
770
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
771
                        MST_O   <= 1;
772
                        IncDP <= 0;
773
                        rResetDp <= 0;
774
                        rClearOutAddress <= 0;
775 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
776
                        rRenderEnable <= 0;
777
                        rPrepateWriteAddressForNextCore <= 0;
778 13 diegovalve
 
779
                        if (ACK_I == 0)
780
                                WBMNextState <= `WBM_SEND_DATA_PHASE2;
781
                        else
782
                                WBMNextState <= `WBM_ACK_DATA_PHASE1;
783
                end
784
                //----------------------------------------
785
                `WBM_SEND_DATA_PHASE2:
786
                begin
787
                        WE_O <=  1;
788
                        CYC_O <= 1;
789
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
790
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
791
                        STB_O <= ~ACK_I;
792
                //      IncIP <= 0;
793
                        IncIA <= 0;
794
                        MST_O   <= 1;
795
                        IncDP <= 0;
796
                        rResetDp <= 0;
797
                        rClearOutAddress <= 0;
798 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
799
                        rRenderEnable <= 0;
800
                        rPrepateWriteAddressForNextCore <= 0;
801 13 diegovalve
 
802
                        if ( ACK_I )
803
                                WBMNextState <= `WBM_ACK_DATA_PHASE2;
804
                        else
805
                                WBMNextState <= `WBM_SEND_DATA_PHASE2;
806
 
807
                end
808
                //----------------------------------------
809
                `WBM_ACK_DATA_PHASE2:
810
                begin
811
                        WE_O <=  1;
812
                        CYC_O <= 1;
813
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
814
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
815
                        STB_O <= 0;      //*
816
                        IncIA <= 0;
817
                        MST_O   <= 1;
818
                        IncDP <= 0;//*           
819
                        rResetDp <= 0;
820
                        rClearOutAddress <= 0;
821 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
822
                        rRenderEnable <= 0;
823
                        rPrepateWriteAddressForNextCore <= 0;
824
 
825 13 diegovalve
                        if (ACK_I == 0)
826
                                WBMNextState <= `WBM_SEND_DATA_PHASE3;
827
                        else
828
                                WBMNextState <= `WBM_ACK_DATA_PHASE2;
829
 
830
                end
831
                //----------------------------------------
832
                `WBM_SEND_DATA_PHASE3:
833
                begin
834
                        WE_O <=  1;
835
                        CYC_O <= 1;
836
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
837
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
838
                        STB_O <= ~ACK_I;
839
                //      IncIP <= 0;
840
                        IncIA <= 0;
841
                        MST_O   <= 1;
842
                        IncDP <= 0;
843
                        rResetDp <= 0;
844
                        rClearOutAddress <= 0;
845 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
846
                        rRenderEnable <= 0;
847
                        rPrepateWriteAddressForNextCore <= 0;
848 13 diegovalve
 
849
                        if ( ACK_I )
850
                                WBMNextState <= `WBM_ACK_DATA_PHASE3;
851
                        else
852
                                WBMNextState <= `WBM_SEND_DATA_PHASE3;
853
 
854
                end
855
                //----------------------------------------
856
                `WBM_ACK_DATA_PHASE3:
857
                begin
858
                        WE_O <=  1;
859
                        CYC_O <= 1;
860
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
861
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
862
                        STB_O <= 0;      //*
863
                        IncIA <= 0;
864
                        MST_O   <= 1;
865
                        IncDP <= 1;//*          
866
                        rResetDp <= 0;
867
                        rClearOutAddress <= 0;
868 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
869
                        rRenderEnable <= 0;
870
                        rPrepateWriteAddressForNextCore <= 0;
871
 
872 13 diegovalve
                        WBMNextState <= `WBM_END_DATA_WRITE_CYCLE;
873
 
874
                end
875
                //----------------------------------------
876
                `WBM_END_DATA_WRITE_CYCLE:
877
                begin
878
                        WE_O <=  0;
879
                        CYC_O <= 0;      //*                                                                                             
880
                        TGC_O <= 0;
881
                        TGA_O <= 0;
882
                        STB_O <= 0;
883
                        IncIA <= 1;//*          
884
                        MST_O   <= 1;
885
                        IncDP <= 0;
886
                        rResetDp <= 0;
887
                        rClearOutAddress <= 0;
888 77 diegovalve
                        rCoreSelect <= `SELECT_ALL_CORES;
889
                        rRenderEnable <= 0;
890
                        rPrepateWriteAddressForNextCore <= 0;
891
 
892
                        if (rDataPointer > 3*5)//wConfigurationPacketSize*3)
893
                                WBMNextState    <= `WBM_CONFIGURE_CORE0_PHASE1;
894 13 diegovalve
                        else
895
                                WBMNextState <= `WBM_SEND_DATA_PHASE1;
896
 
897 77 diegovalve
                end
898
                //----------------------------------------
899
                `WBM_CONFIGURE_CORE0_PHASE1:
900
                begin
901
 
902
                        WE_O <=  1;                                                                                                     //Indicate write cycle
903
                        CYC_O <= 1;                                                                                                     //Start of the cycle
904
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
905
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                                        //TAG Address: 01 means instruction address type.
906
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
907
                //      IncIP <= 0;
908
                        IncIA <= 0;
909
                        MST_O   <= 1;
910
                        IncDP <= 0;
911
                        rResetDp <= 0;
912
                        rClearOutAddress <= 0;
913
                        rCoreSelect <= 4'b0001;
914
                        rRenderEnable <= 0;
915
                        rPrepateWriteAddressForNextCore <= 0;
916
 
917
                        if ( ACK_I )
918
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE0_PHASE1;
919
                        else
920
                                WBMNextState <= `WBM_CONFIGURE_CORE0_PHASE1;
921 13 diegovalve
                end
922 77 diegovalve
                //----------------------------------------
923
                `WBM_ACK_CONFIGURE_CORE0_PHASE1:
924
                begin
925
                        WE_O <=  1;
926
                        CYC_O <= 1;
927
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
928
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
929
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
930
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
931
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
932
                        MST_O   <= 1;
933
                        IncDP <= 0;
934
                        rResetDp <= 0;
935
                        rClearOutAddress <= 0;
936
                        rCoreSelect <= 4'b0001;
937
                        rRenderEnable <= 0;
938
                        rPrepateWriteAddressForNextCore <= 0;
939
 
940
                        if (ACK_I == 0)
941
                                WBMNextState <= `WBM_CONFIGURE_CORE0_PHASE2;
942
                        else
943
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE0_PHASE1;
944
                end
945
        //----------------------------------------
946
                `WBM_CONFIGURE_CORE0_PHASE2:
947
                begin
948
                        WE_O <=  1;                                                                                                     //Indicate write cycle
949
                        CYC_O <= 1;                                                                                                     //Start of the cycle
950
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
951
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                                        //TAG Address: 01 means instruction address type.
952
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
953
                //      IncIP <= 0;
954
                        IncIA <= 0;
955
                        MST_O   <= 1;
956
                        IncDP <= 0;
957
                        rResetDp <= 0;
958
                        rClearOutAddress <= 0;
959
                        rCoreSelect <= 4'b0001;
960
                        rRenderEnable <= 0;
961
                        rPrepateWriteAddressForNextCore <= 0;
962
 
963
                        if ( ACK_I )
964
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE0_PHASE2;
965
                        else
966
                                WBMNextState <= `WBM_CONFIGURE_CORE0_PHASE2;
967
                end
968
                //----------------------------------------
969
                `WBM_ACK_CONFIGURE_CORE0_PHASE2:
970
                begin
971
                        WE_O <=  1;
972
                        CYC_O <= 1;
973
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
974
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
975
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
976
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
977
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
978
                        MST_O   <= 1;
979
                        IncDP <= 0;
980
                        rResetDp <= 0;
981
                        rClearOutAddress <= 0;
982
                        rCoreSelect <= 4'b0001;
983
                        rRenderEnable <= 0;
984
                        rPrepateWriteAddressForNextCore <= 0;
985
 
986
                        if (ACK_I == 0)
987
                                WBMNextState <= `WBM_CONFIGURE_CORE0_PHASE3;
988
                        else
989
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE0_PHASE2;
990
                end
991
//----------------------------------------
992
                `WBM_CONFIGURE_CORE0_PHASE3:
993
                begin
994
                        WE_O <=  1;                                                                                                     //Indicate write cycle
995
                        CYC_O <= 1;                                                                                                     //Start of the cycle
996
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
997
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                                        //TAG Address: 01 means instruction address type.
998
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
999
                //      IncIP <= 0;
1000
                        IncIA <= 0;
1001
                        MST_O   <= 1;
1002
                        IncDP <= 0;
1003
                        rResetDp <= 0;
1004
                        rClearOutAddress <= 0;
1005
                        rCoreSelect <= 4'b0001;
1006
                        rRenderEnable <= 0;
1007
                        rPrepateWriteAddressForNextCore <= 0;
1008
 
1009
                        if ( ACK_I )
1010
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE0_PHASE3;
1011
                        else
1012
                                WBMNextState <= `WBM_CONFIGURE_CORE0_PHASE3;
1013
                end
1014
                //----------------------------------------
1015
                `WBM_ACK_CONFIGURE_CORE0_PHASE3:
1016
                begin
1017
                        WE_O <=  1;
1018
                        CYC_O <= 1;
1019
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
1020
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
1021
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
1022
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
1023
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
1024
                        MST_O   <= 1;
1025
                        IncDP <= 0;
1026
                        rResetDp <= 0;
1027
                        rClearOutAddress <= 0;
1028
                        rCoreSelect <= 4'b0001;
1029
                        rRenderEnable <= 0;
1030
                        rPrepateWriteAddressForNextCore <= 0;
1031
 
1032
                        if (ACK_I == 0)
1033
                                WBMNextState <= `WBM_END_CORE0_WRITE_CYCLE;
1034
                        else
1035
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE0_PHASE3;
1036
                end
1037
//----------------------------------------
1038
                `WBM_END_CORE0_WRITE_CYCLE:
1039
                begin
1040
                        WE_O <=  0;
1041
                        CYC_O <= 0;      //*                                                                                             
1042
                        TGC_O <= 0;
1043
                        TGA_O <= 0;
1044
                        STB_O <= 0;
1045
                        IncIA <= 1;//*          
1046
                        MST_O   <= 1;
1047
                        IncDP <= 0;
1048
                        rResetDp <= 0;
1049
 
1050
                        rCoreSelect <= 4'b0001;
1051
                        rRenderEnable <= 0;
1052
 
1053
 
1054
                        if (rDataPointer > 3*7)
1055
                        begin
1056
                                rClearOutAddress <= 1;
1057
                                rPrepateWriteAddressForNextCore <= 1;
1058
                                WBMNextState    <= `WBM_CONFIGURE_CORE1_PHASE1;
1059
                        end
1060
                        else
1061
                        begin
1062
                                rClearOutAddress <= 0;
1063
                                rPrepateWriteAddressForNextCore <= 0;
1064
                                WBMNextState <= `WBM_CONFIGURE_CORE0_PHASE1;
1065
                        end
1066
 
1067
                end
1068
 
1069
 
1070
//----------------------------------------
1071
                //Ok so from this point we configure CORE,
1072
                //we are going to configure the register:
1073
                //CREG_PIXEL_2D_INITIAL_POSITION and CREG_PIXEL_2D_FINAL_POSITION
1074
                //Since we incremented our Write Address pointer from the Core0 config,
1075
                //then now we need to make point to CREG_PIXEL_2D_INITIAL_POSITION again
1076
                //ans repeat the process for CORE1
1077
                `WBM_CONFIGURE_CORE1_PHASE1:
1078
                begin
1079
 
1080
                        WE_O <=  1;                                                                                                     //Indicate write cycle
1081
                        CYC_O <= 1;                                                                                                     //Start of the cycle
1082
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
1083
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                                        //TAG Address: 01 means instruction address type.
1084
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
1085
                //      IncIP <= 0;
1086
                        IncIA <= 0;
1087
                        MST_O   <= 1;
1088
                        IncDP <= 0;
1089
                        rResetDp <= 0;
1090
                        rClearOutAddress <= 0;
1091
                        rCoreSelect <= 4'b0010;
1092
                        rRenderEnable <= 0;
1093
                        rPrepateWriteAddressForNextCore <= 0;
1094
 
1095
                        if ( ACK_I )
1096
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE1_PHASE1;
1097
                        else
1098
                                WBMNextState <= `WBM_CONFIGURE_CORE1_PHASE1;
1099
                end
1100
                //----------------------------------------
1101
 
1102
                `WBM_ACK_CONFIGURE_CORE1_PHASE1:
1103
                begin
1104
                        WE_O <=  1;
1105
                        CYC_O <= 1;
1106
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
1107
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
1108
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
1109
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
1110
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
1111
                        MST_O   <= 1;
1112
                        IncDP <= 0;
1113
                        rResetDp <= 0;
1114
                        rClearOutAddress <= 0;
1115
                        rCoreSelect <= 4'b0010;
1116
                        rRenderEnable <= 0;
1117
                        rPrepateWriteAddressForNextCore <= 0;
1118
 
1119
                        if (ACK_I == 0)
1120
                                WBMNextState <= `WBM_CONFIGURE_CORE1_PHASE2;
1121
                        else
1122
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE1_PHASE1;
1123
                end
1124
        //----------------------------------------
1125
                `WBM_CONFIGURE_CORE1_PHASE2:
1126
                begin
1127
                        WE_O <=  1;                                                                                                     //Indicate write cycle
1128
                        CYC_O <= 1;                                                                                                     //Start of the cycle
1129
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
1130
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                                        //TAG Address: 01 means instruction address type.
1131
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
1132
                //      IncIP <= 0;
1133
                        IncIA <= 0;
1134
                        MST_O   <= 1;
1135
                        IncDP <= 0;
1136
                        rResetDp <= 0;
1137
                        rClearOutAddress <= 0;
1138
                        rCoreSelect <= 4'b0010;
1139
                        rRenderEnable <= 0;
1140
                        rPrepateWriteAddressForNextCore <= 0;
1141
 
1142
                        if ( ACK_I )
1143
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE1_PHASE2;
1144
                        else
1145
                                WBMNextState <= `WBM_CONFIGURE_CORE1_PHASE2;
1146
                end
1147
                //----------------------------------------
1148
                `WBM_ACK_CONFIGURE_CORE1_PHASE2:
1149
                begin
1150
                        WE_O <=  1;
1151
                        CYC_O <= 1;
1152
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
1153
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
1154
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
1155
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
1156
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
1157
                        MST_O   <= 1;
1158
                        IncDP <= 0;
1159
                        rResetDp <= 0;
1160
                        rClearOutAddress <= 0;
1161
                        rCoreSelect <= 4'b0010;
1162
                        rRenderEnable <= 0;
1163
                        rPrepateWriteAddressForNextCore <= 0;
1164
 
1165
                        if (ACK_I == 0)
1166
                                WBMNextState <= `WBM_CONFIGURE_CORE1_PHASE3;
1167
                        else
1168
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE1_PHASE2;
1169
                end
1170
//----------------------------------------
1171
                `WBM_CONFIGURE_CORE1_PHASE3:
1172
                begin
1173
                        WE_O <=  1;                                                                                                     //Indicate write cycle
1174
                        CYC_O <= 1;                                                                                                     //Start of the cycle
1175
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
1176
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                                        //TAG Address: 01 means instruction address type.
1177
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
1178
                //      IncIP <= 0;
1179
                        IncIA <= 0;
1180
                        MST_O   <= 1;
1181
                        IncDP <= 0;
1182
                        rResetDp <= 0;
1183
                        rClearOutAddress <= 0;
1184
                        rCoreSelect <= 4'b0010;
1185
                        rRenderEnable <= 0;
1186
                        rPrepateWriteAddressForNextCore <= 0;
1187
 
1188
                        if ( ACK_I )
1189
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE1_PHASE3;
1190
                        else
1191
                                WBMNextState <= `WBM_CONFIGURE_CORE1_PHASE3;
1192
                end
1193
                //----------------------------------------
1194
                `WBM_ACK_CONFIGURE_CORE1_PHASE3:
1195
                begin
1196
                        WE_O <=  1;
1197
                        CYC_O <= 1;
1198
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
1199
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
1200
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
1201
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
1202
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
1203
                        MST_O   <= 1;
1204
                        IncDP <= 0;
1205
                        rResetDp <= 0;
1206
                        rClearOutAddress <= 0;
1207
                        rCoreSelect <= 4'b0010;
1208
                        rRenderEnable <= 0;
1209
                        rPrepateWriteAddressForNextCore <= 0;
1210
 
1211
                        if (ACK_I == 0)
1212
                                WBMNextState <= `WBM_END_CORE1_WRITE_CYCLE;
1213
                        else
1214
                                WBMNextState <= `WBM_ACK_CONFIGURE_CORE1_PHASE3;
1215
                end
1216
 
1217
 
1218 13 diegovalve
                //----------------------------------------
1219 77 diegovalve
                `WBM_END_CORE1_WRITE_CYCLE:
1220
                begin
1221
                        WE_O <=  0;
1222
                        CYC_O <= 0;      //*                                                                                             
1223
                        TGC_O <= 0;
1224
                        TGA_O <= 0;
1225
                        STB_O <= 0;
1226
                        IncIA <= 1;//*          
1227
                        MST_O   <= 1;
1228
                        IncDP <= 0;
1229
                        rResetDp <= 0;
1230
                        rClearOutAddress <= 0;
1231
                        rCoreSelect <= 4'b0010;
1232
                        rRenderEnable <= 0;
1233
 
1234
 
1235
                        if (rDataPointer > 3*10)
1236
                        begin
1237
                                rPrepateWriteAddressForNextCore <= 1;
1238
                                WBMNextState    <= `WBM_DONE;
1239
                        end
1240
                        else
1241
                        begin
1242
                                rPrepateWriteAddressForNextCore <= 0;
1243
                                WBMNextState <= `WBM_CONFIGURE_CORE1_PHASE1;
1244
                        end
1245
 
1246
                end
1247
 
1248
                //----------------------------------------      
1249 61 diegovalve
 
1250
                //Here everything is ready so just start!
1251
 
1252 13 diegovalve
                `WBM_DONE:
1253
                begin
1254
                        WE_O <=  0;
1255
                        CYC_O <= 0;
1256
                        TGC_O <= 0;
1257
                        TGA_O <= 0;
1258
                        STB_O <= 0;
1259
                        IncIA <= 0;
1260
                        MST_O   <= 0;
1261
                        IncDP <= 0;
1262
                        rResetDp <= 1;
1263 77 diegovalve
                        rClearOutAddress <= 1;
1264
                        rCoreSelect <= 4'b0010;
1265
                        rRenderEnable <= 4'b0011;
1266
                        rPrepateWriteAddressForNextCore <= 0;
1267 13 diegovalve
 
1268
                        WBMNextState <= `WBM_DONE;
1269
                end
1270
                //----------------------------------------
1271
 
1272
 
1273
                endcase
1274
        end     //end always
1275
        //----------------------------------------------------------    
1276
 
1277
 
1278
 
1279
 
1280
 
1281
endmodule
1282
 

powered by: WebSVN 2.1.0

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