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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [de0/] [fm_hsys.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_hsys.v
7
//
8
// Abstract:
9
//   System register module
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, 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
module fm_hsys (
43
    clk_core,
44
    rst_x,
45
    // internal interface
46
    i_req,
47
    i_wr,
48
    i_adrs,
49
    o_ack,
50
    i_be,
51
    i_wd,
52
    o_rstr,
53
    o_rd,
54
    // configuration output
55
    //   Video controller
56
    o_video_start,
57
    o_aa_en,
58
    o_fb0_offset,
59
    o_fb1_offset,
60
    o_color_mode,
61
    o_front_buffer,
62
    o_fb_blend_en,
63
    // status from Video controller
64
    i_vint_x,
65
    i_vint_edge,
66
    // status from 3D core
67
    i_vtx_int,
68
    // int out
69
    o_int
70
);
71
//////////////////////////////////
72
// I/O port definition
73
//////////////////////////////////
74
    input          clk_core;
75
    input          rst_x;
76
    // internal interface
77
    input          i_req;
78
    input          i_wr;
79
    input  [3:0]   i_adrs;
80
    output         o_ack;
81
    input  [3:0]   i_be;
82
    input  [31:0]  i_wd;
83
    output         o_rstr;
84
    output [31:0]  o_rd;
85
    // configuration output
86
    //   Video controller
87
    output         o_video_start;
88
    output [2:0]   o_aa_en;
89
    output [6:0]   o_fb0_offset;
90
    output [6:0]   o_fb1_offset;
91
    output [1:0]   o_color_mode;
92
    output         o_front_buffer;
93
    output         o_fb_blend_en;
94
    // status from Video controller
95
    input          i_vint_x;
96
    input          i_vint_edge;
97
    // status from 3D core
98
    input          i_vtx_int;
99
    // int out
100
    output reg     o_int;
101
 
102
//////////////////////////////////
103
// regs 
104
//////////////////////////////////
105
    reg            r_video_start;
106
    reg    [2:0]   r_aa_en;
107
    reg    [6:0]   r_fb0_offset;
108
    reg    [6:0]   r_fb1_offset;
109
    reg    [1:0]   r_color_mode;
110
    reg            r_fb_blend_en;
111
 
112
    reg            r_rstr;
113
    reg    [31:0]  r_rd;
114
 
115
    reg            r_vint_x;
116
    reg    [2:0]   r_mask;
117
    reg            r_front_buffer;
118
 
119
    reg            r_vint_clear;
120
//////////////////////////////////
121
// wire
122
//////////////////////////////////
123
    wire           w_hit0;
124
    wire           w_hit1;
125
    wire           w_hit2;
126
    wire           w_hit3;
127
    wire           w_hit4;
128
    wire           w_hit5;
129
    wire           w_hit8;
130
    wire           w_hit9;
131
    wire           w_hitA;
132
    wire           w_hitB;
133
    wire           w_hitC;
134
    wire           w_hitD;
135
    wire           w_hitE;
136
    wire           w_hitF;
137
    wire           w_hit10;
138
    wire           w_hit11;
139
    wire           w_hit12;
140
    wire           w_hit13;
141
 
142
    wire           w_hit0_w;
143
    wire           w_hit1_w;
144
    wire           w_hit2_w;
145
    wire           w_hit3_w;
146
    wire           w_hit4_w;
147
    wire           w_hit5_w;
148
    wire           w_hit9_w;
149
    wire           w_hitA_w;
150
    wire           w_hitB_w;
151
 
152
    wire   [31:0]  w_rd;
153
    wire           w_rstr;
154
    wire           w_vint_x;
155
    wire           w_vint_on;
156
    wire   [2:0]   w_int;
157
//////////////////////////////////
158
// assign
159
//////////////////////////////////
160
assign w_hit0 = (i_adrs[3:0] == 4'h0);  // 0
161
assign w_hit1 = (i_adrs[3:0] == 4'h1);  // 4
162
assign w_hit2 = (i_adrs[3:0] == 4'h2);  // 8
163
assign w_hit3 = (i_adrs[3:0] == 4'h3);  // c
164
assign w_hit4 = (i_adrs[3:0] == 4'h4);  // 10
165
assign w_hit5 = (i_adrs[3:0] == 4'h5);  // 14
166
assign w_hit8 = (i_adrs[3:0] == 4'h8);  // 20
167
assign w_hit9 = (i_adrs[3:0] == 4'h9);  // 24
168
assign w_hitA = (i_adrs[3:0] == 4'ha);  // 28
169
assign w_hitB = (i_adrs[3:0] == 4'hb);  // 2c
170
 
171
assign w_hit0_w = w_hit0 & i_wr & i_req;
172
assign w_hit1_w = w_hit1 & i_wr & i_req;
173
assign w_hit2_w = w_hit2 & i_wr & i_req;
174
assign w_hit3_w = w_hit3 & i_wr & i_req;
175
assign w_hit4_w = w_hit4 & i_wr & i_req;
176
assign w_hit5_w = w_hit5 & i_wr & i_req;
177
assign w_hit9_w = w_hit9 & i_wr & i_req;
178
assign w_hitA_w = w_hitA & i_wr & i_req;
179
assign w_hitB_w = w_hitB & i_wr & i_req;
180
 
181
assign w_rstr = i_req & !i_wr;
182
assign w_rd = (w_hit0) ? {16'hbeef,5'b0,r_aa_en,7'b0,r_video_start} :
183
              (w_hit1) ? {6'b0,r_fb0_offset,19'b0} :
184
              (w_hit2) ? {6'b0,r_fb1_offset,19'b0} :
185
              (w_hit5) ? {30'b0,r_color_mode} :
186
              (w_hit8) ? {29'b0,i_vtx_int,!i_vint_x,!r_vint_x} :
187
              (w_hit9) ? {31'b0,r_vint_clear} :
188
              (w_hitA) ? {29'b0,r_mask} :
189
                         {31'b0,r_front_buffer};
190
 
191
 
192
assign w_vint_on = i_vint_edge;  // falling edge detect
193
assign w_vint_x = ~r_vint_clear | i_vint_x;
194
 
195
assign w_int[0] = (r_mask[0]) ? 1'b0 : ~r_vint_x;
196
assign w_int[1] = 1'b0;
197
assign w_int[2] = (r_mask[2]) ? 1'b0 : i_vtx_int;
198
 
199
assign o_rstr  = r_rstr;
200
assign o_rd = r_rd;
201
assign o_ack = i_req;
202
 
203
assign o_video_start = r_video_start;
204
assign o_aa_en = r_aa_en;
205
assign o_fb0_offset = r_fb0_offset;
206
assign o_fb1_offset = r_fb1_offset;
207
assign o_color_mode = r_color_mode;
208
assign o_front_buffer = r_front_buffer;
209
assign o_fb_blend_en = r_fb_blend_en;
210
 
211
//////////////////////////////////
212
// always
213
//////////////////////////////////
214
 
215
always @(posedge clk_core or negedge rst_x) begin
216
    if (~rst_x) begin
217
        r_video_start <= 1'b0;
218
    end else begin
219
        if (w_hit0_w) begin
220
            if (i_be[0]) r_video_start   <= i_wd[0];
221
            if (i_be[1]) r_aa_en         <= i_wd[10:8];
222
            if (i_be[2]) r_fb_blend_en   <= i_wd[16];
223
        end
224
    end
225
end
226
 
227
// register holds 32-bit address
228
always @(posedge clk_core or negedge rst_x) begin
229
    if (~rst_x) begin
230
        r_fb0_offset <= 7'b0;
231
    end else begin
232
        if (w_hit1_w) begin
233
            if (i_be[2]) r_fb0_offset[4:0] <= i_wd[23:19];
234
            if (i_be[3]) r_fb0_offset[6:5] <= i_wd[25:24];
235
        end
236
    end
237
end
238
 
239
always @(posedge clk_core or negedge rst_x) begin
240
    if (~rst_x) begin
241
        r_fb1_offset <= 7'b0;
242
    end else begin
243
        if (w_hit2_w) begin
244
            if (i_be[2]) r_fb1_offset[4:0] <= i_wd[23:19];
245
            if (i_be[3]) r_fb1_offset[6:5] <= i_wd[25:24];
246
        end
247
    end
248
end
249
 
250
always @(posedge clk_core or negedge rst_x) begin
251
    if (~rst_x) begin
252
        r_color_mode <= 2'b0;
253
    end else begin
254
        if (w_hit5_w) begin
255
            if (i_be[0]) r_color_mode   <= i_wd[1:0];
256
        end
257
    end
258
end
259
 
260
always @(posedge clk_core or negedge rst_x) begin
261
    if (~rst_x) begin
262
        r_vint_clear <= 1'b0;
263
    end else begin
264
        if (w_hit9_w) begin
265
            if (i_be[0]) r_vint_clear <= i_wd[0];
266
        end else if (w_vint_on) begin
267
            r_vint_clear <= 1'b1;
268
        end
269
    end
270
end
271
 
272
always @(posedge clk_core or negedge rst_x) begin
273
    if (~rst_x) begin
274
        r_mask <= 2'b11;
275
    end else begin
276
        if (w_hitA_w) begin
277
            if (i_be[0]) r_mask   <= i_wd[1:0];
278
        end
279
    end
280
end
281
 
282
always @(posedge clk_core or negedge rst_x) begin
283
    if (~rst_x) begin
284
        r_front_buffer <= 1'b0;
285
    end else begin
286
        if (w_hitB_w) begin
287
            if (i_be[0]) r_front_buffer   <= i_wd[0];
288
        end
289
    end
290
end
291
 
292
 
293
always @(posedge clk_core) begin
294
    r_rd <= w_rd;
295
end
296
 
297
always @(posedge clk_core or negedge rst_x) begin
298
    if (~rst_x) begin
299
        r_rstr <= 1'b0;
300
    end else begin
301
        r_rstr <= w_rstr;
302
    end
303
end
304
 
305
 
306
always @(posedge clk_core or negedge rst_x) begin
307
    if (~rst_x) begin
308
        r_vint_x <= 1'b1;
309
    end else begin
310
        r_vint_x <= w_vint_x;
311
    end
312
end
313
 
314
always @(posedge clk_core or negedge rst_x) begin
315
    if (~rst_x) begin
316
        o_int <= 1'b0;
317
    end else begin
318
        o_int <= |w_int;
319
    end
320
end
321
 
322
endmodule

powered by: WebSVN 2.1.0

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