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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_1.1/] [rtl/] [CONTROL/] [Unit_Control.v] - Blame information for rev 112

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

Line No. Rev Author Line
1 18 diegovalve
/**********************************************************************************
2
Theia, Ray Cast Programable graphic Processing Unit.
3
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
4
 
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
9
 
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
 
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 
19
***********************************************************************************/
20
/**********************************************************************************
21
Description:
22
 
23
This is the main Finite State Machine.
24
 
25
**********************************************************************************/
26
 
27
`timescale 1ns / 1ps
28
`include "aDefinitions.v"
29
 
30
`define CU_AFTER_RESET_STATE 0
31
`define CU_WAIT_FOR_INITIAL_CONFIGURATION 1
32
`define CU_TRIGGER_CONFIGURATION_DATA_READ 2
33
`define CU_WAIT_FOR_CONFIG_DATA_READ    3
34
`define CU_ACK_CONFIG_DATA_READ 4
35
`define CU_PRECALCULATE_CONSTANTS 5
36
`define CU_WAIT_FOR_CONSTANT 6
37
`define CU_ACK_PRECALCULATE_CONSTANTS 7
38
`define CU_WAIT_FOR_TASK 8
39
`define CU_READ_TASK_DATA 9
40
`define CU_WAIT_TASK_DATA_READ 10
41
`define CU_ACK_TASK_DATA_READ 11
42
`define CU_TRIGGER_RGU 12
43
`define CU_WAIT_FOR_RGU 13
44
`define CU_ACK_RGU 14
45
`define CU_TRIGGER_GEO 15
46
`define CU_WAIT_FOR_GEO_SYNC 16
47
//`define CU_CHECK_AABBIU_REQUEST 17
48
`define CU_TRIGGER_TCC 17
49
//`define CU_CHECK_BIU_REQUEST 18
50
`define CU_TRIGGER_TFF 18
51
//`define CU_CHECK_GEO_DONE 19
52
`define CU_WAIT_FOR_TFF 19
53
`define CU_TRIGGER_AABBIU 20
54
`define CU_WAIT_FOR_AABBIU 21
55
`define CU_TRIGGER_BIU 22
56
`define CU_WAIT_FOR_BIU 23
57
`define CU_ACK_UCODE 24
58
`define CU_TRIGGER_PSU 25
59
`define CU_WAIT_FOR_PSU 26
60
`define CU_ACK_PSU 27
61
`define CU_TRIGGER_PCU 28
62
`define CU_WAIT_FOR_PCU 29
63
`define CU_ACK_PCU 30
64
`define CU_CHECK_HIT 31
65
`define CU_CLEAR_REGISTERS 32
66
`define CU_WAIT_CLEAR_REGISTERS 33
67
`define CU_ACK_CLEAR_REGISTERS  34
68
`define CU_TRIGGER_PSU_WITH_TEXTURE 35
69
`define WAIT_FOR_TCC 36
70
`define CU_TRIGGER_NPU 37
71
`define CU_WAIT_NPU 38
72
`define CU_ACK_NPU 39
73
`define CU_PERFORM_INTIAL_CONFIGURATION 40
74
`define CU_SET_PICTH 41
75
 
76
//--------------------------------------------------------------
77
module ControlUnit
78
(
79
 
80
input  wire                                  Clock,
81
input  wire                                  Reset,
82
input  wire[15:0]                            iControlRegister,
83
input  wire                                  iExternalBus_DataReady,
84
input    wire                                  iBusUnitDone,
85
output reg                                   oGFUEnable,
86
input    wire                                  iTriggerAABBIURequest,
87
input   wire                                   iTriggerBIURequest,
88
input wire                                   iTriggertTCCRequest,
89
output reg                                   oUCodeEnable,
90
output reg[`ROM_ADDRESS_WIDTH-1:0]           oUCodeInstructioPointer,
91
input   wire                                   iUCodeDone,
92
input wire                                   iUCodeReturnValue,
93
input wire                                   iGFUDone,
94
input wire                                   iGEOSync,
95
output reg                                   oTriggerTFF,
96
input wire                                   iTFFDone,
97
input wire                                   MST_I,
98
output reg[2:0]                              oRamBusOwner,
99
input wire                                   iIODone,
100
output reg                                   oSetCurrentPitch,
101
//output reg                                   //oIncCurrentPitch,
102
//output wire[`WIDTH-1:0]                      oPitchInitialValue,
103
output reg                                   oIOWritePixel
104
 
105
);
106
 
107
//Internal State Machine varibles
108
reg     [5:0]    CurrentState;
109
reg     [5:0]    NextState;
110
integer ucode_file;
111
reg rResetHitFlop,rHitFlopEnable;
112
wire wHit;
113
 
114
`ifdef DUMP_CODE
115
        integer log;
116
 
117
        initial
118
        begin
119
 
120
        $display("Opening ucode dump file....\n");
121
        ucode_file = $fopen("CU.log","w");
122
        end
123
 
124
`endif
125
 
126
 
127
wire[`ROM_ADDRESS_WIDTH-1:0] wAABBIUAddress;
128
assign wAABBIUAddress = (iControlRegister[`CR_USER_AABBIU] == 1'b1) ? `USER_AABBIU_UCODE_ADDRESS : `AABBIU_UCODE_ADDRESS;
129
 
130
 
131
//--------------------------------------------------------------
132
FFToggleOnce_1Bit FFTO1
133
(
134
        .Clock( Clock ),
135
        .Reset( rResetHitFlop ),
136
        .Enable( rHitFlopEnable && iUCodeDone ),
137
        .S( iUCodeReturnValue ),
138
        .Q( wHit )
139
);
140
//--------------------------------------------------------------
141
 
142
`ifdef DEBUG
143
        always @ ( wHit )
144
        begin
145
                `LOGME "*** Triangle HIT ***\n");
146
        end
147
`endif
148
 
149
//Next states logic and Reset sequence
150
always @(posedge Clock or posedge Reset)
151
  begin
152
 
153
    if (Reset)
154
                CurrentState <= `CU_AFTER_RESET_STATE;
155
    else
156
                CurrentState <= NextState;
157
 
158
  end
159
 
160
//--------------------------------------------------------------
161
always @ ( * )
162
begin
163
        case (CurrentState)
164
        //-----------------------------------------
165
        `CU_AFTER_RESET_STATE:
166
        begin
167
 
168
        `ifdef DEBUG
169
                `LOGME"%d CU_AFTER_RESET_STATE\n",$time);
170
        `endif
171
 
172
                oRamBusOwner                            <= 0;
173
                oUCodeInstructioPointer <= `INITIAL_UCODE_ADDRESS;
174
                oGFUEnable                                      <= 0;
175
                oUCodeEnable                            <= 0;
176
                oIOWritePixel                           <= 0;
177
                rResetHitFlop                           <= 1;
178
                rHitFlopEnable                          <= 0;
179
                oTriggerTFF             <= 0;
180
                oSetCurrentPitch        <= 1;
181
                //oIncCurrentPitch        <= 0;
182
 
183
                NextState                                       <= `CU_WAIT_FOR_INITIAL_CONFIGURATION;
184
 
185
        end
186
        //-----------------------------------------
187
 
188
        `CU_WAIT_FOR_INITIAL_CONFIGURATION:
189
        begin
190
        $display("CU_WAIT_FOR_INITIAL_CONFIGURATION");
191
//              `ifdef DEBUG
192
//                      `LOGME"%d Control: CU_WAIT_FOR_INITIAL_CONFIGURATION\n",$time);
193
//              `endif
194
 
195
                oRamBusOwner                            <= 0;
196
                oUCodeInstructioPointer <= 0;
197
                oGFUEnable                                      <= 0;
198
                oUCodeEnable                            <= 0;
199
                oIOWritePixel                           <= 0;
200
                rResetHitFlop                           <= 1;
201
                rHitFlopEnable                          <= 0;
202
      oTriggerTFF             <= 0;
203
                oSetCurrentPitch        <= 0;
204
                //oIncCurrentPitch        <= 0;         
205
 
206
                if ( MST_I  )
207
                        NextState <= `CU_PERFORM_INTIAL_CONFIGURATION;//`CU_WAIT_FOR_CONFIG_DATA_READ;
208
                else
209
                        NextState <= `CU_WAIT_FOR_INITIAL_CONFIGURATION;
210
 
211
 
212
        end
213
        //-----------------------------------------
214
        `CU_PERFORM_INTIAL_CONFIGURATION:
215
        begin
216
        oRamBusOwner                            <= 0;
217
                oUCodeInstructioPointer <= 0;
218
                oGFUEnable                                      <= 0;
219
                oUCodeEnable                            <= 0;
220
                oIOWritePixel                           <= 0;
221
                rResetHitFlop                           <= 1;
222
                rHitFlopEnable                          <= 0;
223
      oTriggerTFF             <= 0;
224
                oSetCurrentPitch        <= 0;
225
                //oIncCurrentPitch        <= 0;         
226
 
227
                if ( MST_I  )
228
                        NextState <= `CU_PERFORM_INTIAL_CONFIGURATION;//`CU_WAIT_FOR_CONFIG_DATA_READ;
229
                else
230
                        NextState <= `CU_CLEAR_REGISTERS;
231
 
232
        end
233
        //-----------------------------------------
234
        `CU_CLEAR_REGISTERS:
235
        begin
236
        `ifdef DEBUG
237
                `LOGME"%d CU_CLEAR_REGISTERS\n",$time);
238
        `endif
239
 
240
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
241
                oUCodeInstructioPointer <= `INITIAL_UCODE_ADDRESS;
242
                oGFUEnable                                      <= 0;
243
                oUCodeEnable                            <= 1;   //*
244
                oIOWritePixel                           <= 0;
245
                rResetHitFlop                           <= 0;
246
                rHitFlopEnable                          <= 0;
247
                oTriggerTFF             <= 0;
248
                oSetCurrentPitch        <= 0;
249
                //oIncCurrentPitch        <= 0;
250
 
251
                NextState                                       <= `CU_WAIT_CLEAR_REGISTERS;
252
        end
253
//-----------------------------------------     
254
        `CU_WAIT_CLEAR_REGISTERS:
255
        begin
256
//      `ifdef DEBUG
257
//              `LOGME"%d CU_WAIT_CLEAR_REGISTERS\n",$time);
258
//      `endif  
259
 
260
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
261
                oUCodeInstructioPointer <= `INITIAL_UCODE_ADDRESS;
262
                oGFUEnable                                      <= 0;
263
                oUCodeEnable                            <= 0;
264
                oIOWritePixel                           <= 0;
265
                rResetHitFlop                           <= 0;
266
                rHitFlopEnable                          <= 0;
267
      oTriggerTFF             <= 0;
268
                oSetCurrentPitch        <= 0;
269
                //oIncCurrentPitch        <= 0;
270
 
271
                if ( iUCodeDone )
272
                        NextState <= `CU_ACK_CLEAR_REGISTERS;
273
                else
274
                        NextState <= `CU_WAIT_CLEAR_REGISTERS;
275
 
276
        end
277
        //-----------------------------------------
278
        `CU_ACK_CLEAR_REGISTERS:
279
        begin
280
        `ifdef DEBUG
281
                `LOGME"%d CU_ACK_CLEAR_REGISTERS\n", $time);
282
        `endif
283
 
284
                oRamBusOwner                            <= 0;
285
                oUCodeInstructioPointer <= 0;
286
                oGFUEnable                                      <= 0;
287
                oUCodeEnable                            <= 0; //*        
288
                oIOWritePixel                           <= 0;
289
                rResetHitFlop                           <= 0;
290
                rHitFlopEnable                          <= 0;
291
      oTriggerTFF             <= 0;
292
                oSetCurrentPitch        <= 0;
293
                //oIncCurrentPitch        <= 0;
294
 
295
                NextState <= `CU_WAIT_FOR_CONFIG_DATA_READ;
296
        end
297
 
298
 
299
 
300
        //-----------------------------------------
301
        `CU_WAIT_FOR_CONFIG_DATA_READ:
302
        begin
303
        $display("CU_WAIT_FOR_CONFIG_DATA_READ");
304
//              `ifdef DEBUG
305
//                      `LOGME"%d Control: CU_WAIT_FOR_CONFIG_DATA_READ\n",$time);
306
//              `endif
307
 
308
                oRamBusOwner                            <= 0;//`REG_BUS_OWNED_BY_BCU;
309
                oUCodeInstructioPointer <= 0;
310
                oGFUEnable                                      <= 0;
311
                oUCodeEnable                            <= 0;
312
                oIOWritePixel                           <= 0;
313
                rResetHitFlop                           <= 0;
314
                rHitFlopEnable                          <= 0;
315
      oTriggerTFF             <= 0;
316
                oSetCurrentPitch        <= 0;
317
                //oIncCurrentPitch        <= 0;
318
 
319
                if ( MST_I == 0  )
320
                        NextState <= `CU_PRECALCULATE_CONSTANTS;
321
                else
322
                        NextState <= `CU_WAIT_FOR_CONFIG_DATA_READ;
323
 
324
        end
325
        //-----------------------------------------
326
        `CU_PRECALCULATE_CONSTANTS:
327
        begin
328
        $display("CU_PRECALCULATE_CONSTANTS");
329
        `ifdef DEBUG
330
                `LOGME"%d Control: CU_PRECALCULATE_CONSTANTS\n", $time);
331
        `endif
332
 
333
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
334
                oUCodeInstructioPointer <= `CPPU_UCODE_ADDRESS;
335
                oGFUEnable                              <= 0;
336
                oUCodeEnable                            <= 1; //*       
337
                oIOWritePixel                           <= 0;
338
                rResetHitFlop                           <= 0;
339
                rHitFlopEnable                          <= 0;
340
      oTriggerTFF             <= 0;
341
                oSetCurrentPitch        <= 0;
342
                //oIncCurrentPitch        <= 0;
343
 
344
                NextState <= `CU_WAIT_FOR_CONSTANT;
345
 
346
        end
347
        //-----------------------------------------
348
        `CU_WAIT_FOR_CONSTANT:
349
        begin
350
//      `ifdef DEBUG
351
//              `LOGME"%d Control: CU_WAIT_FOR_CONSTANT\n", $time);
352
//      `endif
353
 
354
 
355
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
356
                oUCodeInstructioPointer <= `CPPU_UCODE_ADDRESS;
357
                oGFUEnable                                 <= 0;
358
                oUCodeEnable                            <= 0; //*        
359
                oIOWritePixel                           <= 0;
360
                rResetHitFlop                           <= 0;
361
                rHitFlopEnable                          <= 0;
362
      oTriggerTFF             <= 0;
363
                oSetCurrentPitch        <= 0;
364
                //oIncCurrentPitch        <= 0;
365
 
366
                if ( iUCodeDone )
367
                        NextState <= `CU_ACK_PRECALCULATE_CONSTANTS;
368
                else
369
                        NextState <= `CU_WAIT_FOR_CONSTANT;
370
 
371
        end
372
        //-----------------------------------------
373
        `CU_ACK_PRECALCULATE_CONSTANTS:
374
        begin
375
        $display("CU_ACK_PRECALCULATE_CONSTANTS");
376
        `ifdef DEBUG
377
                `LOGME"%d Control: CU_ACK_PRECALCULATE_CONSTANTS\n", $time);
378
        `endif
379
 
380
 
381
                oRamBusOwner                            <= 0;//`REG_BUS_OWNED_BY_BCU;
382
                oUCodeInstructioPointer <= 0;
383
                oGFUEnable                                 <= 0;
384
                oUCodeEnable                            <= 0; //*        
385
                oIOWritePixel                           <= 0;
386
                rResetHitFlop                           <= 0;
387
                rHitFlopEnable                          <= 0;
388
      oTriggerTFF             <= 0;
389
                oSetCurrentPitch        <= 0;
390
                //oIncCurrentPitch        <= 0;
391
 
392
                NextState <= `CU_TRIGGER_RGU;//CU_WAIT_FOR_TASK;
393
 
394
        end
395
        //-----------------------------------------
396
        `CU_TRIGGER_RGU:
397
        begin
398
 
399
        `ifdef DEBUG
400
                `LOGME"%d Control: CU_TRIGGER_RGU\n",$time);
401
        `endif
402
 
403
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
404
                oUCodeInstructioPointer <= `RGU_UCODE_ADDRESS;
405
                oGFUEnable                                      <= 0;
406
                oUCodeEnable                            <= 1;   //*
407
                oIOWritePixel                           <= 0;
408
                rResetHitFlop                           <= 0;
409
                rHitFlopEnable                          <= 0;
410
      oTriggerTFF             <= 0;
411
                oSetCurrentPitch        <= 0;
412
                //oIncCurrentPitch        <= 0;
413
 
414
                NextState <= `CU_WAIT_FOR_RGU;
415
        end
416
        //-----------------------------------------
417
        `CU_WAIT_FOR_RGU:
418
        begin
419
 
420
//      `ifdef DEBUG
421
//              `LOGME"%d Control: CU_WAIT_FOR_RGU\n",$time);
422
//      `endif
423
 
424
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
425
                oUCodeInstructioPointer <= 0;
426
                oGFUEnable                                      <= 0;
427
                oUCodeEnable                            <= 0;
428
                oIOWritePixel                           <= 0;
429
                rResetHitFlop                           <= 0;
430
                rHitFlopEnable                          <= 0;
431
      oTriggerTFF             <= 0;
432
                oSetCurrentPitch        <= 0;
433
                //oIncCurrentPitch        <= 0;
434
 
435
                if ( iUCodeDone )
436
                        NextState <= `CU_ACK_RGU;
437
                else
438
                        NextState <= `CU_WAIT_FOR_RGU;
439
        end
440
        //-----------------------------------------
441
        `CU_ACK_RGU:
442
        begin
443
 
444
        `ifdef DEBUG
445
                `LOGME"%d Control: CU_ACK_RGU\n",$time);
446
        `endif
447
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
448
                oUCodeInstructioPointer <= 0;
449
                oGFUEnable                                      <= 0;
450
                oUCodeEnable                            <= 0; //*        
451
                oIOWritePixel                           <= 0;
452
                rResetHitFlop                           <= 0;
453
                rHitFlopEnable                          <= 0;
454
      oTriggerTFF             <= 0;
455
                oSetCurrentPitch        <= 0;
456
                //oIncCurrentPitch        <= 0;
457
 
458
                if ( iUCodeDone  == 0)
459
                        NextState <= `CU_TRIGGER_GEO;
460
                else
461
                        NextState <= `CU_ACK_RGU;
462
 
463
        end
464
        //-----------------------------------------
465
        `CU_TRIGGER_GEO:
466
        begin
467
 
468
        `ifdef DEBUG
469
                `LOGME"%d Control: CU_TRIGGER_GEO\n",$time);
470
        `endif
471
 
472
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
473
                oUCodeInstructioPointer <= 0;
474
                oUCodeEnable                            <= 0;
475
                oGFUEnable                                      <= 1;
476
                oIOWritePixel                           <= 0;
477
                rResetHitFlop                           <= 1;   //*
478
                rHitFlopEnable                          <= 0;
479
      oTriggerTFF             <= 0;
480
                oSetCurrentPitch        <= 0;
481
                //oIncCurrentPitch        <= 0;
482
 
483
                NextState <= `CU_WAIT_FOR_GEO_SYNC;
484
 
485
        end
486
        //-----------------------------------------
487
        `CU_WAIT_FOR_GEO_SYNC:
488
        begin
489
 
490
        `ifdef DEBUG
491
                `LOGME"%d Control: CU_WAIT_FOR_GEO_SYNC\n",$time);
492
        `endif
493
 
494
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
495
                oUCodeInstructioPointer <= 0;
496
                oUCodeEnable                            <= 0;
497
                oGFUEnable                                      <= 0; //Change AUg 15
498
                oIOWritePixel                           <= 0;
499
                rResetHitFlop                           <= 0;
500
                rHitFlopEnable                          <= 0;
501
      oTriggerTFF             <= 0;
502
                oSetCurrentPitch        <= 0;
503
                //oIncCurrentPitch        <= 0;
504
 
505
        if (iGEOSync & iTriggerAABBIURequest )
506
                NextState <= `CU_TRIGGER_AABBIU;
507
        else if (iGEOSync & iTriggerBIURequest)
508
                NextState <= `CU_TRIGGER_BIU;
509
        else if (iGEOSync & iTriggertTCCRequest )
510
      NextState <= `CU_TRIGGER_TCC;
511
   else if (iGEOSync & iGFUDone )
512
      NextState <= `CU_CHECK_HIT;
513
   else
514
      NextState <= `CU_WAIT_FOR_GEO_SYNC;
515
 
516
        end
517
        //-----------------------------------------
518
        `CU_TRIGGER_TCC:
519
        begin
520
        //$display("CU_TRIGGER_TCC");
521
        `ifdef DEBUG
522
                `LOGME"%d Control: CU_TRIGGER_TCC\n",$time);
523
        `endif
524
 
525
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_UCODE;
526
                oUCodeInstructioPointer <= `TCC_UCODE_ADDRESS;
527
                oUCodeEnable                            <= 1;   //*
528
                oGFUEnable                                      <= 0;
529
                oIOWritePixel                           <= 0;
530
                rResetHitFlop                           <= 0;
531
                rHitFlopEnable                          <= 0;
532
      oTriggerTFF             <= 0;
533
                oSetCurrentPitch        <= 0;
534
                //oIncCurrentPitch        <= 0;
535
 
536
          NextState  <= `WAIT_FOR_TCC;
537
        end
538
        //-----------------------------------------
539
        `WAIT_FOR_TCC:
540
        begin
541
 
542
        //$display("WAIT_FOR_TCC");
543
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_UCODE;
544
                oUCodeInstructioPointer <= `TCC_UCODE_ADDRESS;
545
                oUCodeEnable                            <= 0;    //*
546
                oGFUEnable                                      <= 0;
547
                oIOWritePixel                           <= 0;
548
                rResetHitFlop                           <= 0;
549
                rHitFlopEnable                          <= 0;
550
      oTriggerTFF             <= 0;
551
                oSetCurrentPitch        <= 0;
552
                //oIncCurrentPitch        <= 0;
553
 
554
           if ( iUCodeDone )
555
                        NextState <= `CU_ACK_UCODE;
556
                else
557
                        NextState <= `WAIT_FOR_TCC;
558
 
559
        end
560
        //-----------------------------------------
561
        /*
562
        Was there any hit at all?
563
        At this point, all the triangles in the list
564
        have been traversed looking for a hit with our ray.
565
        There are 3 possibilities:
566
        1) The was not a single hit, then just paint a black
567
        pixel on the screen and send it via PCU.
568
        2)There was a hit and Texturing is not enabled, then trigger the PSU with
569
        no texturing
570
        2) There was a hit and Texturing is enabled, then fetch the texture
571
        values corresponding to the triangle that we hitted.
572
        */
573
        `CU_CHECK_HIT:
574
        begin
575
 
576
        `ifdef DEBUG
577
                `LOGME"%d Control: CU_CHECK_HIT\n",$time);
578
        `endif
579
 
580
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
581
                oUCodeInstructioPointer <= 0;
582
                oUCodeEnable                            <= 0;
583
                oGFUEnable                                      <= 0;    ///CHANGED Aug 15
584
                oIOWritePixel                           <= 0;
585
                rResetHitFlop                           <= 0;
586
                rHitFlopEnable                          <= 0;
587
           oTriggerTFF             <= 0;
588
                oSetCurrentPitch        <= 0;
589
                //oIncCurrentPitch        <= 0;
590
 
591
                if (wHit && !iControlRegister[`CR_EN_TEXTURE] )
592
                        NextState <= `CU_TRIGGER_PSU;
593
                else if (wHit && iControlRegister[`CR_EN_TEXTURE])
594
                        NextState <= `CU_TRIGGER_TFF;           //Fetch the texture values from external RAM
595
                else
596
                        NextState <= `CU_TRIGGER_PCU;           //Make sure contents of the OUT_REG are ZERo!
597
        end
598
        //-----------------------------------------
599
        /*
600
        Get the texture values from external RAM.
601
        GFU already took care of calculating the correct
602
        texture addresses for the 4 coordinates so now lets
603
        just ask for them.
604
        */
605
        `CU_TRIGGER_TFF:
606
        begin
607
        `ifdef DEBUG
608
                `LOGME"%d Control: CU_TRIGGER_TFF\n",$time);
609
        `endif
610
 
611
        //$display("CU_TRIGGER_TFF");
612
 
613
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
614
                oUCodeInstructioPointer <= 0;
615
                oUCodeEnable                            <= 0;
616
                oGFUEnable                                      <= 1;
617
                oIOWritePixel                           <= 0;
618
                rResetHitFlop                           <= 0;
619
                rHitFlopEnable                          <= 0;
620
                oTriggerTFF             <= 1;       //*
621
           oSetCurrentPitch        <= 0;
622
                //oIncCurrentPitch        <= 0;
623
 
624
                NextState <= `CU_WAIT_FOR_TFF;
625
        end
626
        //-----------------------------------------
627
        `CU_WAIT_FOR_TFF:
628
        begin
629
 
630
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_GFU;
631
                oUCodeInstructioPointer <= 0;
632
                oUCodeEnable                            <= 0;
633
                oGFUEnable                                      <= 0;     //Changed Aug 14
634
                oIOWritePixel                           <= 0;
635
                rResetHitFlop                           <= 0;
636
                rHitFlopEnable                          <= 0;
637
                oTriggerTFF             <= 0;
638
                oSetCurrentPitch        <= 0;
639
                //oIncCurrentPitch        <= 0;
640
 
641
        if (iTFFDone)
642
                NextState <= `CU_TRIGGER_PSU_WITH_TEXTURE;
643
        else
644
                NextState <= `CU_WAIT_FOR_TFF;
645
 
646
        end
647
        //-----------------------------------------
648
        `CU_TRIGGER_PSU_WITH_TEXTURE:
649
        begin
650
 
651
        `ifdef DEBUG
652
                `LOGME"%d Control: CU_TRIGGER_PSU_WITH_TEXTURE\n",$time);
653
        `endif
654
 
655
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_UCODE;
656
                oUCodeInstructioPointer <= `PSU_UCODE_ADRESS2;
657
                oUCodeEnable                            <= 1;
658
                oGFUEnable                                      <= 0;
659
                oIOWritePixel                           <= 0;
660
                rResetHitFlop                           <= 0;
661
                rHitFlopEnable                          <= 0;
662
                oTriggerTFF             <= 0;
663
                oSetCurrentPitch        <= 0;
664
           //oIncCurrentPitch        <= 0;
665
 
666
                NextState <= `CU_WAIT_FOR_PSU;
667
        end
668
        //-----------------------------------------
669
        `CU_TRIGGER_AABBIU:
670
        begin
671
 
672
        `ifdef DEBUG
673
                `LOGME"%d Control: CU_TRIGGER_AABBIU\n",$time);
674
        `endif
675
//      $stop();
676
                oRamBusOwner                            <= wAABBIUAddress;//`REG_BUS_OWNED_BY_UCODE;
677
 
678
                oUCodeInstructioPointer <=`AABBIU_UCODE_ADDRESS;
679
                oUCodeEnable                            <= 1;
680
                oGFUEnable                                      <= 1;
681
                oIOWritePixel                           <= 0;
682
                rResetHitFlop                           <= 0;
683
                rHitFlopEnable                          <= 0;
684
      oTriggerTFF             <= 0;
685
                oSetCurrentPitch        <= 0;
686
                //oIncCurrentPitch        <= 0;
687
 
688
                NextState <= `CU_WAIT_FOR_AABBIU;
689
        end
690
        //-----------------------------------------
691
        `CU_WAIT_FOR_AABBIU:
692
        begin
693
 
694
 
695
//      `ifdef DEBUG
696
//              `LOGME"%d Control: CU_WAIT_FOR_AABBIU\n",$time);
697
//      `endif
698
 
699
 
700
//      $display("iUCodeDone",iUCodeDone);
701
 
702
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
703
                oUCodeInstructioPointer <= `AABBIU_UCODE_ADDRESS;
704
                oUCodeEnable                            <= 0;
705
                oGFUEnable                                      <= 1;
706
                oIOWritePixel                           <= 0;
707
                rResetHitFlop                           <= 0;
708
                rHitFlopEnable                          <= 0;
709
      oTriggerTFF             <= 0;
710
                oSetCurrentPitch        <= 0;
711
                //oIncCurrentPitch        <= 0;
712
 
713
                if ( iUCodeDone )
714
                begin
715
        //         $display("iUCodeDone\n",iUCodeDone);
716
        //              $stop();
717
                        NextState <= `CU_ACK_UCODE;
718
                end
719
                else
720
                        NextState <= `CU_WAIT_FOR_AABBIU;
721
        end
722
        //-----------------------------------------
723
        `CU_TRIGGER_BIU:
724
        begin
725
        `ifdef DEBUG
726
                `LOGME"%d Control: CU_TRIGGER_BIU\n",$time);
727
        `endif
728
 
729
                        oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
730
                        oUCodeInstructioPointer <= `BIU_UCODE_ADDRESS;
731
                        oUCodeEnable                            <= 1;
732
                        oGFUEnable                                      <= 1;
733
                        oIOWritePixel                           <= 0;
734
                        rResetHitFlop                           <= 0;//1;        
735
                        rHitFlopEnable                          <= 1;
736
         oTriggerTFF             <= 0;
737
                        oSetCurrentPitch        <= 0;
738
                        //oIncCurrentPitch        <= 0;
739
                //      $stop();
740
 
741
                        NextState <= `CU_WAIT_FOR_BIU;
742
 
743
        end
744
        //-----------------------------------------
745
        `CU_WAIT_FOR_BIU:
746
        begin
747
//      `ifdef DEBUG
748
//              `LOGME"%d Control: CU_WAIT_FOR_BIU\n",$time);
749
//      `endif
750
 
751
                        oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
752
                        oUCodeInstructioPointer <= `BIU_UCODE_ADDRESS;
753
                        oUCodeEnable                            <= 0;
754
                        oGFUEnable                                      <= 1;
755
                        oIOWritePixel                           <= 0;
756
                        rResetHitFlop                           <= 0;
757
                        rHitFlopEnable                          <= 1;
758
         oTriggerTFF             <= 0;
759
                        oSetCurrentPitch        <= 0;
760
                        //oIncCurrentPitch        <= 0;
761
 
762
                if ( iUCodeDone )
763
                        NextState <= `CU_ACK_UCODE;
764
                else
765
                        NextState <= `CU_WAIT_FOR_BIU;
766
        end
767
        //-----------------------------------------
768
        /*
769
                ACK UCODE by setting oUCodeEnable = 0
770
        */
771
        `CU_ACK_UCODE:
772
        begin
773
        `ifdef DEBUG
774
                `LOGME"%d Control: CU_ACK_UCODE\n",$time);
775
        `endif
776
 
777
                        oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
778
                        oUCodeInstructioPointer <= 0; //*
779
                        oUCodeEnable                            <= 0;    //*
780
                        oGFUEnable                                      <= 0; //Changed Aug 15
781
                        oIOWritePixel                           <= 0;
782
                        rResetHitFlop                           <= 0;
783
                        rHitFlopEnable                          <= 0;
784
         oTriggerTFF             <= 0;
785
                        oSetCurrentPitch        <= 0;
786
                        //oIncCurrentPitch        <= 0;
787
 
788
        //              $stop();
789
 
790
                        if ( iUCodeDone == 0 )
791
                                NextState <= `CU_WAIT_FOR_GEO_SYNC;
792
                        else
793
                                NextState <= `CU_ACK_UCODE;
794
        end
795
        //-----------------------------------------
796
        /*
797
        Here we no longer use GFU so set Enable to zero
798
        */
799
        `CU_TRIGGER_PSU:
800
        begin
801
        `ifdef DEBUG
802
                `LOGME"%d Control: CU_TRIGGER_PSU\n",$time);
803
        `endif
804
 
805
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
806
                oUCodeInstructioPointer <= `PSU_UCODE_ADRESS;
807
                oUCodeEnable                            <= 1;
808
                oGFUEnable                                      <= 0;//*
809
                oIOWritePixel                           <= 0;
810
                rResetHitFlop                           <= 0;
811
                rHitFlopEnable                          <= 0;
812
                oTriggerTFF             <= 0;
813
                oSetCurrentPitch        <= 0;
814
                //oIncCurrentPitch        <= 0;
815
 
816
 
817
                NextState <= `CU_WAIT_FOR_PSU;
818
        end
819
        //-----------------------------------------
820
        `CU_WAIT_FOR_PSU:
821
        begin
822
 
823
//      `ifdef DEBUG
824
//              `LOGME"%d Control: CU_TRIGGER_PSU\n",$time);
825
//      `endif
826
 
827
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
828
                oUCodeInstructioPointer <= `PSU_UCODE_ADRESS;
829
                oUCodeEnable                            <= 0;
830
                oGFUEnable                                      <= 0;
831
                oIOWritePixel                           <= 0;
832
                rResetHitFlop                           <= 0;
833
                rHitFlopEnable                          <= 0;
834
                oTriggerTFF             <= 0;
835
                oSetCurrentPitch        <= 0;
836
                //oIncCurrentPitch        <= 0;
837
 
838
 
839
                if ( iUCodeDone )
840
                        NextState <= `CU_ACK_PSU;
841
                else
842
                        NextState <= `CU_WAIT_FOR_PSU;
843
 
844
        end
845
        //-----------------------------------------
846
        `CU_ACK_PSU:
847
        begin
848
        `ifdef DEBUG
849
                `LOGME"%d Control: CU_ACK_PSU\n",$time);
850
        `endif
851
 
852
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
853
                oUCodeInstructioPointer <= 0;    //*
854
                oUCodeEnable                            <= 0;    //*
855
                oGFUEnable                                      <= 0;
856
                oIOWritePixel                           <= 0;
857
                rResetHitFlop                           <= 0;
858
                rHitFlopEnable                          <= 0;
859
      oTriggerTFF             <= 0;
860
                oSetCurrentPitch        <= 0;
861
                //oIncCurrentPitch        <= 0;
862
 
863
                if ( iUCodeDone  == 0)
864
                        NextState <= `CU_TRIGGER_PCU;
865
                else
866
                        NextState <= `CU_ACK_PSU;
867
 
868
 
869
        end
870
        //-----------------------------------------
871
        /*
872
                Trigger the Pixel Commit.
873
        */
874
        `CU_TRIGGER_PCU:
875
        begin
876
 
877
        `ifdef DEBUG
878
                `LOGME"%d Control: CU_TRIGGER_PCU\n",$time);
879
        `endif
880
 
881
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
882
                oUCodeInstructioPointer <= 0;    //*
883
                oUCodeEnable                            <= 0;    //*
884
                oGFUEnable                                      <= 0;
885
                oIOWritePixel                           <= 1; //*
886
                rResetHitFlop                           <= 0;
887
                rHitFlopEnable                          <= 0;
888
      oTriggerTFF             <= 0;
889
                oSetCurrentPitch        <= 0;
890
                //oIncCurrentPitch        <= 0;
891
 
892
 
893
                NextState <= `CU_SET_PICTH;
894
 
895
        end
896
        //-----------------------------------------
897
        `CU_SET_PICTH:
898
        begin
899
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
900
                oUCodeInstructioPointer <= 0;    //*
901
                oUCodeEnable                            <= 0;    //*
902
                oGFUEnable                                      <= 0;
903
                oIOWritePixel                           <= 1; //*
904
                rResetHitFlop                           <= 0;
905
                rHitFlopEnable                          <= 0;
906
      oTriggerTFF             <= 0;
907
                oSetCurrentPitch        <= 1; //*
908
                //oIncCurrentPitch        <= 0;
909
 
910
 
911
                NextState <= `CU_WAIT_FOR_PCU;
912
        end
913
        //-----------------------------------------
914
        `CU_WAIT_FOR_PCU:
915
        begin
916
 
917
//      `ifdef DEBUG
918
//              `LOGME"%d Control: CU_WAIT_FOR_PCU\n",$time);
919
//      `endif
920
 
921
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
922
                oUCodeInstructioPointer <= 0;    //*
923
                oUCodeEnable                            <= 0;    //*
924
                oGFUEnable                                      <= 0;
925
                oIOWritePixel                           <= 1;
926
                rResetHitFlop                           <= 0;
927
                rHitFlopEnable                          <= 0;
928
      oTriggerTFF             <= 0;
929
                oSetCurrentPitch        <= 0;
930
                //oIncCurrentPitch        <= 0;
931
 
932
                if ( iIODone )
933
                        NextState <= `CU_ACK_PCU;
934
                else
935
                        NextState <= `CU_WAIT_FOR_PCU;
936
 
937
        end
938
        //-----------------------------------------
939
        `CU_ACK_PCU:
940
        begin
941
 
942
        `ifdef DEBUG
943
                `LOGME"%d Control: CU_ACK_PCU\n",$time);
944
        `endif
945
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
946
                oUCodeInstructioPointer <= 0;    //*
947
                oUCodeEnable                            <= 0;    //*
948
                oGFUEnable                                      <= 0;
949
                oIOWritePixel                           <= 0;
950
                rResetHitFlop                           <= 0;
951
                rHitFlopEnable                          <= 0;
952
      oTriggerTFF             <= 0;
953
                oSetCurrentPitch        <= 0;
954
                //oIncCurrentPitch        <= 0;
955
 
956
                NextState <= `CU_TRIGGER_NPU;
957
 
958
        end
959
        //-----------------------------------------
960
        `CU_TRIGGER_NPU: //Next Pixel Unit
961
        begin
962
        `ifdef DEBUG
963
                `LOGME"%d Control: CU_TRIGGER_NPU\n",$time);
964
        `endif
965
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
966
                oUCodeInstructioPointer <= `NPG_UCODE_ADDRESS;  //*
967
                oUCodeEnable                            <= 1;   //*
968
                oGFUEnable                                      <= 0;
969
                oIOWritePixel                           <= 0;
970
                rResetHitFlop                           <= 0;
971
                rHitFlopEnable                          <= 0;
972
      oTriggerTFF             <= 0;
973
                oSetCurrentPitch        <= 0;
974
                //oIncCurrentPitch        <= 0;
975
 
976
                NextState <= `CU_WAIT_NPU;
977
        end
978
        //-----------------------------------------
979
        `CU_WAIT_NPU:
980
        begin
981
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
982
                oUCodeInstructioPointer <= `NPG_UCODE_ADDRESS;
983
                oUCodeEnable                            <= 0;
984
                oGFUEnable                                      <= 0;
985
                oIOWritePixel                           <= 0;
986
                rResetHitFlop                           <= 0;
987
                rHitFlopEnable                          <= 0;
988
                oTriggerTFF             <= 0;
989
                oSetCurrentPitch        <= 0;
990
                //oIncCurrentPitch        <= 0;
991
 
992
                if ( iUCodeDone )
993
                        NextState <= `CU_ACK_NPU;
994
                else
995
                        NextState <= `CU_WAIT_NPU;
996
        end
997
        //-----------------------------------------
998
        `CU_ACK_NPU:
999
        begin
1000
        `ifdef DEBUG
1001
                `LOGME"%d Control: CU_ACK_PSU\n",$time);
1002
        `endif
1003
 
1004
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1005
                oUCodeInstructioPointer <= 0;    //*
1006
                oUCodeEnable                            <= 0;    //*
1007
                oGFUEnable                                      <= 0;
1008
                oIOWritePixel                           <= 0;
1009
                rResetHitFlop                           <= 0;
1010
                rHitFlopEnable                          <= 0;
1011
      oTriggerTFF             <= 0;
1012
                oSetCurrentPitch        <= 0;
1013
                //oIncCurrentPitch        <= 0;
1014
 
1015
                if ( iUCodeDone  == 0)
1016
                        NextState <= `CU_TRIGGER_RGU;
1017
                else
1018
                        NextState <= `CU_ACK_NPU;
1019
 
1020
 
1021
        end
1022
        //-----------------------------------------
1023
        default:
1024
        begin
1025
 
1026
        `ifdef DEBUG
1027
                `LOGME"%d Control: ERRO Undefined State\n",$time);
1028
        `endif
1029
 
1030
                oRamBusOwner                            <= 0;
1031
                oUCodeInstructioPointer <= 0;
1032
                oUCodeEnable                            <= 0;
1033
                oGFUEnable                                      <= 0;
1034
                oIOWritePixel                           <= 0;
1035
                rResetHitFlop                           <= 0;
1036
                rHitFlopEnable                          <= 0;
1037
      oTriggerTFF             <= 0;
1038
                oSetCurrentPitch        <= 0;
1039
                //oIncCurrentPitch        <= 0;
1040
 
1041
                NextState <= `CU_AFTER_RESET_STATE;
1042
        end
1043
        //-----------------------------------------
1044
 
1045
        endcase
1046
 
1047
end //always    
1048
endmodule

powered by: WebSVN 2.1.0

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