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 61

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
 
66
module TestBench_Theia;
67
 
68
 
69
        //------------------------------------------------------------------------
70
        //**WARNING: Declare all of your varaibles at the begining
71
        //of the file. I hve noticed that sometimes the verilog
72
        //simulator allows you to use some regs even if they have not been 
73
        //previously declared, leadeing to crahses or unexpected behavior
74
        // Inputs
75
        reg Clock;
76
        reg Reset;
77
        reg ExternalBus_DataReady;
78
 
79
        // Outputs
80
        wire ExternalBus_Acknowledge;
81
        wire TaskCompleted;
82
 
83
        //CTE state machin logic
84
 
85
        reg[31:0] CurrentState,NextState;
86
        reg[3:0]  LightCount;
87
        reg[31:0] rLaneA,rLaneB,rLaneC,rLaneD;
88
        reg[16:0] CurrentTaskId;
89
        reg[31:0] CurrentPixelRow, CurrentPixelCol,CurrentRayType;
90
 
91
        reg CTE_WriteEnable;
92
        wire [`WB_WIDTH-1:0] DAT_O;
93
 
94
        reg                                             ACK_O;
95
        wire                                            ACK_I;
96
        wire [`WB_WIDTH-1:0] ADR_I,ADR_O;
97
        wire                                            WE_I,STB_I,CYC_I;
98
        reg CYC_O,WE_O,TGC_O,STB_O;
99
        wire [1:0] TGC_I;
100
        reg [1:0] TGA_O;
101
        wire [1:0] TGA_I;
102
        wire [31:0] DAT_I;
103
        integer ucode_file;
104
 
105
 
106
        reg [31:0] rInitialCol,rInitialRow;
107
        reg [31:0]       rControlRegister[2:0];
108
 
109
 
110
        integer file, log, r, a, b;
111
 
112
 
113
        reg [31:0]  rSceneParameters[31:0];
114
        reg [31:0]       rVertexBuffer[6000:0];
115 61 diegovalve
        reg [31:0]       rInstructionBuffer[512:0];
116 13 diegovalve
        `define TEXTURE_BUFFER_SIZE (256*256*3)
117
        reg [31:0]  rTextures[`TEXTURE_BUFFER_SIZE:0];            //Lets asume we use 256*256 textures
118
 
119
        //------------------------------------------------------------------------
120
        //Debug registers
121
        `define TASK_TIMEOUTMAX 50000
122
 
123
 
124
 
125
        //------------------------------------------------------------------------
126
 
127
 
128
 
129
                reg MST_O;
130
//---------------------------------------------------------------       
131
        THEIACORE THEIA
132
                (
133
                .CLK_I( Clock ),
134
                .RST_I( Reset ),
135
                .DAT_I( DAT_O ),
136
                .ADR_O( ADR_I ),
137
                .ACK_I( ACK_O ),
138
                .WE_O ( WE_I ),
139
                .STB_O( STB_I ),
140
                .CYC_O( CYC_I ),
141
                .CYC_I( CYC_O ),
142
                .TGC_O( TGC_I ),
143
                .MST_I( MST_O ),
144
                .TGA_I( TGA_O ),
145
                .ACK_O( ACK_I ),
146
                .ADR_I( ADR_O ),
147
                .DAT_O( DAT_I ),
148
                .WE_I(  WE_O  ),
149
 
150
                .STB_I( STB_O ),
151
                .TGA_O(TGA_I),
152
 
153
 
154
 
155
 
156
                //Control register
157
                .CREG_I( rControlRegister[0][15:0] )
158
                //Other stuff
159
 
160
 
161
 
162
 
163
 
164
 
165
        );
166
        //&
167
//---------------------------------------------------------------               
168
 
169
 
170
        //---------------------------------------------
171
        //generate the clock signal here
172
        always begin
173 61 diegovalve
                #`CLOCK_CYCLE  Clock =  ! Clock;
174 13 diegovalve
 
175
        end
176
        //---------------------------------------------
177
 
178
reg [15:0] rTimeOut;
179
 
180
                `define MAX_INSTRUCTIONS 2
181
 
182
        initial begin
183
                // Initialize Inputs
184
 
185
 
186
                Clock                                   = 0;
187
                Reset                                   = 0;
188
                CTE_WriteEnable                 = 0;
189
                rLaneA                                  = 32'b0;
190
                rLaneB                                  = 32'b0;
191
                rLaneC                                  = 32'b0;
192
                rLaneD                                  = 32'b0;
193
                ExternalBus_DataReady = 0;
194
                rTimeOut              = 0;
195
 
196
 
197
        `ifdef DUMP_CODE
198
                $display("Opening dump file....\n");
199
                ucode_file = $fopen("TestBench.log","w");
200
        `endif
201
 
202
                //Read Config register values
203
                $readmemh("Creg.mem",rControlRegister);
204
 
205
                rInitialRow = rControlRegister[1];
206
                rInitialCol = rControlRegister[2];
207
        //  rControlRegister[0] = 32'b0;
208
 
209
                //Read configuration Data
210
                $readmemh("Params.mem", rSceneParameters        );
211
                //Read Scene Data
212
                $readmemh("Vertex.mem",rVertexBuffer);
213
                //Read Texture Data
214
                $readmemh("Textures.mem",rTextures);
215
                //Read instruction data
216
                $readmemh("Instructions.mem",rInstructionBuffer);
217
 
218
                $display("Control Register: %b",rControlRegister[0]);
219
 
220
 
221
 
222
                $display("Initial Row: %h",rInitialRow);
223
                $display("Initial Column: %h",rInitialCol);
224
 
225
                `LOGME"AABB min %h %h %h\n",rVertexBuffer[0],rVertexBuffer[1],rVertexBuffer[2]);
226
                `LOGME"AABB max %h %h %h\n",rVertexBuffer[3],rVertexBuffer[4],rVertexBuffer[5]);
227
                `LOGME"%h %h %h\n",rVertexBuffer[6],rVertexBuffer[7],rVertexBuffer[8]);
228
                `LOGME"%h %h %h\n",rVertexBuffer[9],rVertexBuffer[10],rVertexBuffer[11]);
229
                `LOGME"%h %h %h\n",rVertexBuffer[12],rVertexBuffer[13],rVertexBuffer[14]);
230
                `LOGME"%h %h %h\n",rVertexBuffer[15],rVertexBuffer[16],rVertexBuffer[17]);
231
                `LOGME"%h %h %h\n",rVertexBuffer[18],rVertexBuffer[19],rVertexBuffer[20]);
232
                //Open output file
233
                file = $fopen("Output.ppm");
234
                log  = $fopen("Simulation.log");
235
                $fwrite(log, "Simulation start time : %dns\n",$time);
236
                $fwrite(log, "Width : %d\n",`RESOLUTION_WIDTH);
237
                $fwrite(log, "Height : %d\n",`RESOLUTION_HEIGHT);
238
 
239
                $fwrite(file,"P3\n");
240
                $fwrite(file,"#This file was generated by Theia's RTL simulation\n");
241
                $fwrite(file,"%d %d\n",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
242
                $fwrite(file,"255\n");
243
 
244
                `LOGME"Running at %d X %d\n", `RESOLUTION_WIDTH, `RESOLUTION_HEIGHT);
245
 
246
                `LOGME"%h\n",rSceneParameters[0]);
247
                `LOGME"%h\n",rSceneParameters[1]);
248
                `LOGME"%h\n",rSceneParameters[2]);
249
 
250
                `LOGME"%h\n",rSceneParameters[3]);
251
                `LOGME"%h\n",rSceneParameters[4]);
252
                `LOGME"%h\n",rSceneParameters[5]);
253
 
254
                `LOGME"%h\n",rSceneParameters[6]);
255
                `LOGME"%h\n",rSceneParameters[7]);
256
                `LOGME"%h\n",rSceneParameters[8]);
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
                        if ( STB_I == 1 )
339
                                WBSNextState = `WBS_ACK_O;
340
                        else
341
                                WBSNextState = `WBS_MOINTOR_STB_I;
342
                end
343
                //----------------------------------------
344
                `WBS_ACK_O:
345
                begin
346
                        if (WE_I == 0)
347
                        begin
348
 
349
                                rAddress = ADR_I;
350
                                if (TGA_I == 2'b01) //replace this by TGA_I
351
                                begin
352
                                 //Multiply pithc (3), Add 2 because the first 2 bytes are text Width, Height
353
                                rConvertedTextureAddress = {1'b0,rAddress[30:0]} + 2;
354
                                if (rConvertedTextureAddress >= `TEXTURE_BUFFER_SIZE)
355
                                        rConvertedTextureAddress = `TEXTURE_BUFFER_SIZE-1;
356
 
357
 
358
                                        rSlaveData_O = rTextures[  rConvertedTextureAddress ];
359
                                        `ifdef DEBUG
360
 
361
                                        `LOGME"WB SLAVE: MASTER Requested read from texture address: %h (%d)Data = %h \n",rAddress, rConvertedTextureAddress,DAT_O );
362
                                        `endif
363
                                end
364
                                else
365
                                begin
366
                                        Thingy = 0;
367
                                        rSlaveData_O = rVertexBuffer[ rAddress ];
368
                                        `ifdef DEBUG
369
                                        `LOGME"WB SLAVE: MASTER Requested read from vertex address: %h Data = %h\n",rAddress,DAT_O);
370
                                        `endif
371
                                end
372
 
373
                        end
374
                        else
375
                        begin
376
                        //      $display("Theia Writes value: %h @ %h (Time to process pixel %d Clock cycle)",DAT_I,ADR_I,rTimeOut);
377
 
378
 
379
                        if (Thingy == 0)
380
                        begin
381
                                $fwrite(file,"\n# %d %d\n",CurrentPixelRow,CurrentPixelCol);
382
                                $write(".");
383
                        end
384
 
385
                        Thingy = Thingy + 1;
386
                        if (CurrentPixelRow >=  `RESOLUTION_WIDTH)
387
                        begin
388
                                CurrentPixelRow = 0;
389
                                CurrentPixelCol = CurrentPixelCol + 1;
390
                                $display("]- %d (%d)",CurrentPixelCol,ADR_I);
391
                                $write("[");
392
                        end
393
 
394
                        if (Thingy == 3)
395
                        begin
396
                                CurrentPixelRow = CurrentPixelRow + 1;
397
                                Thingy = 0;
398
                        end
399
                                rTimeOut = 0;
400
                                R = ((DAT_I >> (`SCALE-8)) > 255) ? 255 : (DAT_I >>  (`SCALE-8));
401
                                $fwrite(file,"%d " , R );
402
 
403
                        end
404
 
405
 
406
                        ACK_O = 1;
407 61 diegovalve
 
408 13 diegovalve
                        if (CurrentPixelCol >= `RESOLUTION_HEIGHT)
409
                                WBSNextState = `WBS_DONE;
410
                        else
411
                                WBSNextState = `WBS_MOINTOR_STB_I_NEG;
412
                end
413
                //----------------------------------------
414
                `WBS_MOINTOR_STB_I_NEG:
415
                begin
416
                        if ( STB_I == 0 )
417
                        begin
418
                                ACK_O = 0;
419
                                WBSNextState = `WBS_MOINTOR_STB_I;
420
                        end
421
                        else
422
                                WBSNextState = `WBS_MOINTOR_STB_I_NEG;
423
                end
424
                //----------------------------------------
425
                `WBS_DONE:
426
                begin
427
                $display("RESOLUTION_WIDTH = %d,RESOLUTION_HEIGHT= %d",
428
                `RESOLUTION_WIDTH,`RESOLUTION_HEIGHT);
429
                $display("ADR_I = %d\n",ADR_I);
430
                        `LOGME"RENDER COMPLETE");
431
                        `LOGME"Closing File");
432
                        $fclose(file);
433
                        $fwrite(log, "Simulation end time : %dns\n",$time);
434
                        $fclose(log);
435
                        `LOGME"File Closed");
436
                        $stop();
437
                        $fclose(ucode_file);
438
                end
439
                //----------------------------------------
440
                default:
441
                begin
442 61 diegovalve
                $display("WBS Undefined state");
443 13 diegovalve
                end
444
                endcase
445
        end     //end always
446
        //----------------------------------------------------------    
447
 
448
 
449
 
450
 
451
`define TAG_BLOCK_WRITE_CYCLE    2'b01
452
`define TAG_INSTRUCTION_ADDRESS_TYPE 2'b01
453
`define TAG_DATA_ADDRESS_TYPE        2'b10
454
 
455
`define WBM_AFTER_RESET                                                 0
456
`define WBM_WRITE_INSTRUCTION_PHASE1            1
457
`define WBM_ACK_INSTRUCTION_PHASE1                      2
458
`define WBM_WRITE_INSTRUCTION_PHASE2            3
459
`define WBM_ACK_INSTRUCTION_PHASE2                      4
460
`define WBM_END_INSTRUCTION_WRITE_CYCLE   5
461
`define WBM_SEND_DATA_PHASE1                          6
462
`define WBM_ACK_DATA_PHASE1                           7
463
`define WBM_SEND_DATA_PHASE2                          8
464
`define WBM_ACK_DATA_PHASE2                           9
465
`define WBM_SEND_DATA_PHASE3                          10
466
`define WBM_ACK_DATA_PHASE3                           11
467
`define WBM_END_DATA_WRITE_CYCLE          12
468
`define WBM_DONE                          13
469
 
470
reg[31:0] rInstructionPointer;
471
reg[31:0] rAddressToSend;
472
reg[31:0] rDataAddress;
473
reg[31:0] rDataPointer;
474
 
475
reg IncIP,IncIA,IncDP;
476
reg rClearOutAddress;
477
//-----------------------------------------------------
478
always @ (posedge Clock or posedge rClearOutAddress)
479
begin
480
 
481
        if ( IncIA && ~rClearOutAddress)
482
                rAddressToSend = rAddressToSend + 1;
483
        else if (rClearOutAddress)
484
        begin
485
                if (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE)
486
                        rAddressToSend =  {16'd1,16'd0};
487
                else
488
                        rAddressToSend = 0;
489
        end
490
 
491
 
492
end
493
//-----------------------------------------------------
494
always @ (posedge ACK_I or posedge Reset )
495
begin
496
 
497
        if ( ACK_I && ~Reset)
498
                rInstructionPointer = rInstructionPointer + 1;
499
        else if (Reset)
500
                rInstructionPointer = 0;
501
 
502
 
503
 
504
end
505
//-----------------------------------------------------
506
reg rResetDp;
507
 
508
always @ (posedge Clock or posedge rResetDp )
509
begin
510
 
511
        if ( ACK_I && ~rResetDp)//IncDP && ~Reset)
512
                rDataPointer = rDataPointer + 1;
513
        else if (rResetDp)
514
                rDataPointer =  32'b0;
515
 
516
 
517
end
518
//-----------------------------------------------------
519
 
520
 
521
 
522
 
523
assign DAT_O = ( MST_O == 1'b1 ) ? wMasteData_O : rSlaveData_O;
524
 
525
wire[31:0] wMasteData_O;
526
 
527 61 diegovalve
 
528
 
529
assign wMasteData_O = (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE) ? rInstructionBuffer[rInstructionPointer+1] : rSceneParameters[ rDataPointer  ];
530
 
531
 
532
always @ (posedge STB_O)
533
begin
534
        if (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE)
535
        begin
536
                $display("-- %x\n",wMasteData_O);
537
        end
538
end
539 13 diegovalve
assign ADR_O = rAddressToSend;
540
 
541
        reg [7:0]                        WBMCurrentState,WBMNextState;
542
        reg [31:0]                       rWriteAddress;
543
 
544
        always @(posedge Clock or posedge Reset)
545
        begin
546
        if( Reset!=1 )
547
           WBMCurrentState = WBMNextState;
548
                  else
549
                          WBMCurrentState = `WBM_AFTER_RESET;
550
        end
551
 
552
                wire[31:0] wConfigurationPacketSize;
553
                assign wConfigurationPacketSize = rSceneParameters[2];
554
 
555
   reg [31:0]  InstructionIndex;
556
        reg [31:0]  InstructionWriteAddress;
557
        //Send the instructions now...
558
        //----------------------------------------------------------    
559
        always @(posedge Clock)
560
        begin
561
                case (WBMCurrentState)
562
                //----------------------------------------
563 61 diegovalve
 
564
                //Wait until the reset secuence is complete to
565
                //begin sending stuff.
566
 
567 13 diegovalve
                `WBM_AFTER_RESET:
568
                begin
569
                        WE_O <=  0;
570
                        CYC_O <= 0;
571
                        TGC_O <= 0;
572
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
573
                        STB_O <= 0;
574
                //      IncIP <= 0;
575
                        IncIA <= 0;
576
                        MST_O   <= 0;
577
                        IncDP <= 0;
578
                        rResetDp <= 1;
579
                        rClearOutAddress <= 1;
580
 
581
                        if (Reset == 0)
582
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
583
                        else
584
                                WBMNextState <= `WBM_AFTER_RESET;
585
                end
586
                //----------------------------------------
587 61 diegovalve
 
588
                //CLOCK EDGE 0: MASTER presents a valid address on [ADR_O()]
589
                //MASTER presents valid data on [DAT_O()]
590
                //MASTER asserts [WE_O] to indicate a WRITE cycle.
591
                //MASTER asserts [CYC_O] and [TGC_O()] to indicate the start of the cycle.
592
                //MASTER asserts [STB_O] to indicate the start of the phase.
593
 
594 13 diegovalve
                `WBM_WRITE_INSTRUCTION_PHASE1:
595
                begin
596
                        WE_O <=  1;                                                                                                     //Indicate write cycle
597
                        CYC_O <= 1;                                                                                                     //Start of the cycle
598
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
599
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;                 //TAG Address: 01 means instruction address type.
600
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
601
                //      IncIP <= 0;
602
                        IncIA <= 0;
603
                        MST_O   <= 1;
604
                        IncDP <= 0;
605
                        rResetDp <= 1;
606
                        rClearOutAddress <= 0;
607
 
608
 
609
 
610
                        if ( ACK_I )
611
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE1;
612
                        else
613
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
614
 
615
                end
616
                //----------------------------------------
617
                `WBM_ACK_INSTRUCTION_PHASE1:
618
                begin
619
                        WE_O <=  1;
620
                        CYC_O <= 1;
621
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
622
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
623
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
624
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
625
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
626
                        MST_O   <= 1;
627
                        IncDP <= 0;
628
                        rResetDp <= 1;
629
                        rClearOutAddress <= 0;
630
 
631
                        if (ACK_I == 0)
632
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE2;
633
                        else
634
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE1;
635
                end
636
                //----------------------------------------
637
                `WBM_WRITE_INSTRUCTION_PHASE2:
638
                begin
639
                        WE_O <=  1;
640
                        CYC_O <= 1;
641
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
642
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
643
                        STB_O <= ~ACK_I;
644
                //      IncIP <= 0;
645
                        IncIA <= 0;
646
                        MST_O   <= 1;
647
                        IncDP <= 0;
648
                        rResetDp <= 1;
649
                        rClearOutAddress <= 0;
650
 
651
 
652
                        if ( ACK_I )
653
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE2;
654
                        else
655
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE2;
656
 
657
                end
658
                //----------------------------------------
659
                `WBM_ACK_INSTRUCTION_PHASE2:
660
                begin
661
                        WE_O <=  1;
662
                        CYC_O <= 0;
663
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
664
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
665
                        STB_O <= 0;      //*
666
 
667
                        MST_O   <= 1;
668
                        IncDP <= 0;
669
                        rResetDp <= 1;
670
 
671
 
672
 
673 61 diegovalve
                if (rInstructionPointer >= rInstructionBuffer[0])
674 13 diegovalve
                begin
675
                                IncIA <= 0;//*   
676
                                rClearOutAddress <= 1;
677
                                WBMNextState    <= `WBM_SEND_DATA_PHASE1;
678
                end
679
                else
680
                begin
681
                                IncIA <= 1;//*  
682
                                rClearOutAddress <= 0;
683
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
684
                end
685
 
686
                end
687
        //****************************************
688
        `WBM_SEND_DATA_PHASE1:
689
                begin
690
                        WE_O <=  1;                                                                                                     //Indicate write cycle
691
                        CYC_O <= 1;                                                                                                     //Start of the cycle
692
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
693
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                //TAG Address: 01 means instruction address type.
694
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
695
                //      IncIP <= 0;
696
                        IncIA <= 0;
697
                        MST_O   <= 1;
698
                        IncDP <= 0;
699
                        rResetDp <= 0;
700
                        rClearOutAddress <= 0;
701
 
702
 
703
 
704
                        if ( ACK_I )
705
                                WBMNextState <= `WBM_ACK_DATA_PHASE1;
706
                        else
707
                                WBMNextState <= `WBM_SEND_DATA_PHASE1;
708
 
709
                end
710
                //----------------------------------------
711
                `WBM_ACK_DATA_PHASE1:
712
                begin
713
                        WE_O <=  1;
714
                        CYC_O <= 1;
715
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
716
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
717
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
718
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
719
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
720
                        MST_O   <= 1;
721
                        IncDP <= 0;
722
                        rResetDp <= 0;
723
                        rClearOutAddress <= 0;
724
 
725
                        if (ACK_I == 0)
726
                                WBMNextState <= `WBM_SEND_DATA_PHASE2;
727
                        else
728
                                WBMNextState <= `WBM_ACK_DATA_PHASE1;
729
                end
730
                //----------------------------------------
731
                `WBM_SEND_DATA_PHASE2:
732
                begin
733
                        WE_O <=  1;
734
                        CYC_O <= 1;
735
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
736
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
737
                        STB_O <= ~ACK_I;
738
                //      IncIP <= 0;
739
                        IncIA <= 0;
740
                        MST_O   <= 1;
741
                        IncDP <= 0;
742
                        rResetDp <= 0;
743
                        rClearOutAddress <= 0;
744
 
745
 
746
                        if ( ACK_I )
747
                                WBMNextState <= `WBM_ACK_DATA_PHASE2;
748
                        else
749
                                WBMNextState <= `WBM_SEND_DATA_PHASE2;
750
 
751
                end
752
                //----------------------------------------
753
                `WBM_ACK_DATA_PHASE2:
754
                begin
755
                        WE_O <=  1;
756
                        CYC_O <= 1;
757
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
758
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
759
                        STB_O <= 0;      //*
760
                        IncIA <= 0;
761
                        MST_O   <= 1;
762
                        IncDP <= 0;//*           
763
                        rResetDp <= 0;
764
                        rClearOutAddress <= 0;
765
 
766
                        if (ACK_I == 0)
767
                                WBMNextState <= `WBM_SEND_DATA_PHASE3;
768
                        else
769
                                WBMNextState <= `WBM_ACK_DATA_PHASE2;
770
 
771
                end
772
                //----------------------------------------
773
                `WBM_SEND_DATA_PHASE3:
774
                begin
775
                        WE_O <=  1;
776
                        CYC_O <= 1;
777
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
778
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
779
                        STB_O <= ~ACK_I;
780
                //      IncIP <= 0;
781
                        IncIA <= 0;
782
                        MST_O   <= 1;
783
                        IncDP <= 0;
784
                        rResetDp <= 0;
785
                        rClearOutAddress <= 0;
786
 
787
 
788
                        if ( ACK_I )
789
                                WBMNextState <= `WBM_ACK_DATA_PHASE3;
790
                        else
791
                                WBMNextState <= `WBM_SEND_DATA_PHASE3;
792
 
793
                end
794
                //----------------------------------------
795
                `WBM_ACK_DATA_PHASE3:
796
                begin
797
                        WE_O <=  1;
798
                        CYC_O <= 1;
799
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
800
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
801
                        STB_O <= 0;      //*
802
                        IncIA <= 0;
803
                        MST_O   <= 1;
804
                        IncDP <= 1;//*          
805
                        rResetDp <= 0;
806
                        rClearOutAddress <= 0;
807
 
808
                        WBMNextState <= `WBM_END_DATA_WRITE_CYCLE;
809
 
810
                end
811
                //----------------------------------------
812
                `WBM_END_DATA_WRITE_CYCLE:
813
                begin
814
                        WE_O <=  0;
815
                        CYC_O <= 0;      //*                                                                                             
816
                        TGC_O <= 0;
817
                        TGA_O <= 0;
818
                        STB_O <= 0;
819
                        IncIA <= 1;//*          
820
                        MST_O   <= 1;
821
                        IncDP <= 0;
822
                        rResetDp <= 0;
823
                        rClearOutAddress <= 0;
824
 
825
                        $display("rDataPointer = %d\n",rDataPointer);
826
                        if (rDataPointer > wConfigurationPacketSize*3)
827
                                WBMNextState    <= `WBM_DONE;
828
                        else
829
                                WBMNextState <= `WBM_SEND_DATA_PHASE1;
830
 
831
                end
832
 
833
                //----------------------------------------
834 61 diegovalve
 
835
                //Here everything is ready so just start!
836
 
837 13 diegovalve
                `WBM_DONE:
838
                begin
839
                        WE_O <=  0;
840
                        CYC_O <= 0;
841
                        TGC_O <= 0;
842
                        TGA_O <= 0;
843
                        STB_O <= 0;
844
                        IncIA <= 0;
845
                        MST_O   <= 0;
846
                        IncDP <= 0;
847
                        rResetDp <= 1;
848
                        rClearOutAddress <= 1;
849
 
850
                        WBMNextState <= `WBM_DONE;
851
                end
852
                //----------------------------------------
853
 
854
 
855
                endcase
856
        end     //end always
857
        //----------------------------------------------------------    
858
 
859
 
860
 
861
 
862
 
863
endmodule
864
 

powered by: WebSVN 2.1.0

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