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 75

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 69 diegovalve
        `define TASK_TIMEOUTMAX 150000//50000
122 13 diegovalve
 
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 69 diegovalve
                $write("Opening TestBench.log.... ");
199 13 diegovalve
                ucode_file = $fopen("TestBench.log","w");
200 69 diegovalve
                $display("Done");
201 13 diegovalve
        `endif
202
 
203
                //Read Config register values
204 69 diegovalve
                $write("Loading control register.... ");
205 13 diegovalve
                $readmemh("Creg.mem",rControlRegister);
206 69 diegovalve
                $display("Done");
207 13 diegovalve
 
208
 
209 69 diegovalve
 
210 13 diegovalve
                //Read configuration Data
211 69 diegovalve
                $write("Loading scene parameters.... ");
212 13 diegovalve
                $readmemh("Params.mem", rSceneParameters        );
213 69 diegovalve
                $display("Done");
214
 
215
                rInitialRow = rSceneParameters[18];
216
                rInitialCol = rSceneParameters[19];
217
 
218 13 diegovalve
                //Read Scene Data
219 69 diegovalve
                $write("Loading scene geometry.... ");
220 13 diegovalve
                $readmemh("Vertex.mem",rVertexBuffer);
221 69 diegovalve
                $display("Done");
222
 
223 13 diegovalve
                //Read Texture Data
224 69 diegovalve
                $write("Loading scene texture.... ");
225 13 diegovalve
                $readmemh("Textures.mem",rTextures);
226 69 diegovalve
                $display("Done");
227
 
228
 
229 13 diegovalve
                //Read instruction data
230 69 diegovalve
                $write("Loading code allocation table and user shaders.... ");
231 13 diegovalve
                $readmemh("Instructions.mem",rInstructionBuffer);
232 69 diegovalve
                $display("Done");
233 13 diegovalve
 
234 69 diegovalve
                $display("Control Register : %b",rControlRegister[0]);
235
                $display("Initial Row      : %h",rInitialRow);
236
                $display("Initial Column   : %h",rInitialCol);
237
                $display("Resolution       : %d X %d",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
238
 
239 13 diegovalve
                //Open output file
240
                file = $fopen("Output.ppm");
241
                log  = $fopen("Simulation.log");
242
                $fwrite(log, "Simulation start time : %dns\n",$time);
243
                $fwrite(log, "Width : %d\n",`RESOLUTION_WIDTH);
244
                $fwrite(log, "Height : %d\n",`RESOLUTION_HEIGHT);
245
 
246
                $fwrite(file,"P3\n");
247
                $fwrite(file,"#This file was generated by Theia's RTL simulation\n");
248
                $fwrite(file,"%d %d\n",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
249
                $fwrite(file,"255\n");
250
 
251
                CurrentPixelRow = 0;
252
                CurrentPixelCol = 0;
253
                #10
254
                Reset = 1;
255
                ExternalBus_DataReady = 0;
256
 
257
                // Wait 100 ns for global reset to finish
258
                #100  Reset = 0;
259
 
260
        end
261
 
262
        reg [5:0] DataIndex;
263
        reg [31:0] ConfigurationPacketSize;
264
 
265
        reg [7:0] R,G,B;
266
 
267
 
268
//---------------------------------------------
269
 
270
always @ (posedge Clock)
271
begin
272
        rTimeOut = rTimeOut+1'b1;
273
        if (rTimeOut > `TASK_TIMEOUTMAX)
274
        begin
275
                 $display("%dns ERROR: THEIA Timed out after %d of inactivity\n",
276
                 $time(),rTimeOut);
277
                 $stop();
278
        end
279
end
280
 
281
reg [31:0] rSlaveData_O;
282
//reg [31:0] rOutputFrameBuffer[39000:0];
283
reg [31:0] rColor;
284
 
285
reg [7:0] Thingy;
286
//Wish-Bone Slave logic.
287
//
288
//This logic represents a WBS FSM. It will provide
289
//the memory for Vertex and Texture data.
290
//Vertex/Tetxure data is stored in a 4GB RAM.
291
//Vertex data starts at address 0 and ends at address 0x80_000_000.
292
//Texture data starts at address 0x80_000_000 and ends at address
293
//0xFFFFFFFF.
294
//The Bit 31, indcates wheather we look for vertex (b=0)
295
//or texture (b=1)
296
 
297
`define WBS_AFTER_RESET                                 0
298
`define WBS_MOINTOR_STB_I                               1
299
`define WBS_ACK_O                                                       2
300
`define WBS_MOINTOR_STB_I_NEG                   3
301
`define WBS_DONE                    4
302
 
303
        reg [7:0]                        WBSCurrentState,WBSNextState;
304
        reg [31:0]                       rAddress;
305
 
306
        always @(negedge Clock)
307
        begin
308
        if( Reset!=1 )
309
           WBSCurrentState = WBSNextState;
310
                  else
311
                          WBSCurrentState = `WBS_AFTER_RESET;
312
        end
313
 
314
 
315
 
316
        reg [31:0] rConvertedTextureAddress;
317
        //----------------------------------------------------------    
318
        always @(posedge Clock)
319
        begin
320
                case (WBSCurrentState)
321
                //----------------------------------------
322
                `WBS_AFTER_RESET:
323
                begin
324
                        ACK_O = 0;
325
                        rSlaveData_O = 32'b0;
326
 
327
                        WBSNextState = `WBS_MOINTOR_STB_I;
328
                end
329
                //----------------------------------------
330
                `WBS_MOINTOR_STB_I:
331
                begin
332
                        if ( STB_I == 1 )
333
                                WBSNextState = `WBS_ACK_O;
334
                        else
335
                                WBSNextState = `WBS_MOINTOR_STB_I;
336
                end
337
                //----------------------------------------
338
                `WBS_ACK_O:
339
                begin
340
                        if (WE_I == 0)
341
                        begin
342
 
343
                                rAddress = ADR_I;
344
                                if (TGA_I == 2'b01) //replace this by TGA_I
345
                                begin
346
                                 //Multiply pithc (3), Add 2 because the first 2 bytes are text Width, Height
347
                                rConvertedTextureAddress = {1'b0,rAddress[30:0]} + 2;
348
                                if (rConvertedTextureAddress >= `TEXTURE_BUFFER_SIZE)
349
                                        rConvertedTextureAddress = `TEXTURE_BUFFER_SIZE-1;
350
 
351
 
352
                                        rSlaveData_O = rTextures[  rConvertedTextureAddress ];
353
                                        `ifdef DEBUG
354
 
355
                                        `LOGME"WB SLAVE: MASTER Requested read from texture address: %h (%d)Data = %h \n",rAddress, rConvertedTextureAddress,DAT_O );
356
                                        `endif
357
                                end
358
                                else
359
                                begin
360
                                        Thingy = 0;
361
                                        rSlaveData_O = rVertexBuffer[ rAddress ];
362
                                        `ifdef DEBUG
363
                                        `LOGME"WB SLAVE: MASTER Requested read from vertex address: %h Data = %h\n",rAddress,DAT_O);
364
                                        `endif
365
                                end
366
 
367
                        end
368
                        else
369
                        begin
370
                        //      $display("Theia Writes value: %h @ %h (Time to process pixel %d Clock cycle)",DAT_I,ADR_I,rTimeOut);
371
 
372
 
373
                        if (Thingy == 0)
374
                        begin
375
                                $fwrite(file,"\n# %d %d\n",CurrentPixelRow,CurrentPixelCol);
376
                                $write(".");
377
                        end
378
 
379
                        Thingy = Thingy + 1;
380
                        if (CurrentPixelRow >=  `RESOLUTION_WIDTH)
381
                        begin
382
                                CurrentPixelRow = 0;
383
                                CurrentPixelCol = CurrentPixelCol + 1;
384
                                $display("]- %d (%d)",CurrentPixelCol,ADR_I);
385
                                $write("[");
386
                        end
387
 
388
                        if (Thingy == 3)
389
                        begin
390
                                CurrentPixelRow = CurrentPixelRow + 1;
391
                                Thingy = 0;
392
                        end
393
                                rTimeOut = 0;
394
                                R = ((DAT_I >> (`SCALE-8)) > 255) ? 255 : (DAT_I >>  (`SCALE-8));
395
                                $fwrite(file,"%d " , R );
396
 
397
                        end
398
 
399
 
400
                        ACK_O = 1;
401 61 diegovalve
 
402 13 diegovalve
                        if (CurrentPixelCol >= `RESOLUTION_HEIGHT)
403
                                WBSNextState = `WBS_DONE;
404
                        else
405
                                WBSNextState = `WBS_MOINTOR_STB_I_NEG;
406
                end
407
                //----------------------------------------
408
                `WBS_MOINTOR_STB_I_NEG:
409
                begin
410
                        if ( STB_I == 0 )
411
                        begin
412
                                ACK_O = 0;
413
                                WBSNextState = `WBS_MOINTOR_STB_I;
414
                        end
415
                        else
416
                                WBSNextState = `WBS_MOINTOR_STB_I_NEG;
417
                end
418
                //----------------------------------------
419
                `WBS_DONE:
420
                begin
421
                $display("RESOLUTION_WIDTH = %d,RESOLUTION_HEIGHT= %d",
422
                `RESOLUTION_WIDTH,`RESOLUTION_HEIGHT);
423
                $display("ADR_I = %d\n",ADR_I);
424
                        `LOGME"RENDER COMPLETE");
425
                        `LOGME"Closing File");
426
                        $fclose(file);
427
                        $fwrite(log, "Simulation end time : %dns\n",$time);
428
                        $fclose(log);
429
                        `LOGME"File Closed");
430
                        $stop();
431
                        $fclose(ucode_file);
432
                end
433
                //----------------------------------------
434
                default:
435
                begin
436 61 diegovalve
                $display("WBS Undefined state");
437 13 diegovalve
                end
438
                endcase
439
        end     //end always
440
        //----------------------------------------------------------    
441
 
442
 
443
 
444
 
445
`define TAG_BLOCK_WRITE_CYCLE    2'b01
446
`define TAG_INSTRUCTION_ADDRESS_TYPE 2'b01
447
`define TAG_DATA_ADDRESS_TYPE        2'b10
448
 
449
`define WBM_AFTER_RESET                                                 0
450
`define WBM_WRITE_INSTRUCTION_PHASE1            1
451
`define WBM_ACK_INSTRUCTION_PHASE1                      2
452
`define WBM_WRITE_INSTRUCTION_PHASE2            3
453
`define WBM_ACK_INSTRUCTION_PHASE2                      4
454
`define WBM_END_INSTRUCTION_WRITE_CYCLE   5
455
`define WBM_SEND_DATA_PHASE1                          6
456
`define WBM_ACK_DATA_PHASE1                           7
457
`define WBM_SEND_DATA_PHASE2                          8
458
`define WBM_ACK_DATA_PHASE2                           9
459
`define WBM_SEND_DATA_PHASE3                          10
460
`define WBM_ACK_DATA_PHASE3                           11
461
`define WBM_END_DATA_WRITE_CYCLE          12
462
`define WBM_DONE                          13
463
 
464
reg[31:0] rInstructionPointer;
465
reg[31:0] rAddressToSend;
466
reg[31:0] rDataAddress;
467
reg[31:0] rDataPointer;
468
 
469
reg IncIP,IncIA,IncDP;
470
reg rClearOutAddress;
471
//-----------------------------------------------------
472
always @ (posedge Clock or posedge rClearOutAddress)
473
begin
474
 
475
        if ( IncIA && ~rClearOutAddress)
476
                rAddressToSend = rAddressToSend + 1;
477
        else if (rClearOutAddress)
478
        begin
479
                if (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE)
480
                        rAddressToSend =  {16'd1,16'd0};
481
                else
482
                        rAddressToSend = 0;
483
        end
484
 
485
 
486
end
487
//-----------------------------------------------------
488
always @ (posedge ACK_I or posedge Reset )
489
begin
490
 
491
        if ( ACK_I && ~Reset)
492
                rInstructionPointer = rInstructionPointer + 1;
493
        else if (Reset)
494
                rInstructionPointer = 0;
495
 
496
 
497
 
498
end
499
//-----------------------------------------------------
500
reg rResetDp;
501
 
502
always @ (posedge Clock or posedge rResetDp )
503
begin
504
 
505
        if ( ACK_I && ~rResetDp)//IncDP && ~Reset)
506
                rDataPointer = rDataPointer + 1;
507
        else if (rResetDp)
508
                rDataPointer =  32'b0;
509
 
510
 
511
end
512
//-----------------------------------------------------
513
 
514
 
515
 
516
 
517
assign DAT_O = ( MST_O == 1'b1 ) ? wMasteData_O : rSlaveData_O;
518
 
519
wire[31:0] wMasteData_O;
520
 
521 61 diegovalve
 
522
 
523
assign wMasteData_O = (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE) ? rInstructionBuffer[rInstructionPointer+1] : rSceneParameters[ rDataPointer  ];
524
 
525
 
526
always @ (posedge STB_O)
527
begin
528
        if (TGA_O == `TAG_INSTRUCTION_ADDRESS_TYPE)
529
        begin
530 69 diegovalve
                //$display("-- %x\n",wMasteData_O);
531 61 diegovalve
        end
532
end
533 13 diegovalve
assign ADR_O = rAddressToSend;
534
 
535
        reg [7:0]                        WBMCurrentState,WBMNextState;
536
        reg [31:0]                       rWriteAddress;
537
 
538
        always @(posedge Clock or posedge Reset)
539
        begin
540
        if( Reset!=1 )
541
           WBMCurrentState = WBMNextState;
542
                  else
543
                          WBMCurrentState = `WBM_AFTER_RESET;
544
        end
545
 
546
                wire[31:0] wConfigurationPacketSize;
547
                assign wConfigurationPacketSize = rSceneParameters[2];
548
 
549
   reg [31:0]  InstructionIndex;
550
        reg [31:0]  InstructionWriteAddress;
551
        //Send the instructions now...
552
        //----------------------------------------------------------    
553
        always @(posedge Clock)
554
        begin
555
                case (WBMCurrentState)
556
                //----------------------------------------
557 61 diegovalve
 
558
                //Wait until the reset secuence is complete to
559
                //begin sending stuff.
560
 
561 13 diegovalve
                `WBM_AFTER_RESET:
562
                begin
563
                        WE_O <=  0;
564
                        CYC_O <= 0;
565
                        TGC_O <= 0;
566
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
567
                        STB_O <= 0;
568
                //      IncIP <= 0;
569
                        IncIA <= 0;
570
                        MST_O   <= 0;
571
                        IncDP <= 0;
572
                        rResetDp <= 1;
573
                        rClearOutAddress <= 1;
574
 
575
                        if (Reset == 0)
576
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
577
                        else
578
                                WBMNextState <= `WBM_AFTER_RESET;
579
                end
580
                //----------------------------------------
581 61 diegovalve
 
582
                //CLOCK EDGE 0: MASTER presents a valid address on [ADR_O()]
583
                //MASTER presents valid data on [DAT_O()]
584
                //MASTER asserts [WE_O] to indicate a WRITE cycle.
585
                //MASTER asserts [CYC_O] and [TGC_O()] to indicate the start of the cycle.
586
                //MASTER asserts [STB_O] to indicate the start of the phase.
587
 
588 13 diegovalve
                `WBM_WRITE_INSTRUCTION_PHASE1:
589
                begin
590
                        WE_O <=  1;                                                                                                     //Indicate write cycle
591
                        CYC_O <= 1;                                                                                                     //Start of the cycle
592
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
593
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;                 //TAG Address: 01 means instruction address type.
594
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
595
                //      IncIP <= 0;
596
                        IncIA <= 0;
597
                        MST_O   <= 1;
598
                        IncDP <= 0;
599
                        rResetDp <= 1;
600
                        rClearOutAddress <= 0;
601
 
602
 
603
 
604
                        if ( ACK_I )
605
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE1;
606
                        else
607
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
608
 
609
                end
610
                //----------------------------------------
611
                `WBM_ACK_INSTRUCTION_PHASE1:
612
                begin
613
                        WE_O <=  1;
614
                        CYC_O <= 1;
615
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
616
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
617
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
618
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
619
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
620
                        MST_O   <= 1;
621
                        IncDP <= 0;
622
                        rResetDp <= 1;
623
                        rClearOutAddress <= 0;
624
 
625
                        if (ACK_I == 0)
626
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE2;
627
                        else
628
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE1;
629
                end
630
                //----------------------------------------
631
                `WBM_WRITE_INSTRUCTION_PHASE2:
632
                begin
633
                        WE_O <=  1;
634
                        CYC_O <= 1;
635
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
636
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
637
                        STB_O <= ~ACK_I;
638
                //      IncIP <= 0;
639
                        IncIA <= 0;
640
                        MST_O   <= 1;
641
                        IncDP <= 0;
642
                        rResetDp <= 1;
643
                        rClearOutAddress <= 0;
644
 
645
 
646
                        if ( ACK_I )
647
                                WBMNextState <= `WBM_ACK_INSTRUCTION_PHASE2;
648
                        else
649
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE2;
650
 
651
                end
652
                //----------------------------------------
653
                `WBM_ACK_INSTRUCTION_PHASE2:
654
                begin
655
                        WE_O <=  1;
656
                        CYC_O <= 0;
657
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
658
                        TGA_O <= `TAG_INSTRUCTION_ADDRESS_TYPE;
659
                        STB_O <= 0;      //*
660
 
661
                        MST_O   <= 1;
662
                        IncDP <= 0;
663
                        rResetDp <= 1;
664
 
665
 
666
 
667 61 diegovalve
                if (rInstructionPointer >= rInstructionBuffer[0])
668 13 diegovalve
                begin
669
                                IncIA <= 0;//*   
670
                                rClearOutAddress <= 1;
671
                                WBMNextState    <= `WBM_SEND_DATA_PHASE1;
672
                end
673
                else
674
                begin
675
                                IncIA <= 1;//*  
676
                                rClearOutAddress <= 0;
677
                                WBMNextState <= `WBM_WRITE_INSTRUCTION_PHASE1;
678
                end
679
 
680
                end
681
        //****************************************
682
        `WBM_SEND_DATA_PHASE1:
683
                begin
684
                        WE_O <=  1;                                                                                                     //Indicate write cycle
685
                        CYC_O <= 1;                                                                                                     //Start of the cycle
686
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;                                                //TAG CYCLE: 10 indicated multiple write Cycle
687
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;                //TAG Address: 01 means instruction address type.
688
                        STB_O <= ~ACK_I;                                                                                        //Start of phase (you put this in zero to introduce wait cycles)
689
                //      IncIP <= 0;
690
                        IncIA <= 0;
691
                        MST_O   <= 1;
692
                        IncDP <= 0;
693
                        rResetDp <= 0;
694
                        rClearOutAddress <= 0;
695
 
696
 
697
 
698
                        if ( ACK_I )
699
                                WBMNextState <= `WBM_ACK_DATA_PHASE1;
700
                        else
701
                                WBMNextState <= `WBM_SEND_DATA_PHASE1;
702
 
703
                end
704
                //----------------------------------------
705
                `WBM_ACK_DATA_PHASE1:
706
                begin
707
                        WE_O <=  1;
708
                        CYC_O <= 1;
709
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
710
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
711
                        STB_O <= 0;      //*                                                                                     //Negate STB_O in response to ACK_I
712
                //      IncIP <= 1;     //*                                                                                     //Increment local inst pointer to send the next 32 bits                                 
713
                        IncIA <= 0;                                                                                                      //leave the instruction write address the same
714
                        MST_O   <= 1;
715
                        IncDP <= 0;
716
                        rResetDp <= 0;
717
                        rClearOutAddress <= 0;
718
 
719
                        if (ACK_I == 0)
720
                                WBMNextState <= `WBM_SEND_DATA_PHASE2;
721
                        else
722
                                WBMNextState <= `WBM_ACK_DATA_PHASE1;
723
                end
724
                //----------------------------------------
725
                `WBM_SEND_DATA_PHASE2:
726
                begin
727
                        WE_O <=  1;
728
                        CYC_O <= 1;
729
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
730
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
731
                        STB_O <= ~ACK_I;
732
                //      IncIP <= 0;
733
                        IncIA <= 0;
734
                        MST_O   <= 1;
735
                        IncDP <= 0;
736
                        rResetDp <= 0;
737
                        rClearOutAddress <= 0;
738
 
739
 
740
                        if ( ACK_I )
741
                                WBMNextState <= `WBM_ACK_DATA_PHASE2;
742
                        else
743
                                WBMNextState <= `WBM_SEND_DATA_PHASE2;
744
 
745
                end
746
                //----------------------------------------
747
                `WBM_ACK_DATA_PHASE2:
748
                begin
749
                        WE_O <=  1;
750
                        CYC_O <= 1;
751
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
752
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
753
                        STB_O <= 0;      //*
754
                        IncIA <= 0;
755
                        MST_O   <= 1;
756
                        IncDP <= 0;//*           
757
                        rResetDp <= 0;
758
                        rClearOutAddress <= 0;
759
 
760
                        if (ACK_I == 0)
761
                                WBMNextState <= `WBM_SEND_DATA_PHASE3;
762
                        else
763
                                WBMNextState <= `WBM_ACK_DATA_PHASE2;
764
 
765
                end
766
                //----------------------------------------
767
                `WBM_SEND_DATA_PHASE3:
768
                begin
769
                        WE_O <=  1;
770
                        CYC_O <= 1;
771
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
772
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
773
                        STB_O <= ~ACK_I;
774
                //      IncIP <= 0;
775
                        IncIA <= 0;
776
                        MST_O   <= 1;
777
                        IncDP <= 0;
778
                        rResetDp <= 0;
779
                        rClearOutAddress <= 0;
780
 
781
 
782
                        if ( ACK_I )
783
                                WBMNextState <= `WBM_ACK_DATA_PHASE3;
784
                        else
785
                                WBMNextState <= `WBM_SEND_DATA_PHASE3;
786
 
787
                end
788
                //----------------------------------------
789
                `WBM_ACK_DATA_PHASE3:
790
                begin
791
                        WE_O <=  1;
792
                        CYC_O <= 1;
793
                        TGC_O <= `TAG_BLOCK_WRITE_CYCLE;
794
                        TGA_O <= `TAG_DATA_ADDRESS_TYPE;
795
                        STB_O <= 0;      //*
796
                        IncIA <= 0;
797
                        MST_O   <= 1;
798
                        IncDP <= 1;//*          
799
                        rResetDp <= 0;
800
                        rClearOutAddress <= 0;
801
 
802
                        WBMNextState <= `WBM_END_DATA_WRITE_CYCLE;
803
 
804
                end
805
                //----------------------------------------
806
                `WBM_END_DATA_WRITE_CYCLE:
807
                begin
808
                        WE_O <=  0;
809
                        CYC_O <= 0;      //*                                                                                             
810
                        TGC_O <= 0;
811
                        TGA_O <= 0;
812
                        STB_O <= 0;
813
                        IncIA <= 1;//*          
814
                        MST_O   <= 1;
815
                        IncDP <= 0;
816
                        rResetDp <= 0;
817
                        rClearOutAddress <= 0;
818
 
819 69 diegovalve
 
820 13 diegovalve
                        if (rDataPointer > wConfigurationPacketSize*3)
821
                                WBMNextState    <= `WBM_DONE;
822
                        else
823
                                WBMNextState <= `WBM_SEND_DATA_PHASE1;
824
 
825
                end
826
 
827
                //----------------------------------------
828 61 diegovalve
 
829
                //Here everything is ready so just start!
830
 
831 13 diegovalve
                `WBM_DONE:
832
                begin
833
                        WE_O <=  0;
834
                        CYC_O <= 0;
835
                        TGC_O <= 0;
836
                        TGA_O <= 0;
837
                        STB_O <= 0;
838
                        IncIA <= 0;
839
                        MST_O   <= 0;
840
                        IncDP <= 0;
841
                        rResetDp <= 1;
842
                        rClearOutAddress <= 1;
843
 
844
                        WBMNextState <= `WBM_DONE;
845
                end
846
                //----------------------------------------
847
 
848
 
849
                endcase
850
        end     //end always
851
        //----------------------------------------------------------    
852
 
853
 
854
 
855
 
856
 
857
endmodule
858
 

powered by: WebSVN 2.1.0

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