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 15

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 15 cavanaug
use WORK.fillunit_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
                -- SDRAM pin connections
68
                pin_sclkfb : in std_logic;                   -- feedback SDRAM clock with PCB delays
69
                pin_sclk   : out std_logic;                  -- clock to SDRAM
70
                pin_cke    : out std_logic;                  -- SDRAM clock-enable
71
                pin_cs_n   : out std_logic;                  -- SDRAM chip-select
72
                pin_ras_n  : out std_logic;                  -- SDRAM RAS
73
                pin_cas_n  : out std_logic;                  -- SDRAM CAS
74
                pin_we_n   : out std_logic;                  -- SDRAM write-enable
75
                pin_ba     : out std_logic_vector( 1 downto 0);      -- SDRAM bank-address
76
                pin_sAddr  : out std_logic_vector(11 downto 0);      -- SDRAM address bus
77
                pin_sData  : inout std_logic_vector (16-1 downto 0);  -- data bus to SDRAM
78
                pin_dqmh   : out std_logic;                  -- SDRAM DQMH
79
                pin_dqml   : out std_logic                   -- SDRAM DQML                      
80
        );
81
end gpuChip;
82
 
83
architecture arch of gpuChip is
84
 
85
        constant YES:   std_logic := '1';
86
        constant NO:    std_logic := '0';
87
        constant HI:    std_logic := '1';
88
        constant LO:    std_logic := '0';
89
 
90
        --internal signals
91 10 zuofu
   signal sysClk                                                                                : std_logic;  -- system clock
92
   signal sysReset                                                                              : std_logic;  -- system reset
93 2 zuofu
 
94
         --Application Side Signals for the DualPort Controller
95 10 zuofu
        signal rst_i                                                                                    : std_logic;    --tied reset signal
96 2 zuofu
   signal opBegun0, opBegun1                       : std_logic;  -- read/write operation started indicator
97
   signal earlyOpBegun0, earlyOpBegun1          : std_logic;  -- read/write operation started indicator
98
   signal rdPending0, rdPending1                                           : std_logic;  -- read operation pending in SDRAM pipeline indicator
99
   signal done0, done1                               : std_logic;  -- read/write operation complete indicator
100
   signal rdDone0, rdDone1                                     : std_logic;  -- read operation complete indicator
101
   signal hAddr0, hAddr1                                 : std_logic_vector(ADDR_WIDTH-1 downto 0);  -- host-side address bus
102
   signal hDIn0, hDIn1                                    : std_logic_vector(DATA_WIDTH-1 downto 0);  -- host-side data to SDRAM
103
   signal hDOut0, hDOut1                                                      : std_logic_vector(DATA_WIDTH-1 downto 0);  -- host-side data from SDRAM
104
   signal rd0, rd1                                      : std_logic;  -- host-side read control signal
105
   signal wr0, wr1                              : std_logic;  -- host-side write control signal
106 10 zuofu
 
107 2 zuofu
        -- SDRAM host side signals
108 10 zuofu
        signal sdram_bufclk                                                                     : std_logic;    -- buffered input (non-DLL) clock
109
        signal sdram_clk1x                                                                      : std_logic;    -- internal master clock signal
110
        signal sdram_clk2x                                                                      : std_logic;            -- doubled clock
111
        signal sdram_lock                                                                       : std_logic;    -- SDRAM clock DLL lock indicator
112
        signal sdram_rst                                                                        : std_logic;    -- internal reset signal
113
        signal sdram_rd                                                                         : std_logic;    -- host-side read control signal
114
        signal sdram_wr                                                                         : std_logic;    -- host-side write control signal
115
        signal sdram_earlyOpBegun                                                       : std_logic;
116
        signal sdram_OpBegun                                                                    : std_logic;
117
        signal sdram_rdPending                                                          : std_logic;
118
        signal sdram_done                                                                       : std_logic;    -- SDRAM operation complete indicator
119
        signal sdram_rdDone                                                                     : std_logic;            -- host-side read completed signal
120
        signal sdram_hAddr                                                                      : std_logic_vector(ADDR_WIDTH -1 downto 0);  -- host address bus
121
        signal sdram_hDIn                                                                       : std_logic_vector(DATA_WIDTH -1 downto 0);      -- host-side data to SDRAM
122
        signal sdram_hDOut                                                                      : std_logic_vector(DATA_WIDTH -1 downto 0);      -- host-side data from SDRAM
123
        signal sdram_status                                                                     : std_logic_vector(3 downto 0);  -- SDRAM controller status
124 2 zuofu
 
125 10 zuofu
 
126
        -- VGA related signals
127
        signal eof                                                                              : std_logic;      -- end-of-frame signal from VGA controller
128
   signal full                                                                                          : std_logic;      -- indicates when the VGA pixel buffer is full
129
   signal vga_address                                                           : unsigned(ADDR_WIDTH-1 downto 0);  -- SDRAM address counter 
130 13 zuofu
        signal pixels                                                                                   : std_logic_vector(DATA_WIDTH-1 downto 0);
131 10 zuofu
        signal rst_n                                                                                    : std_logic;            --VGA reset (active low)
132 13 zuofu
        signal drawframe                                                                                : std_logic;  -- flag to indicate whether we are drawing current frame  
133
 
134 2 zuofu
--------------------------------------------------------------------------------------------------------------
135
-- Beginning of Submodules
136
-- All instances of submodules and signals associated with them
137
-- are declared within. Signals not directly associated with
138
-- submodules are declared elsewhere.
139
--  
140
--------------------------------------------------------------------------------------------------------------
141
 
142
begin
143
 ------------------------------------------------------------------------
144
 -- Instantiate the dualport module
145
 ------------------------------------------------------------------------
146
  u1 : dualport
147
    generic map(
148
      PIPE_EN         => PIPE_EN,
149
      PORT_TIME_SLOTS => PORT_TIME_SLOTS,
150
      DATA_WIDTH      => DATA_WIDTH,
151
      HADDR_WIDTH     => ADDR_WIDTH
152
      )
153
    port map(
154
      clk             => sdram_clk1x,
155
 
156
                -- Memory Port 0 connections
157
                rst0            => rst_i,
158
      rd0             => rd0,
159
      wr0             => wr0,
160
      rdPending0      => rdPending0,
161
      opBegun0        => opBegun0,
162
      earlyOpBegun0   => earlyOpBegun0,
163
      rdDone0         => rdDone0,
164
      done0           => done0,
165
      hAddr0          => hAddr0,
166
      hDIn0           => hDIn0,
167
      hDOut0          => hDOut0,
168
      status0         => open,
169
 
170
                -- Memory Port 1 connections
171
      rst1            => rst_i,
172
      rd1             => rd1,
173
      wr1             => wr1,
174
      rdPending1      => rdPending1,
175
      opBegun1        => opBegun1,
176
      earlyOpBegun1   => earlyOpBegun1,
177
      rdDone1         => rdDone1,
178
      done1           => done1,
179
      hAddr1          => hAddr1,
180
      hDIn1           => hDIn1,
181
      hDOut1          => hDOut1,
182
      status1         => open,
183
      -- connections to the SDRAM controller
184
      rst             => sdram_rst,
185
      rd              => sdram_rd,
186
      wr              => sdram_wr,
187
      rdPending       => sdram_rdPending,
188
      opBegun         => sdram_opBegun,
189
      earlyOpBegun    => sdram_earlyOpBegun,
190
      rdDone          => sdram_rdDone,
191
      done            => sdram_done,
192
      hAddr           => sdram_hAddr,
193
      hDIn            => sdram_hDIn,
194
      hDOut           => sdram_hDOut,
195
      status          => sdram_status
196
      );
197
 
198
 
199
  ------------------------------------------------------------------------
200
  -- Instantiate the SDRAM controller that connects to the dualport
201
  -- module and interfaces to the external SDRAM chip.
202
  ------------------------------------------------------------------------
203
  u2 : xsaSDRAMCntl
204
    generic map(
205
      FREQ                                        => FREQ,
206
      CLK_DIV                                     => CLK_DIV,
207
      PIPE_EN                        => PIPE_EN,
208
      MULTIPLE_ACTIVE_ROWS   => MULTIPLE_ACTIVE_ROWS,
209
                DATA_WIDTH                        => DATA_WIDTH,
210
      NROWS                               => NROWS,
211
      NCOLS                               => NCOLS,
212
      HADDR_WIDTH                         => ADDR_WIDTH,
213
      SADDR_WIDTH                         => SADDR_WIDTH
214
      )
215
    port map(
216
                --Dual Port Controller (Host) Side
217
      clk          => pin_clkin,             -- master clock from external clock source (unbuffered)
218
      bufclk       => sdram_bufclk,                -- buffered master clock output
219
      clk1x        => sdram_clk1x,                 -- synchronized master clock (accounts for delays to external SDRAM)
220
      clk2x        => sdram_clk2x,              -- synchronized doubled master clock
221
      lock         => sdram_lock,                       -- DLL lock indicator
222
      rst          => sdram_rst,                        -- reset
223
      rd           => sdram_rd,                         -- host-side SDRAM read control from dualport
224
      wr           => sdram_wr,                         -- host-side SDRAM write control from dualport
225
      earlyOpBegun => sdram_earlyOpBegun,               -- early indicator that memory operation has begun 
226
                opBegun      => sdram_opBegun,          -- indicates memory read/write has begun
227
                rdPending    => sdram_rdPending,                -- read operation to SDRAM is in progress
228
      done         => sdram_done,                       -- indicates SDRAM memory read or write operation is done
229
      rdDone       => sdram_rdDone,                     -- indicates SDRAM memory read operation is done
230
      hAddr        => sdram_hAddr,           -- host-side address from dualport to SDRAM
231
      hDIn         => sdram_hDIn,            -- test data pattern from dualport to SDRAM
232
      hDOut        => sdram_hDOut,           -- SDRAM data output to dualport
233
      status       => sdram_status,          -- SDRAM controller state (for diagnostics)
234
 
235
           --SDRAM (External) Side
236
                sclkfb       => pin_sclkfb,           -- clock feedback with added external PCB delays
237
      sclk         => pin_sclk,             -- synchronized clock to external SDRAM
238
      cke          => pin_cke,              -- SDRAM clock enable
239
      cs_n         => pin_cs_n,             -- SDRAM chip-select
240
      ras_n        => pin_ras_n,            -- SDRAM RAS
241
      cas_n        => pin_cas_n,            -- SDRAM CAS
242
      we_n         => pin_we_n,             -- SDRAM write-enable
243
      ba           => pin_ba,               -- SDRAM bank address
244
      sAddr        => pin_sAddr,            -- SDRAM address
245
      sData        => pin_sData,            -- SDRAM databus
246
      dqmh         => pin_dqmh,             -- SDRAM DQMH
247
      dqml         => pin_dqml              -- SDRAM DQML
248
      );
249
 
250 15 cavanaug
------------------------------------------------------------------------------------------------------------
251
-- instance of vga
252
------------------------------------------------------------------------------------------------------------
253
 
254 2 zuofu
 
255 10 zuofu
        u3 : vga
256
    generic map (
257
      FREQ            => FREQ,
258
      CLK_DIV         => VGA_CLK_DIV,
259
      PIXEL_WIDTH     => PIXEL_WIDTH,
260
      PIXELS_PER_LINE => PIXELS_PER_LINE,
261
      LINES_PER_FRAME => LINES_PER_FRAME,
262
      NUM_RGB_BITS    => NUM_RGB_BITS,
263
      FIT_TO_SCREEN   => FIT_TO_SCREEN
264
      )
265
    port map (
266
      rst             => rst_i,
267
      clk             => sdram_clk1x,   -- use the resync'ed master clock so VGA generator is in sync with SDRAM
268
      wr              => rdDone0,       -- write to pixel buffer when the data read from SDRAM is available
269 13 zuofu
      pixel_data_in   => pixels,                 -- pixel data from SDRAM
270 10 zuofu
      full            => full,          -- indicates when the pixel buffer is full
271
      eof             => eof,           -- indicates when the VGA generator has finished a video frame
272
      r               => pin_red,       -- RGB components (output)
273
      g               => pin_green,
274
      b               => pin_blue,
275
      hsync_n         => pin_hsync_n,   -- horizontal sync
276
      vsync_n         => pin_vsync_n,   -- vertical sync
277
      blank           => open
278
      );
279 15 cavanaug
 
280
------------------------------------------------------------------------------------------------------------
281
-- instance of fill-unit
282
------------------------------------------------------------------------------------------------------------
283
 
284
  u4: fillunit
285
  generic map(
286
    FREQ                => FREQ,
287
    DATA_WIDTH    => DATA_WIDTH,
288
    HADDR_WIDTH   => ADDR_WIDTH
289
    )
290
  port map(
291
    clk           => sdram_clk1x,      -- master clock
292
         reset                  => sysReset,             -- reset for this entity
293
         rd1           => rd1,                           -- initiate read operation
294
    wr1           => wr1,                                -- initiate write operation
295
    opBegun                => opBegun1,          --operation recieved
296
         done1          => done1,                                -- read or write operation is done
297
    hAddr1        => hAddr1,                -- address to SDRAM
298
    hDIn1         => hDIn1,                 -- data to dualport to SDRAM
299
    hDOut1        => hDOut1                 -- data from dualport to SDRAM
300
    );
301
 
302
 
303
 
304
 
305 2 zuofu
--------------------------------------------------------------------------------------------------------------
306
-- End of Submodules
307
--------------------------------------------------------------------------------------------------------------
308
-- Begin Top Level Module
309 10 zuofu
 
310
-- connect internal signals     
311 2 zuofu
        rst_i <= sysReset;
312 13 zuofu
        pin_ce_n <= '1';                                                  -- disable Flash RAM
313
        rd0 <= ((not full) and drawframe); -- negate the full signal for use in controlling the SDRAM read operation
314
        hDIn0 <= "0000000000000000000000"; -- don't need to write to port 0 (VGA Port)
315 10 zuofu
        wr0 <= '0';
316
        hAddr0 <= std_logic_vector(vga_address);
317 2 zuofu
 
318 13 zuofu
        -- Port0 is reserved for VGA
319 2 zuofu
 
320 13 zuofu
        pixels <= hDOut0 when drawframe = '1' else "00000000";
321
 
322 10 zuofu
   -- update the SDRAM address counter
323
   process(sdram_clk1x)
324
   begin
325
     if rising_edge(sdram_clk1x) then
326
       if eof = YES then
327 13 zuofu
         drawframe <= not drawframe;                                     -- draw every other frame
328
                        vga_address <= "00000000000000000000000";  -- reset the address at the end of a video frame
329 10 zuofu
       elsif earlyOpBegun0 = YES then
330
         vga_address <= vga_address + 1;         -- go to the next address once the read of the current address has begun
331 13 zuofu
                 elsif drawframe = '0' then
332
                  vga_address <= vga_address + 1;               --if we're not drawing a frame, keep incrementing the address      
333
                 end if;
334 10 zuofu
     end if;
335
   end process;
336 2 zuofu
 
337 10 zuofu
        --process reset circuitry
338 2 zuofu
        process(sdram_bufclk)
339
        begin
340
                if (rising_edge(sdram_bufclk)) then
341
                        if sdram_lock='0' then
342
                                sysReset <= '1';     -- keep in reset until DLLs start up
343
                        else
344
                                --sysReset <= '0';
345
                                sysReset <= not pin_pushbtn;  -- push button will reset
346
                        end if;
347
                end if;
348
        end process;
349 10 zuofu
 
350 2 zuofu
 
351
end arch;

powered by: WebSVN 2.1.0

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