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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [axi_cmn/] [fm_asys.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_asys.v
7
//
8
// Abstract:
9
//   System control module
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 5 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2016, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
`include "polyphony_def.v"
43
module fm_asys (
44
    clk_core,
45
    rst_x,
46
    // internal interface
47
    i_req,
48
    i_wr,
49
    i_adrs,
50
    o_ack,
51
    i_be,
52
    i_wd,
53
    o_rstr,
54
    o_rd,
55
    // configuration output
56
    //   Video controller
57
    o_video_start,
58
    o_aa_en,
59
    o_fb0_offset,
60
    o_fb0_ms_offset,
61
    o_fb1_offset,
62
    o_fb1_ms_offset,
63
    o_color_mode,
64
    o_front_buffer,
65
    o_fb_blend_en,
66
    // status from Video controller
67
    i_vint_x,
68
    i_vint_edge,
69
    // status from 3D core
70
    i_vtx_int,
71
    // int out to sh4
72
    o_int_x,
73
    // DMA
74
    o_dma_start,
75
    o_dma_mode,
76
    i_dma_end,
77
    o_dma_top_address0,
78
    o_dma_top_address1,
79
    o_dma_top_address2,
80
    o_dma_top_address3,
81
    o_dma_length,
82
    o_dma_be,
83
    o_dma_wd0,
84
    o_dma_wd1,
85
    // AXI Configuration
86
    o_conf_arcache_m,
87
    o_conf_aruser_m,
88
    o_conf_awcache_m,
89
    o_conf_awuser_m
90
);
91
//////////////////////////////////
92
// I/O port definition
93
//////////////////////////////////
94
    input          clk_core;
95
    input          rst_x;
96
    // internal interface
97
    input          i_req;
98
    input          i_wr;
99
    input  [21:0]  i_adrs;
100
    output         o_ack;
101
    input  [3:0]   i_be;
102
    input  [31:0]  i_wd;
103
    output         o_rstr;
104
    output [31:0]  o_rd;
105
    // configuration output
106
    //   Video controller
107
    output [1:0]   o_video_start;
108
    output [2:0]   o_aa_en;
109
    output [11:0]  o_fb0_offset;
110
    output [11:0]  o_fb0_ms_offset;
111
    output [11:0]  o_fb1_offset;
112
    output [11:0]  o_fb1_ms_offset;
113
    output [1:0]   o_color_mode;
114
    output         o_front_buffer;
115
    output         o_fb_blend_en;
116
    // status from Video controller
117
    input          i_vint_x;
118
    input          i_vint_edge;
119
    // status from 3D core
120
    input          i_vtx_int;
121
    // int out to sh4
122
    output         o_int_x;
123
    // DMA
124
    output         o_dma_start;
125
    output [3:0]   o_dma_mode;
126
    input          i_dma_end;
127
    output [19:0]  o_dma_top_address0;
128
    output [19:0]  o_dma_top_address1;
129
    output [19:0]  o_dma_top_address2;
130
    output [19:0]  o_dma_top_address3;
131
    output [17:0]  o_dma_length;
132
    output [3:0]   o_dma_be;
133
    output [31:0]  o_dma_wd0;
134
    output [31:0]  o_dma_wd1;
135
    // AXI Configuration
136
    output [3:0]   o_conf_arcache_m;
137
    output [4:0]   o_conf_aruser_m;
138
    output [3:0]   o_conf_awcache_m;
139
    output [4:0]   o_conf_awuser_m;
140
//////////////////////////////////
141
// regs 
142
//////////////////////////////////
143
    reg    [1:0]   r_video_start;
144
    reg    [2:0]   r_aa_en;
145
    reg    [11:0]  r_fb0_offset;
146
    reg    [11:0]  r_fb0_ms_offset;
147
    reg    [11:0]  r_fb1_offset;
148
    reg    [11:0]  r_fb1_ms_offset;
149
    reg    [1:0]   r_color_mode;
150
    reg            r_fb_blend_en;
151
 
152
    reg            r_rstr;
153
    reg    [31:0]  r_rd;
154
 
155
    reg            r_vint_x;
156
    reg    [2:0]   r_mask;
157
    reg            r_front_buffer;
158
    reg            r_dma_start;
159
    reg    [3:0]   r_dma_mode;
160
    reg            r_dma_int;
161
    reg    [19:0]  r_dma_top_address0;
162
    reg    [19:0]  r_dma_top_address1;
163
    reg    [19:0]  r_dma_top_address2;
164
    reg    [19:0]  r_dma_top_address3;
165
    reg    [17:0]  r_dma_length;
166
    reg    [3:0]   r_dma_be;
167
    reg    [31:0]  r_dma_wd0;
168
    reg    [31:0]  r_dma_wd1;
169
 
170
    reg            r_vint_clear;
171
 
172
    reg    [3:0]   r_conf_arcache_m;
173
    reg    [4:0]   r_conf_aruser_m;
174
    reg    [3:0]   r_conf_awcache_m;
175
    reg    [4:0]   r_conf_awuser_m;
176
//////////////////////////////////
177
// wire
178
//////////////////////////////////
179
    wire           w_hit0;
180
    wire           w_hit1;
181
    wire           w_hit2;
182
    wire           w_hit3;
183
    wire           w_hit4;
184
    wire           w_hit5;
185
    wire           w_hit6;
186
    wire           w_hit8;
187
    wire           w_hit9;
188
    wire           w_hitA;
189
    wire           w_hitB;
190
    wire           w_hitC;
191
    wire           w_hitD;
192
    wire           w_hitE;
193
    wire           w_hitF;
194
    wire           w_hit10;
195
    wire           w_hit11;
196
    wire           w_hit12;
197
    wire           w_hit13;
198
    wire           w_hit14;
199
    wire           w_hit15;
200
    wire           w_hit16;
201
 
202
    wire           w_hit0_w;
203
    wire           w_hit1_w;
204
    wire           w_hit2_w;
205
    wire           w_hit3_w;
206
    wire           w_hit4_w;
207
    wire           w_hit5_w;
208
    wire           w_hit6_w;
209
    wire           w_hit9_w;
210
    wire           w_hitA_w;
211
    wire           w_hitB_w;
212
    wire           w_hitC_w;
213
    wire           w_hitD_w;
214
    wire           w_hitE_w;
215
    wire           w_hitF_w;
216
    wire           w_hit10_w;
217
    wire           w_hit11_w;
218
    wire           w_hit12_w;
219
    wire           w_hit13_w;
220
    wire   [31:0]  w_rd;
221
    wire           w_rstr;
222
    wire           w_vint_x;
223
    wire           w_vint_on;
224
    wire   [2:0]   w_int;
225
//////////////////////////////////
226
// assign
227
//////////////////////////////////
228
assign w_hit0 = (i_adrs[7:2] == 6'h00);  // 0
229
assign w_hit1 = (i_adrs[7:2] == 6'h01);  // 4
230
assign w_hit2 = (i_adrs[7:2] == 6'h02);  // 8
231
assign w_hit3 = (i_adrs[7:2] == 6'h03);  // c
232
assign w_hit4 = (i_adrs[7:2] == 6'h04);  // 10
233
assign w_hit5 = (i_adrs[7:2] == 6'h05);  // 14
234
assign w_hit6 = (i_adrs[7:2] == 6'h06);  // 18
235
assign w_hit8 = (i_adrs[7:2] == 6'h08);  // 20
236
assign w_hit9 = (i_adrs[7:2] == 6'h09);  // 24
237
assign w_hitA = (i_adrs[7:2] == 6'h0a);  // 28
238
assign w_hitB = (i_adrs[7:2] == 6'h0b);  // 2c
239
assign w_hitC = (i_adrs[7:2] == 6'h0c);  // 30
240
assign w_hitD = (i_adrs[7:2] == 6'h0d);  // 34
241
assign w_hitE = (i_adrs[7:2] == 6'h0e);  // 38
242
assign w_hitF = (i_adrs[7:2] == 6'h0f);  // 3c
243
assign w_hit10 = (i_adrs[7:2] == 6'h10);  // 40
244
assign w_hit11 = (i_adrs[7:2] == 6'h11);  // 44
245
assign w_hit12 = (i_adrs[7:2] == 6'h12);  // 48
246
assign w_hit13 = (i_adrs[7:2] == 6'h13);  // 4c
247
assign w_hit14 = (i_adrs[7:2] == 6'h14);  // 50
248
assign w_hit15 = (i_adrs[7:2] == 6'h15);  // 54
249
 
250
 
251
assign w_hit0_w = w_hit0 & i_wr & i_req;
252
assign w_hit1_w = w_hit1 & i_wr & i_req;
253
assign w_hit2_w = w_hit2 & i_wr & i_req;
254
assign w_hit3_w = w_hit3 & i_wr & i_req;
255
assign w_hit4_w = w_hit4 & i_wr & i_req;
256
assign w_hit5_w = w_hit5 & i_wr & i_req;
257
assign w_hit6_w = w_hit6 & i_wr & i_req;
258
assign w_hit9_w = w_hit9 & i_wr & i_req;
259
assign w_hitA_w = w_hitA & i_wr & i_req;
260
assign w_hitB_w = w_hitB & i_wr & i_req;
261
assign w_hitC_w = w_hitC & i_wr & i_req;
262
assign w_hitD_w = w_hitD & i_wr & i_req;
263
assign w_hitE_w = w_hitE & i_wr & i_req;
264
assign w_hitF_w = w_hitF & i_wr & i_req;
265
assign w_hit10_w = w_hit10 & i_wr & i_req;
266
assign w_hit11_w = w_hit11 & i_wr & i_req;
267
assign w_hit12_w = w_hit12 & i_wr & i_req;
268
assign w_hit13_w = w_hit13 & i_wr & i_req;
269
assign w_rstr = i_req & !i_wr;
270
assign w_rd = (w_hit0) ? {15'b0,r_fb_blend_en,5'b0,r_aa_en,6'b0,r_video_start} :
271
              (w_hit1) ? {r_fb0_offset,20'b0} :
272
              (w_hit2) ? {r_fb1_offset,20'b0} :
273
              (w_hit3) ? {r_fb0_ms_offset,20'b0} :
274
              (w_hit4) ? {r_fb1_ms_offset,20'b0} :
275
              (w_hit5) ? {30'b0,r_color_mode} :
276
              (w_hit6) ? {
277
                            3'b0,
278
                            r_conf_awuser_m,
279
                            4'b0,
280
                            r_conf_awcache_m,
281
                            3'b0,
282
                            r_conf_aruser_m,
283
                            4'b0,
284
                            r_conf_arcache_m
285
                          } :
286
              (w_hit8) ? {29'b0,i_vtx_int,r_dma_int,!r_vint_x} :
287
              (w_hit9) ? {31'b0,r_vint_clear} :
288
              (w_hitA) ? {29'b0,r_mask} :
289
              (w_hitB) ? {31'b0,r_front_buffer} :
290
              (w_hitC) ? {r_dma_top_address0,12'b0} :
291
              (w_hitD) ? {r_dma_top_address1,12'b0} :
292
              (w_hitE) ? {r_dma_top_address2,12'b0} :
293
              (w_hitF) ? {r_dma_top_address3,12'b0} :
294
              (w_hit10) ? {4'b0,r_dma_be,6'b0,r_dma_length} :
295
              (w_hit11) ?  r_dma_wd0 :
296
              (w_hit12) ? r_dma_wd1 :
297
              (w_hit14) ? 32'h50475055 :  // PGPU
298
              (w_hit15) ? 32'h76415849 :  // vAXI
299
                         {23'b0,r_dma_int, r_dma_mode,3'b0,r_dma_start};  // w_hit13
300
 
301
 
302
assign w_vint_on = i_vint_edge;  // falling edge detect
303
assign w_vint_x = ~r_vint_clear | i_vint_x;
304
 
305
assign w_int[0] = (r_mask[0]) ? 1'b0 : ~r_vint_x;
306
assign w_int[1] = (r_mask[1]) ? 1'b0 : r_dma_int;
307
assign w_int[2] = (r_mask[2]) ? 1'b0 : i_vtx_int;
308
 
309
 
310
assign o_int_x = !(|w_int);
311
 
312
assign o_rstr  = r_rstr;
313
assign o_rd = r_rd;
314
assign o_ack = i_req;
315
 
316
assign o_video_start = r_video_start;
317
assign o_aa_en = r_aa_en;
318
assign o_fb0_offset = r_fb0_offset;
319
assign o_fb0_ms_offset = r_fb0_ms_offset;
320
assign o_fb1_offset = r_fb1_offset;
321
assign o_fb1_ms_offset = r_fb1_ms_offset;
322
assign o_color_mode = r_color_mode;
323
assign o_front_buffer = r_front_buffer;
324
assign o_fb_blend_en = r_fb_blend_en;
325
assign o_dma_start = r_dma_start;
326
assign o_dma_mode = r_dma_mode;
327
assign o_dma_top_address0 = r_dma_top_address0;
328
assign o_dma_top_address1 = r_dma_top_address1;
329
assign o_dma_top_address2 = r_dma_top_address2;
330
assign o_dma_top_address3 = r_dma_top_address3;
331
assign o_dma_length = r_dma_length;
332
assign o_dma_be = r_dma_be;
333
assign o_dma_wd0 = r_dma_wd0;
334
assign o_dma_wd1 = r_dma_wd1;
335
assign o_conf_arcache_m = r_conf_arcache_m;
336
assign o_conf_aruser_m = r_conf_aruser_m;
337
assign o_conf_awcache_m = r_conf_awcache_m;
338
assign o_conf_awuser_m = r_conf_awuser_m;
339
 
340
//////////////////////////////////
341
// always
342
//////////////////////////////////
343
 
344
always @(posedge clk_core or negedge rst_x) begin
345
    if (~rst_x) begin
346
        r_video_start <= 2'b0;
347
    end else begin
348
        if (w_hit0_w) begin
349
            if (i_be[0]) r_video_start   <= i_wd[1:0];
350
            if (i_be[1]) r_aa_en         <= i_wd[10:8];
351
            if (i_be[2]) r_fb_blend_en   <= i_wd[16];
352
        end
353
    end
354
end
355
 
356
// register holds 32-bit address
357
always @(posedge clk_core or negedge rst_x) begin
358
    if (~rst_x) begin
359
        r_fb0_offset <= 12'b0;
360
        r_fb0_ms_offset <= 12'b0;
361
    end else begin
362
        if (w_hit1_w) begin
363
            if (i_be[2]) r_fb0_offset[3:0] <= i_wd[23:20];
364
            if (i_be[3]) r_fb0_offset[11:4] <= i_wd[31:24];
365
        end
366
        if (w_hit3_w) begin
367
            if (i_be[2]) r_fb0_ms_offset[3:0] <= i_wd[23:20];
368
            if (i_be[3]) r_fb0_ms_offset[11:4] <= i_wd[31:24];
369
        end
370
    end
371
end
372
 
373
always @(posedge clk_core or negedge rst_x) begin
374
    if (~rst_x) begin
375
        r_fb1_offset <= 12'b0;
376
        r_fb1_ms_offset <= 12'b0;
377
    end else begin
378
        if (w_hit2_w) begin
379
            if (i_be[2]) r_fb1_offset[3:0] <= i_wd[23:20];
380
            if (i_be[3]) r_fb1_offset[11:4] <= i_wd[31:24];
381
        end
382
        if (w_hit4_w) begin
383
            if (i_be[2]) r_fb1_ms_offset[3:0] <= i_wd[23:20];
384
            if (i_be[3]) r_fb1_ms_offset[11:4] <= i_wd[31:24];
385
        end
386
    end
387
end
388
 
389
always @(posedge clk_core or negedge rst_x) begin
390
    if (~rst_x) begin
391
        r_color_mode <= 2'b0;
392
    end else begin
393
        if (w_hit5_w) begin
394
            if (i_be[0]) r_color_mode   <= i_wd[1:0];
395
        end
396
    end
397
end
398
 
399
always @(posedge clk_core or negedge rst_x) begin
400
    if (~rst_x) begin
401
      r_conf_arcache_m <= 4'h0;
402
      r_conf_aruser_m <= 5'h0;
403
      r_conf_awcache_m <= 4'h0;
404
      r_conf_awuser_m <= 5'h0;
405
    end else begin
406
        if (w_hit6_w) begin
407
            if (i_be[0]) r_conf_arcache_m   <= i_wd[3:0];
408
            if (i_be[1]) r_conf_aruser_m    <= i_wd[12:8];
409
            if (i_be[2]) r_conf_awcache_m   <= i_wd[19:16];
410
            if (i_be[3]) r_conf_awuser_m    <= i_wd[29:24];
411
        end
412
    end
413
end
414
 
415
always @(posedge clk_core or negedge rst_x) begin
416
    if (~rst_x) begin
417
        r_vint_clear <= 1'b0;
418
    end else begin
419
        if (w_hit9_w) begin
420
            if (i_be[0]) r_vint_clear <= i_wd[0];
421
        end else if (w_vint_on) begin
422
            r_vint_clear <= 1'b1;
423
        end
424
    end
425
end
426
 
427
always @(posedge clk_core or negedge rst_x) begin
428
    if (~rst_x) begin
429
        r_mask <= 2'b11;
430
    end else begin
431
        if (w_hitA_w) begin
432
            if (i_be[0]) r_mask   <= i_wd[1:0];
433
        end
434
    end
435
end
436
 
437
always @(posedge clk_core or negedge rst_x) begin
438
    if (~rst_x) begin
439
        r_front_buffer <= 1'b0;
440
    end else begin
441
        if (w_hitB_w) begin
442
            if (i_be[0]) r_front_buffer   <= i_wd[0];
443
        end
444
    end
445
end
446
 
447
always @(posedge clk_core or negedge rst_x) begin
448
    if (~rst_x) begin
449
        r_dma_top_address0 <= 20'b0;
450
        r_dma_top_address1 <= 20'b0;
451
        r_dma_top_address2 <= 20'b0;
452
        r_dma_top_address3 <= 20'b0;
453
    end else begin
454
        if (w_hitC_w) begin
455
            r_dma_top_address0[11:0]  <= i_wd[23:12];
456
            r_dma_top_address0[19:12] <= i_wd[31:24];
457
        end
458
        if (w_hitD_w) begin
459
            r_dma_top_address1[11:0]  <= i_wd[23:12];
460
            r_dma_top_address1[19:12] <= i_wd[31:24];
461
        end
462
        if (w_hitE_w) begin
463
            r_dma_top_address2[11:0]  <= i_wd[23:12];
464
            r_dma_top_address2[19:12] <= i_wd[31:24];
465
        end
466
        if (w_hitF_w) begin
467
            r_dma_top_address3[11:0]  <= i_wd[23:12];
468
            r_dma_top_address3[19:12] <= i_wd[31:24];
469
        end
470
    end
471
end
472
 
473
always @(posedge clk_core or negedge rst_x) begin
474
    if (~rst_x) begin
475
        r_dma_length <= 18'b0;
476
        r_dma_be <= 4'hf;
477
    end else begin
478
        if (w_hit10_w) begin
479
            if (i_be[0]) r_dma_length[7:0]   <= i_wd[7:0];
480
            if (i_be[1]) r_dma_length[15:8]  <= i_wd[15:8];
481
            if (i_be[2]) r_dma_length[17:16]  <= i_wd[17:16];
482
            if (i_be[3]) r_dma_be <= i_wd[27:24];
483
        end
484
    end
485
end
486
 
487
always @(posedge clk_core or negedge rst_x) begin
488
    if (~rst_x) begin
489
        r_dma_wd0 <= 32'b0;
490
        r_dma_wd1 <= 32'b0;
491
    end else begin
492
        if (w_hit11_w) begin
493
            r_dma_wd0   <= i_wd;
494
        end
495
        if (w_hit12_w) begin
496
            r_dma_wd1   <= i_wd;
497
        end
498
    end
499
end
500
 
501
 
502
always @(posedge clk_core or negedge rst_x) begin
503
    if (~rst_x) begin
504
        r_dma_start <= 1'b0;
505
        r_dma_mode <= 4'b0;
506
        r_dma_int <= 1'b0;
507
    end else begin
508
        if (w_hit13_w) begin
509
            if (i_be[0]) r_dma_start   <= i_wd[0];
510
            if (i_be[0]) r_dma_mode    <= i_wd[7:4];
511
            if (i_be[1]) r_dma_int <= i_wd[8];
512
        end else begin
513
            if (i_dma_end) begin
514
                r_dma_start <= 1'b0;
515
                r_dma_mode  <= 1'b0;
516
                r_dma_int   <= 1'b1;
517
            end
518
        end
519
    end
520
end
521
 
522
always @(posedge clk_core) begin
523
    r_rd <= w_rd;
524
end
525
 
526
always @(posedge clk_core or negedge rst_x) begin
527
    if (~rst_x) begin
528
        r_rstr <= 1'b0;
529
    end else begin
530
        r_rstr <= w_rstr;
531
    end
532
end
533
 
534
 
535
always @(posedge clk_core or negedge rst_x) begin
536
    if (~rst_x) begin
537
        r_vint_x <= 1'b1;
538
    end else begin
539
        r_vint_x <= w_vint_x;
540
    end
541
end
542
endmodule

powered by: WebSVN 2.1.0

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