OpenCores
URL https://opencores.org/ocsvn/395_vgs/395_vgs/trunk

Subversion Repositories 395_vgs

[/] [395_vgs/] [trunk/] [hdl/] [gpuchip.vhd] - Blame information for rev 18

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

Line No. Rev Author Line
1 2 zuofu
--ECE395 GPU:
2
--Top Level HDL
3
--=====================================================
4
--Designed by:
5
--Zuofu Cheng
6
--James Cavanaugh
7
--Eric Sands
8
--
9
--of the University of Illinois at Urbana Champaign
10
--under the direction of Dr. Lippold Haken
11
--====================================================
12 10 zuofu
--
13
--Heavily based off of HDL examples provided by XESS Corporation
14
--www.xess.com
15
--
16 2 zuofu
--Based in part on Doug Hodson's work which in turn
17
--was based off of the XSOC from Gray Research LLC.
18
--                                                                              
19 10 zuofu
--
20 2 zuofu
--release under the GNU General Public License
21
--and kindly hosted by www.opencores.org
22
 
23
 
24
library IEEE;
25
use IEEE.std_logic_1164.all;
26
use IEEE.std_logic_unsigned.all;
27
use IEEE.numeric_std.all;
28
use WORK.common.all;
29
use WORK.xsasdram.all;
30
use WORK.sdram.all;
31 10 zuofu
use WORK.vga_pckg.all;
32 17 zuofu
use WORK.gpu_core_pckg.all;
33 2 zuofu
 
34
entity gpuChip is
35
 
36
        generic(
37
      FREQ            :       natural                       := 50_000;  -- frequency of operation in KHz
38
      PIPE_EN         :       boolean                       := true;  -- enable fast, pipelined SDRAM operation
39
      MULTIPLE_ACTIVE_ROWS:   boolean                                                           := true;  -- if true, allow an active row in each bank
40 10 zuofu
                CLK_DIV         :       real                                                               := 1.0;  -- SDRAM Clock div
41 2 zuofu
                NROWS           :       natural                       := 4096;  -- number of rows in the SDRAM
42
      NCOLS           :       natural                       := 512;  -- number of columns in each SDRAM row
43
        SADDR_WIDTH      :              natural                                                         := 12;
44 10 zuofu
                DATA_WIDTH      :       natural                                                                 := 16;  -- SDRAM databus width
45
                ADDR_WIDTH      :       natural                                                                 := 23;  -- host-side address width
46 12 zuofu
                VGA_CLK_DIV     :       natural                                                                 := 4;  -- pixel clock = FREQ / CLK_DIV
47 10 zuofu
        PIXEL_WIDTH     :       natural                                                                 := 8;  -- width of a pixel in memory
48
        NUM_RGB_BITS    :       natural                                                                 := 2;  -- #bits in each R,G,B component of a pixel
49 12 zuofu
        PIXELS_PER_LINE :       natural                                                                 := 320; -- width of image in pixels
50
        LINES_PER_FRAME :       natural                                                                 := 240;  -- height of image in scanlines
51 10 zuofu
        FIT_TO_SCREEN   :       boolean                                                                 := true;  -- adapt video timing to fit image width x             
52 15 cavanaug
           PORT_TIME_SLOTS :       std_logic_vector(15 downto 0) := "0000111100001111"
53 2 zuofu
   );
54
 
55
        port(
56
                pin_clkin   : in std_logic;       -- main clock input from external clock source
57
                pin_ce_n    : out std_logic;      -- Flash RAM chip-enable
58
                pin_pushbtn : in std_logic;
59
 
60
                -- vga port connections
61
                pin_red     : out std_logic_vector(1 downto 0);
62
                pin_green   : out std_logic_vector(1 downto 0);
63
                pin_blue    : out std_logic_vector(1 downto 0);
64
                pin_hsync_n : out std_logic;
65
                pin_vsync_n : out std_logic;
66
 
67 17 zuofu
                -- SRAM Cache connections
68
                pin_cData  : inout std_logic_vector(15 downto 0);        -- data bus to Cache
69
                pin_cAddr  : out std_logic_vector(14 downto 0);          -- Cache address bus
70
                pin_cwrite : out std_logic;
71
                pin_cread  : out std_logic;
72
 
73 2 zuofu
                -- SDRAM pin connections
74
                pin_sclkfb : in std_logic;                   -- feedback SDRAM clock with PCB delays
75
                pin_sclk   : out std_logic;                  -- clock to SDRAM
76
                pin_cke    : out std_logic;                  -- SDRAM clock-enable
77
                pin_cs_n   : out std_logic;                  -- SDRAM chip-select
78
                pin_ras_n  : out std_logic;                  -- SDRAM RAS
79
                pin_cas_n  : out std_logic;                  -- SDRAM CAS
80
                pin_we_n   : out std_logic;                  -- SDRAM write-enable
81
                pin_ba     : out std_logic_vector( 1 downto 0);      -- SDRAM bank-address
82
                pin_sAddr  : out std_logic_vector(11 downto 0);      -- SDRAM address bus
83
                pin_sData  : inout std_logic_vector (16-1 downto 0);  -- data bus to SDRAM
84
                pin_dqmh   : out std_logic;                  -- SDRAM DQMH
85
                pin_dqml   : out std_logic                   -- SDRAM DQML                      
86
        );
87
end gpuChip;
88
 
89
architecture arch of gpuChip is
90
 
91
        constant YES:   std_logic := '1';
92
        constant NO:    std_logic := '0';
93
        constant HI:    std_logic := '1';
94
        constant LO:    std_logic := '0';
95
 
96
        --internal signals
97 10 zuofu
   signal sysClk                                                                                : std_logic;  -- system clock
98
   signal sysReset                                                                              : std_logic;  -- system reset
99 2 zuofu
 
100
         --Application Side Signals for the DualPort Controller
101 10 zuofu
        signal rst_i                                                                                    : std_logic;    --tied reset signal
102 2 zuofu
   signal opBegun0, opBegun1                       : std_logic;  -- read/write operation started indicator
103
   signal earlyOpBegun0, earlyOpBegun1          : std_logic;  -- read/write operation started indicator
104
   signal rdPending0, rdPending1                                           : std_logic;  -- read operation pending in SDRAM pipeline indicator
105
   signal done0, done1                               : std_logic;  -- read/write operation complete indicator
106
   signal rdDone0, rdDone1                                     : std_logic;  -- read operation complete indicator
107
   signal hAddr0, hAddr1                                 : std_logic_vector(ADDR_WIDTH-1 downto 0);  -- host-side address bus
108
   signal hDIn0, hDIn1                                    : std_logic_vector(DATA_WIDTH-1 downto 0);  -- host-side data to SDRAM
109
   signal hDOut0, hDOut1                                                      : std_logic_vector(DATA_WIDTH-1 downto 0);  -- host-side data from SDRAM
110
   signal rd0, rd1                                      : std_logic;  -- host-side read control signal
111
   signal wr0, wr1                              : std_logic;  -- host-side write control signal
112 10 zuofu
 
113 2 zuofu
        -- SDRAM host side signals
114 10 zuofu
        signal sdram_bufclk                                                                     : std_logic;    -- buffered input (non-DLL) clock
115
        signal sdram_clk1x                                                                      : std_logic;    -- internal master clock signal
116
        signal sdram_clk2x                                                                      : std_logic;            -- doubled clock
117
        signal sdram_lock                                                                       : std_logic;    -- SDRAM clock DLL lock indicator
118
        signal sdram_rst                                                                        : std_logic;    -- internal reset signal
119
        signal sdram_rd                                                                         : std_logic;    -- host-side read control signal
120
        signal sdram_wr                                                                         : std_logic;    -- host-side write control signal
121
        signal sdram_earlyOpBegun                                                       : std_logic;
122
        signal sdram_OpBegun                                                                    : std_logic;
123
        signal sdram_rdPending                                                          : std_logic;
124
        signal sdram_done                                                                       : std_logic;    -- SDRAM operation complete indicator
125
        signal sdram_rdDone                                                                     : std_logic;            -- host-side read completed signal
126
        signal sdram_hAddr                                                                      : std_logic_vector(ADDR_WIDTH -1 downto 0);  -- host address bus
127
        signal sdram_hDIn                                                                       : std_logic_vector(DATA_WIDTH -1 downto 0);      -- host-side data to SDRAM
128
        signal sdram_hDOut                                                                      : std_logic_vector(DATA_WIDTH -1 downto 0);      -- host-side data from SDRAM
129
        signal sdram_status                                                                     : std_logic_vector(3 downto 0);  -- SDRAM controller status
130 2 zuofu
 
131 10 zuofu
 
132
        -- VGA related signals
133
        signal eof                                                                              : std_logic;      -- end-of-frame signal from VGA controller
134
   signal full                                                                                          : std_logic;      -- indicates when the VGA pixel buffer is full
135
   signal vga_address                                                           : unsigned(ADDR_WIDTH-1 downto 0);  -- SDRAM address counter 
136 13 zuofu
        signal pixels                                                                                   : std_logic_vector(DATA_WIDTH-1 downto 0);
137 10 zuofu
        signal rst_n                                                                                    : std_logic;            --VGA reset (active low)
138 13 zuofu
        signal drawframe                                                                                : std_logic;  -- flag to indicate whether we are drawing current frame  
139
 
140 2 zuofu
--------------------------------------------------------------------------------------------------------------
141
-- Beginning of Submodules
142
-- All instances of submodules and signals associated with them
143
-- are declared within. Signals not directly associated with
144
-- submodules are declared elsewhere.
145
--  
146
--------------------------------------------------------------------------------------------------------------
147
 
148
begin
149
 ------------------------------------------------------------------------
150
 -- Instantiate the dualport module
151
 ------------------------------------------------------------------------
152
  u1 : dualport
153
    generic map(
154
      PIPE_EN         => PIPE_EN,
155
      PORT_TIME_SLOTS => PORT_TIME_SLOTS,
156
      DATA_WIDTH      => DATA_WIDTH,
157
      HADDR_WIDTH     => ADDR_WIDTH
158
      )
159
    port map(
160
      clk             => sdram_clk1x,
161
 
162
                -- Memory Port 0 connections
163
                rst0            => rst_i,
164
      rd0             => rd0,
165
      wr0             => wr0,
166
      rdPending0      => rdPending0,
167
      opBegun0        => opBegun0,
168
      earlyOpBegun0   => earlyOpBegun0,
169
      rdDone0         => rdDone0,
170
      done0           => done0,
171
      hAddr0          => hAddr0,
172
      hDIn0           => hDIn0,
173
      hDOut0          => hDOut0,
174
      status0         => open,
175
 
176
                -- Memory Port 1 connections
177
      rst1            => rst_i,
178
      rd1             => rd1,
179
      wr1             => wr1,
180
      rdPending1      => rdPending1,
181
      opBegun1        => opBegun1,
182
      earlyOpBegun1   => earlyOpBegun1,
183
      rdDone1         => rdDone1,
184
      done1           => done1,
185
      hAddr1          => hAddr1,
186
      hDIn1           => hDIn1,
187
      hDOut1          => hDOut1,
188
      status1         => open,
189
      -- connections to the SDRAM controller
190
      rst             => sdram_rst,
191
      rd              => sdram_rd,
192
      wr              => sdram_wr,
193
      rdPending       => sdram_rdPending,
194
      opBegun         => sdram_opBegun,
195
      earlyOpBegun    => sdram_earlyOpBegun,
196
      rdDone          => sdram_rdDone,
197
      done            => sdram_done,
198
      hAddr           => sdram_hAddr,
199
      hDIn            => sdram_hDIn,
200
      hDOut           => sdram_hDOut,
201
      status          => sdram_status
202
      );
203
 
204
 
205
  ------------------------------------------------------------------------
206
  -- Instantiate the SDRAM controller that connects to the dualport
207
  -- module and interfaces to the external SDRAM chip.
208
  ------------------------------------------------------------------------
209
  u2 : xsaSDRAMCntl
210
    generic map(
211
      FREQ                                        => FREQ,
212
      CLK_DIV                                     => CLK_DIV,
213
      PIPE_EN                        => PIPE_EN,
214
      MULTIPLE_ACTIVE_ROWS   => MULTIPLE_ACTIVE_ROWS,
215
                DATA_WIDTH                        => DATA_WIDTH,
216
      NROWS                               => NROWS,
217
      NCOLS                               => NCOLS,
218
      HADDR_WIDTH                         => ADDR_WIDTH,
219
      SADDR_WIDTH                         => SADDR_WIDTH
220
      )
221
    port map(
222
                --Dual Port Controller (Host) Side
223
      clk          => pin_clkin,             -- master clock from external clock source (unbuffered)
224
      bufclk       => sdram_bufclk,                -- buffered master clock output
225
      clk1x        => sdram_clk1x,                 -- synchronized master clock (accounts for delays to external SDRAM)
226
      clk2x        => sdram_clk2x,              -- synchronized doubled master clock
227
      lock         => sdram_lock,                       -- DLL lock indicator
228
      rst          => sdram_rst,                        -- reset
229
      rd           => sdram_rd,                         -- host-side SDRAM read control from dualport
230
      wr           => sdram_wr,                         -- host-side SDRAM write control from dualport
231
      earlyOpBegun => sdram_earlyOpBegun,               -- early indicator that memory operation has begun 
232
                opBegun      => sdram_opBegun,          -- indicates memory read/write has begun
233
                rdPending    => sdram_rdPending,                -- read operation to SDRAM is in progress
234
      done         => sdram_done,                       -- indicates SDRAM memory read or write operation is done
235
      rdDone       => sdram_rdDone,                     -- indicates SDRAM memory read operation is done
236
      hAddr        => sdram_hAddr,           -- host-side address from dualport to SDRAM
237
      hDIn         => sdram_hDIn,            -- test data pattern from dualport to SDRAM
238
      hDOut        => sdram_hDOut,           -- SDRAM data output to dualport
239
      status       => sdram_status,          -- SDRAM controller state (for diagnostics)
240
 
241
           --SDRAM (External) Side
242
                sclkfb       => pin_sclkfb,           -- clock feedback with added external PCB delays
243
      sclk         => pin_sclk,             -- synchronized clock to external SDRAM
244
      cke          => pin_cke,              -- SDRAM clock enable
245
      cs_n         => pin_cs_n,             -- SDRAM chip-select
246
      ras_n        => pin_ras_n,            -- SDRAM RAS
247
      cas_n        => pin_cas_n,            -- SDRAM CAS
248
      we_n         => pin_we_n,             -- SDRAM write-enable
249
      ba           => pin_ba,               -- SDRAM bank address
250
      sAddr        => pin_sAddr,            -- SDRAM address
251
      sData        => pin_sData,            -- SDRAM databus
252
      dqmh         => pin_dqmh,             -- SDRAM DQMH
253
      dqml         => pin_dqml              -- SDRAM DQML
254
      );
255
 
256 15 cavanaug
------------------------------------------------------------------------------------------------------------
257
-- instance of vga
258
------------------------------------------------------------------------------------------------------------
259
 
260 2 zuofu
 
261 10 zuofu
        u3 : vga
262
    generic map (
263
      FREQ            => FREQ,
264
      CLK_DIV         => VGA_CLK_DIV,
265
      PIXEL_WIDTH     => PIXEL_WIDTH,
266
      PIXELS_PER_LINE => PIXELS_PER_LINE,
267
      LINES_PER_FRAME => LINES_PER_FRAME,
268
      NUM_RGB_BITS    => NUM_RGB_BITS,
269
      FIT_TO_SCREEN   => FIT_TO_SCREEN
270
      )
271
    port map (
272
      rst             => rst_i,
273
      clk             => sdram_clk1x,   -- use the resync'ed master clock so VGA generator is in sync with SDRAM
274
      wr              => rdDone0,       -- write to pixel buffer when the data read from SDRAM is available
275 13 zuofu
      pixel_data_in   => pixels,                 -- pixel data from SDRAM
276 10 zuofu
      full            => full,          -- indicates when the pixel buffer is full
277
      eof             => eof,           -- indicates when the VGA generator has finished a video frame
278
      r               => pin_red,       -- RGB components (output)
279
      g               => pin_green,
280
      b               => pin_blue,
281
      hsync_n         => pin_hsync_n,   -- horizontal sync
282
      vsync_n         => pin_vsync_n,   -- vertical sync
283
      blank           => open
284
      );
285 15 cavanaug
 
286 17 zuofu
 
287 15 cavanaug
------------------------------------------------------------------------------------------------------------
288
-- instance of fill-unit
289
------------------------------------------------------------------------------------------------------------
290
 
291 17 zuofu
--  u4: fillunit
292
--  generic map(
293
--    FREQ              => FREQ, 
294
--    DATA_WIDTH    => DATA_WIDTH,
295
--    HADDR_WIDTH   => ADDR_WIDTH
296
--    )
297
--  port map(
298
--    clk           => sdram_clk1x,      -- master clock
299
--       reset                  => sysReset,             -- reset for this entity
300
--       rd1           => rd1,                           -- initiate read operation
301
--    wr1           => wr1,                              -- initiate write operation
302
--    opBegun              => opBegun1,          --operation recieved
303
--       done1          => done1,                                -- read or write operation is done
304
--    hAddr1        => hAddr1,              -- address to SDRAM
305
--    hDIn1         => hDIn1,               -- data to dualport to SDRAM
306
--    hDOut1        => hDOut1               -- data from dualport to SDRAM
307
--    );
308
--
309
 
310
        u5: gpu_core
311
        generic map(
312 15 cavanaug
    FREQ                => FREQ,
313
    DATA_WIDTH    => DATA_WIDTH,
314
    HADDR_WIDTH   => ADDR_WIDTH
315
    )
316 17 zuofu
  port map (
317
    clk                         =>sdram_clk1x,
318
         rst                            =>sysReset,
319
         rd1           =>rd1,
320
    wr1           =>wr1,
321
    opBegun       =>opBegun1,
322
    done1         =>done1,
323
         rddone1                        =>rddone1,
324
    hAddr1        =>hAddr1,
325
    hDIn1         =>hDIn1,
326
    hDOut1        =>hDOut1,
327
         CacheDIn               =>pin_cData,
328
         CacheAddr              =>pin_cAddr,
329
         cread                  =>pin_cread,
330
         cwrite                 =>pin_cwrite
331
         );
332 15 cavanaug
 
333 2 zuofu
--------------------------------------------------------------------------------------------------------------
334
-- End of Submodules
335
--------------------------------------------------------------------------------------------------------------
336
-- Begin Top Level Module
337 10 zuofu
 
338
-- connect internal signals     
339 2 zuofu
        rst_i <= sysReset;
340 13 zuofu
        pin_ce_n <= '1';                                                  -- disable Flash RAM
341
        rd0 <= ((not full) and drawframe); -- negate the full signal for use in controlling the SDRAM read operation
342 17 zuofu
        hDIn0 <= "0000000000000000"; -- don't need to write to port 0 (VGA Port)
343 10 zuofu
        wr0 <= '0';
344
        hAddr0 <= std_logic_vector(vga_address);
345 2 zuofu
 
346 13 zuofu
        -- Port0 is reserved for VGA
347 2 zuofu
 
348 13 zuofu
        pixels <= hDOut0 when drawframe = '1' else "00000000";
349
 
350 10 zuofu
   -- update the SDRAM address counter
351
   process(sdram_clk1x)
352
   begin
353
     if rising_edge(sdram_clk1x) then
354
       if eof = YES then
355 13 zuofu
         drawframe <= not drawframe;                                     -- draw every other frame
356
                        vga_address <= "00000000000000000000000";  -- reset the address at the end of a video frame
357 10 zuofu
       elsif earlyOpBegun0 = YES then
358
         vga_address <= vga_address + 1;         -- go to the next address once the read of the current address has begun
359 13 zuofu
                 elsif drawframe = '0' then
360
                  vga_address <= vga_address + 1;               --if we're not drawing a frame, keep incrementing the address      
361
                 end if;
362 10 zuofu
     end if;
363
   end process;
364 2 zuofu
 
365 10 zuofu
        --process reset circuitry
366 2 zuofu
        process(sdram_bufclk)
367
        begin
368
                if (rising_edge(sdram_bufclk)) then
369
                        if sdram_lock='0' then
370
                                sysReset <= '1';     -- keep in reset until DLLs start up
371
                        else
372
                                --sysReset <= '0';
373
                                sysReset <= not pin_pushbtn;  -- push button will reset
374
                        end if;
375
                end if;
376
        end process;
377 10 zuofu
 
378 2 zuofu
 
379
end arch;

powered by: WebSVN 2.1.0

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