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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [demo/] [c2sb_demo.vhdl] - Blame information for rev 73

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

Line No. Rev Author Line
1 46 ja_rd
--##############################################################################
2 2 ja_rd
-- ION MIPS-compatible CPU demo on Terasic DE-1 Cyclone-II starter board
3 46 ja_rd
--##############################################################################
4 2 ja_rd
-- This module is little more than a wrapper around the CPU and its memories.
5 46 ja_rd
--##############################################################################
6 2 ja_rd
 
7
library ieee;
8
use ieee.std_logic_1164.all;
9
use ieee.std_logic_arith.all;
10
use ieee.std_logic_unsigned.all;
11
 
12
-- FPGA i/o for Terasic DE-1 board
13
-- (Many of the board's i/o devices will go unused in this demo)
14
entity c2sb_demo is
15 59 ja_rd
    port (
16 2 ja_rd
        -- ***** Clocks
17
        clk_50MHz     : in std_logic;
18
 
19
        -- ***** Flash 4MB
20
        flash_addr    : out std_logic_vector(21 downto 0);
21
        flash_data    : in std_logic_vector(7 downto 0);
22
        flash_oe_n    : out std_logic;
23
        flash_we_n    : out std_logic;
24
        flash_reset_n : out std_logic;
25
 
26
        -- ***** SRAM 256K x 16
27
        sram_addr     : out std_logic_vector(17 downto 0);
28
        sram_data     : inout std_logic_vector(15 downto 0);
29
        sram_oe_n     : out std_logic;
30
        sram_ub_n     : out std_logic;
31 59 ja_rd
        sram_lb_n     : out std_logic;
32 2 ja_rd
        sram_ce_n     : out std_logic;
33 59 ja_rd
        sram_we_n     : out std_logic;
34 2 ja_rd
 
35
        -- ***** RS-232
36
        rxd           : in std_logic;
37
        txd           : out std_logic;
38
 
39
        -- ***** Switches and buttons
40
        switches      : in std_logic_vector(9 downto 0);
41
        buttons       : in std_logic_vector(3 downto 0);
42
 
43
        -- ***** Quad 7-seg displays
44
        hex0          : out std_logic_vector(0 to 6);
45
        hex1          : out std_logic_vector(0 to 6);
46
        hex2          : out std_logic_vector(0 to 6);
47
        hex3          : out std_logic_vector(0 to 6);
48
 
49
        -- ***** Leds
50
        red_leds      : out std_logic_vector(9 downto 0);
51
        green_leds    : out std_logic_vector(7 downto 0);
52
 
53
        -- ***** SD Card
54
        sd_data       : in  std_logic;
55
        sd_cs         : out std_logic;
56
        sd_cmd        : out std_logic;
57 59 ja_rd
        sd_clk        : out std_logic
58 2 ja_rd
    );
59
end c2sb_demo;
60
 
61
architecture minimal of c2sb_demo is
62
 
63
 
64
--##############################################################################
65 59 ja_rd
--
66 2 ja_rd
 
67 46 ja_rd
constant SRAM_ADDR_SIZE : integer := 18;
68
 
69 2 ja_rd
--##############################################################################
70
-- RS232 interface signals
71
 
72
signal rx_rdy :             std_logic;
73
signal tx_rdy :             std_logic;
74
signal rs232_data_rx :      std_logic_vector(7 downto 0);
75
signal rs232_status :       std_logic_vector(7 downto 0);
76
signal data_io_out :        std_logic_vector(7 downto 0);
77
signal io_port :            std_logic_vector(7 downto 0);
78
signal read_rx :            std_logic;
79
signal write_tx :           std_logic;
80
 
81
 
82
--##############################################################################
83 63 ja_rd
-- I/O registers
84 2 ja_rd
 
85
 
86 63 ja_rd
signal sd_clk_reg :         std_logic;
87
signal sd_cs_reg :          std_logic;
88
signal sd_cmd_reg :         std_logic;
89
signal sd_do_reg :          std_logic;
90
 
91
 
92 59 ja_rd
-- CPU access to hex display
93 2 ja_rd
signal reg_display :        std_logic_vector(15 downto 0);
94
 
95
 
96
 
97
--##############################################################################
98
-- DE-1 board interface signals
99
 
100 59 ja_rd
-- Synchronization FF chain for asynchronous reset input
101
signal reset_sync :         std_logic_vector(2 downto 0);
102
 
103 2 ja_rd
-- Quad 7-segment display (non multiplexed) & LEDS
104
signal display_data :       std_logic_vector(15 downto 0);
105 59 ja_rd
signal reg_gleds :          std_logic_vector(7 downto 0);
106 2 ja_rd
 
107
-- Clock & reset signals
108
signal clk_1hz :            std_logic;
109
signal clk_master :         std_logic;
110
signal counter_1hz :        std_logic_vector(25 downto 0);
111
signal reset :              std_logic;
112
signal clk :                std_logic;
113
 
114
-- SD control signals
115
signal sd_in :              std_logic;
116
signal reg_sd_dout :        std_logic;
117
signal reg_sd_clk :         std_logic;
118
signal reg_sd_cs :          std_logic;
119
 
120 46 ja_rd
-- MPU interface signals
121 2 ja_rd
signal data_uart :          std_logic_vector(31 downto 0);
122
signal data_uart_status :   std_logic_vector(31 downto 0);
123
signal uart_tx_rdy :        std_logic := '1';
124
signal uart_rx_rdy :        std_logic := '1';
125
 
126 46 ja_rd
signal io_rd_data :         std_logic_vector(31 downto 0);
127
signal io_rd_addr :         std_logic_vector(31 downto 2);
128
signal io_wr_addr :         std_logic_vector(31 downto 2);
129
signal io_wr_data :         std_logic_vector(31 downto 0);
130
signal io_rd_vma :          std_logic;
131
signal io_byte_we :         std_logic_vector(3 downto 0);
132 2 ja_rd
 
133 46 ja_rd
signal mpu_sram_address :   std_logic_vector(SRAM_ADDR_SIZE downto 1);
134
signal mpu_sram_databus :   std_logic_vector(15 downto 0);
135
signal mpu_sram_byte_we_n : std_logic_vector(1 downto 0);
136
signal mpu_sram_oe_n :      std_logic;
137
 
138 59 ja_rd
-- Converts hex nibble to 7-segment
139
-- Segments ordered as "GFEDCBA"; '0' is ON, '1' is OFF
140
function nibble_to_7seg(nibble : std_logic_vector(3 downto 0))
141
                        return std_logic_vector is
142
begin
143
    case nibble is
144
    when X"0"       => return "0000001";
145
    when X"1"       => return "1001111";
146
    when X"2"       => return "0010010";
147
    when X"3"       => return "0000110";
148
    when X"4"       => return "1001100";
149
    when X"5"       => return "0100100";
150
    when X"6"       => return "0100000";
151
    when X"7"       => return "0001111";
152
    when X"8"       => return "0000000";
153
    when X"9"       => return "0000100";
154
    when X"a"       => return "0001000";
155
    when X"b"       => return "1100000";
156
    when X"c"       => return "0110001";
157
    when X"d"       => return "1000010";
158
    when X"e"       => return "0110000";
159
    when X"f"       => return "0111000";
160
    when others     => return "0111111"; -- can't happen
161
    end case;
162
end function nibble_to_7seg;
163 46 ja_rd
 
164
 
165 2 ja_rd
begin
166
 
167
    mpu: entity work.mips_mpu
168 46 ja_rd
    generic map (
169
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
170
    )
171 2 ja_rd
    port map (
172
        interrupt   => '0',
173 59 ja_rd
 
174 46 ja_rd
        -- interface to FPGA i/o devices
175
        io_rd_data  => io_rd_data,
176
        io_rd_addr  => io_rd_addr,
177
        io_wr_addr  => io_wr_addr,
178
        io_wr_data  => io_wr_data,
179
        io_rd_vma   => io_rd_vma,
180
        io_byte_we  => io_byte_we,
181 59 ja_rd
 
182 46 ja_rd
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
183
        sram_address    => mpu_sram_address,
184
        sram_databus    => sram_data,
185
        sram_byte_we_n  => mpu_sram_byte_we_n,
186
        sram_oe_n       => mpu_sram_oe_n,
187 2 ja_rd
 
188 59 ja_rd
 
189 2 ja_rd
        uart_rxd    => rxd,
190
        uart_txd    => txd,
191 59 ja_rd
 
192 2 ja_rd
        clk         => clk,
193
        reset       => reset
194
    );
195
 
196
 
197 63 ja_rd
--##############################################################################
198
-- I/O registers
199
--##############################################################################
200 2 ja_rd
 
201 63 ja_rd
hex_display_register:
202
process(clk)
203
begin
204
    if clk'event and clk='1' then
205
        if io_byte_we/="0000" and io_wr_addr(15 downto 12)=X"2" then
206
            reg_display <= io_wr_data(15 downto 0);
207
        end if;
208
    end if;
209
end process hex_display_register;
210
 
211
sd_control_register:
212
process(clk)
213
begin
214
    if clk'event and clk='1' then
215
        if io_byte_we/="0000" and io_wr_addr(15 downto 12)=X"1" then
216
            if io_wr_addr(5)='1' then
217
                sd_clk_reg <= io_wr_addr(4);
218
            end if;
219
            if io_wr_addr(7)='1' then
220
                sd_cs_reg <= io_wr_addr(6);
221
            end if;
222
            if io_wr_addr(11)='1' then
223
                sd_do_reg <= io_wr_data(0);
224
            end if;
225
        end if;
226
    end if;
227
end process sd_control_register;
228
 
229
 
230
-- Show the SD interface signals on the green leds for debug
231
reg_gleds <= sd_clk_reg & sd_in & sd_do_reg & "000" & sd_cmd_reg & sd_cs_reg;
232
 
233
io_rd_data(0) <= sd_in;
234
io_rd_data(31 downto 22) <= switches;
235
 
236
 
237
 
238 59 ja_rd
-- red leds (light with '1') -- some CPU control signals
239 2 ja_rd
red_leds(0) <= '0';
240
red_leds(1) <= '0';
241
red_leds(2) <= '0';
242
red_leds(3) <= '0';
243
red_leds(4) <= '0';
244
red_leds(5) <= '0';
245
red_leds(6) <= '0';
246
red_leds(7) <= '0';
247
red_leds(8) <= '0';
248
red_leds(9) <= clk_1hz;
249
 
250
 
251
--##############################################################################
252
-- terasIC Cyclone II STARTER KIT BOARD -- interface to on-board devices
253
--##############################################################################
254
 
255
--##############################################################################
256
-- FLASH (flash is unused in this demo)
257
--##############################################################################
258
 
259
flash_addr <= (others => '0');
260
flash_we_n <= '1'; -- all enable signals inactive
261
flash_oe_n <= '1';
262
flash_reset_n <= '1';
263
 
264
 
265
--##############################################################################
266
-- SRAM (used as 64K x 8)
267
--
268
-- NOTE: All writes go to SRAM independent of rom paging status
269
--##############################################################################
270
 
271 46 ja_rd
sram_addr <= mpu_sram_address;
272
sram_oe_n <= mpu_sram_oe_n;
273
sram_ub_n <= mpu_sram_byte_we_n(1) and mpu_sram_oe_n;
274
sram_lb_n <= mpu_sram_byte_we_n(0) and mpu_sram_oe_n;
275
sram_ce_n <= '0';
276
sram_we_n <= mpu_sram_byte_we_n(1) and mpu_sram_byte_we_n(0);
277 2 ja_rd
 
278
 
279
--##############################################################################
280
-- RESET, CLOCK
281
--##############################################################################
282
 
283
-- Use button 3 as reset
284 59 ja_rd
reset_synchronization:
285
process(clk)
286
begin
287
    if clk'event and clk='1' then
288
        reset_sync(2) <= not buttons(3);
289
        reset_sync(1) <= reset_sync(2);
290
        reset_sync(0) <= reset_sync(1);
291
    end if;
292
end process reset_synchronization;
293 2 ja_rd
 
294 59 ja_rd
reset <= reset_sync(0);
295 2 ja_rd
 
296 59 ja_rd
 
297 2 ja_rd
-- Generate a 1-Hz 'clock' to flash a LED for visual reference.
298
process(clk_50MHz)
299
begin
300
  if clk_50MHz'event and clk_50MHz='1' then
301
    if reset = '1' then
302
      clk_1hz <= '0';
303
      counter_1hz <= (others => '0');
304
    else
305
      if conv_integer(counter_1hz) = 50000000 then
306
        counter_1hz <= (others => '0');
307
        clk_1hz <= not clk_1hz;
308
      else
309
        counter_1hz <= counter_1hz + 1;
310
      end if;
311
    end if;
312
  end if;
313
end process;
314
 
315
-- Master clock is external 50MHz oscillator
316
clk <= clk_50MHz;
317
 
318
 
319
--##############################################################################
320
-- LEDS, SWITCHES
321
--##############################################################################
322
 
323
-- Display the contents of a debug register at the green leds bar
324 59 ja_rd
green_leds <= reg_gleds;
325 2 ja_rd
 
326
 
327
--##############################################################################
328
-- QUAD 7-SEGMENT DISPLAYS
329
--##############################################################################
330
 
331 59 ja_rd
-- Show contents of debug register in hex display
332 2 ja_rd
display_data <= reg_display;
333
 
334 59 ja_rd
 
335 2 ja_rd
-- 7-segment encoders; the dev board displays are not multiplexed or encoded
336 59 ja_rd
hex3 <= nibble_to_7seg(display_data(15 downto 12));
337
hex2 <= nibble_to_7seg(display_data(11 downto  8));
338
hex1 <= nibble_to_7seg(display_data( 7 downto  4));
339
hex0 <= nibble_to_7seg(display_data( 3 downto  0));
340 2 ja_rd
 
341
--##############################################################################
342
-- SD card interface
343
--##############################################################################
344
 
345 63 ja_rd
-- Connect to FFs for use in bit-banged interface
346
--sd_cs       <= sd_cs_reg;
347
--sd_cmd      <= sd_do_reg;
348
--sd_clk      <= sd_clk_reg;
349
--sd_data     <= 'Z' when sd_do_reg='1' else '0';
350
--sd_in       <= sd_data;
351 2 ja_rd
 
352 63 ja_rd
sd_cs       <= sd_cs_reg;
353
sd_cmd      <= sd_do_reg;
354
sd_clk      <= sd_clk_reg;
355
--sd_data     <= 'Z';-- when sd_do_reg='1' else '0';
356
sd_in       <= sd_data;
357 2 ja_rd
 
358 63 ja_rd
 
359 2 ja_rd
--##############################################################################
360
-- SERIAL
361
--##############################################################################
362
 
363
--  Embedded in the MPU entity
364
 
365
end minimal;

powered by: WebSVN 2.1.0

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