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

Subversion Repositories ion

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

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 59 ja_rd
--
84 2 ja_rd
 
85
 
86 59 ja_rd
-- CPU access to hex display
87 2 ja_rd
signal reg_display :        std_logic_vector(15 downto 0);
88
 
89
 
90
 
91
--##############################################################################
92
-- DE-1 board interface signals
93
 
94 59 ja_rd
-- Synchronization FF chain for asynchronous reset input
95
signal reset_sync :         std_logic_vector(2 downto 0);
96
 
97 2 ja_rd
-- Quad 7-segment display (non multiplexed) & LEDS
98
signal display_data :       std_logic_vector(15 downto 0);
99 59 ja_rd
signal reg_gleds :          std_logic_vector(7 downto 0);
100 2 ja_rd
 
101
-- Clock & reset signals
102
signal clk_1hz :            std_logic;
103
signal clk_master :         std_logic;
104
signal counter_1hz :        std_logic_vector(25 downto 0);
105
signal reset :              std_logic;
106
signal clk :                std_logic;
107
 
108
-- SD control signals
109
signal sd_in :              std_logic;
110
signal reg_sd_dout :        std_logic;
111
signal reg_sd_clk :         std_logic;
112
signal reg_sd_cs :          std_logic;
113
 
114 46 ja_rd
-- MPU interface signals
115 2 ja_rd
signal data_uart :          std_logic_vector(31 downto 0);
116
signal data_uart_status :   std_logic_vector(31 downto 0);
117
signal uart_tx_rdy :        std_logic := '1';
118
signal uart_rx_rdy :        std_logic := '1';
119
 
120 46 ja_rd
signal io_rd_data :         std_logic_vector(31 downto 0);
121
signal io_rd_addr :         std_logic_vector(31 downto 2);
122
signal io_wr_addr :         std_logic_vector(31 downto 2);
123
signal io_wr_data :         std_logic_vector(31 downto 0);
124
signal io_rd_vma :          std_logic;
125
signal io_byte_we :         std_logic_vector(3 downto 0);
126 2 ja_rd
 
127 46 ja_rd
signal mpu_sram_address :   std_logic_vector(SRAM_ADDR_SIZE downto 1);
128
signal mpu_sram_databus :   std_logic_vector(15 downto 0);
129
signal mpu_sram_byte_we_n : std_logic_vector(1 downto 0);
130
signal mpu_sram_oe_n :      std_logic;
131
 
132 59 ja_rd
-- Converts hex nibble to 7-segment
133
-- Segments ordered as "GFEDCBA"; '0' is ON, '1' is OFF
134
function nibble_to_7seg(nibble : std_logic_vector(3 downto 0))
135
                        return std_logic_vector is
136
begin
137
    case nibble is
138
    when X"0"       => return "0000001";
139
    when X"1"       => return "1001111";
140
    when X"2"       => return "0010010";
141
    when X"3"       => return "0000110";
142
    when X"4"       => return "1001100";
143
    when X"5"       => return "0100100";
144
    when X"6"       => return "0100000";
145
    when X"7"       => return "0001111";
146
    when X"8"       => return "0000000";
147
    when X"9"       => return "0000100";
148
    when X"a"       => return "0001000";
149
    when X"b"       => return "1100000";
150
    when X"c"       => return "0110001";
151
    when X"d"       => return "1000010";
152
    when X"e"       => return "0110000";
153
    when X"f"       => return "0111000";
154
    when others     => return "0111111"; -- can't happen
155
    end case;
156
end function nibble_to_7seg;
157 46 ja_rd
 
158
 
159 2 ja_rd
begin
160
 
161
    mpu: entity work.mips_mpu
162 46 ja_rd
    generic map (
163
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
164
    )
165 2 ja_rd
    port map (
166
        interrupt   => '0',
167 59 ja_rd
 
168 46 ja_rd
        -- interface to FPGA i/o devices
169
        io_rd_data  => io_rd_data,
170
        io_rd_addr  => io_rd_addr,
171
        io_wr_addr  => io_wr_addr,
172
        io_wr_data  => io_wr_data,
173
        io_rd_vma   => io_rd_vma,
174
        io_byte_we  => io_byte_we,
175 59 ja_rd
 
176 46 ja_rd
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
177
        sram_address    => mpu_sram_address,
178
        sram_databus    => sram_data,
179
        sram_byte_we_n  => mpu_sram_byte_we_n,
180
        sram_oe_n       => mpu_sram_oe_n,
181 2 ja_rd
 
182 59 ja_rd
 
183 2 ja_rd
        uart_rxd    => rxd,
184
        uart_txd    => txd,
185 59 ja_rd
 
186 2 ja_rd
        clk         => clk,
187
        reset       => reset
188
    );
189
 
190
 
191 46 ja_rd
reg_display <= io_wr_data(15 downto 0);
192
reg_gleds <= io_rd_vma & "000" & io_byte_we;
193 2 ja_rd
 
194 59 ja_rd
-- red leds (light with '1') -- some CPU control signals
195 2 ja_rd
red_leds(0) <= '0';
196
red_leds(1) <= '0';
197
red_leds(2) <= '0';
198
red_leds(3) <= '0';
199
red_leds(4) <= '0';
200
red_leds(5) <= '0';
201
red_leds(6) <= '0';
202
red_leds(7) <= '0';
203
red_leds(8) <= '0';
204
red_leds(9) <= clk_1hz;
205
 
206
 
207
--##############################################################################
208
-- terasIC Cyclone II STARTER KIT BOARD -- interface to on-board devices
209
--##############################################################################
210
 
211
--##############################################################################
212
-- FLASH (flash is unused in this demo)
213
--##############################################################################
214
 
215
flash_addr <= (others => '0');
216
flash_we_n <= '1'; -- all enable signals inactive
217
flash_oe_n <= '1';
218
flash_reset_n <= '1';
219
 
220
 
221
--##############################################################################
222
-- SRAM (used as 64K x 8)
223
--
224
-- NOTE: All writes go to SRAM independent of rom paging status
225
--##############################################################################
226
 
227 46 ja_rd
sram_addr <= mpu_sram_address;
228
sram_oe_n <= mpu_sram_oe_n;
229
sram_ub_n <= mpu_sram_byte_we_n(1) and mpu_sram_oe_n;
230
sram_lb_n <= mpu_sram_byte_we_n(0) and mpu_sram_oe_n;
231
sram_ce_n <= '0';
232
sram_we_n <= mpu_sram_byte_we_n(1) and mpu_sram_byte_we_n(0);
233 2 ja_rd
 
234
 
235
--##############################################################################
236
-- RESET, CLOCK
237
--##############################################################################
238
 
239
-- Use button 3 as reset
240 59 ja_rd
reset_synchronization:
241
process(clk)
242
begin
243
    if clk'event and clk='1' then
244
        reset_sync(2) <= not buttons(3);
245
        reset_sync(1) <= reset_sync(2);
246
        reset_sync(0) <= reset_sync(1);
247
    end if;
248
end process reset_synchronization;
249 2 ja_rd
 
250 59 ja_rd
reset <= reset_sync(0);
251 2 ja_rd
 
252 59 ja_rd
 
253 2 ja_rd
-- Generate a 1-Hz 'clock' to flash a LED for visual reference.
254
process(clk_50MHz)
255
begin
256
  if clk_50MHz'event and clk_50MHz='1' then
257
    if reset = '1' then
258
      clk_1hz <= '0';
259
      counter_1hz <= (others => '0');
260
    else
261
      if conv_integer(counter_1hz) = 50000000 then
262
        counter_1hz <= (others => '0');
263
        clk_1hz <= not clk_1hz;
264
      else
265
        counter_1hz <= counter_1hz + 1;
266
      end if;
267
    end if;
268
  end if;
269
end process;
270
 
271
-- Master clock is external 50MHz oscillator
272
clk <= clk_50MHz;
273
 
274
 
275
--##############################################################################
276
-- LEDS, SWITCHES
277
--##############################################################################
278
 
279
-- Display the contents of a debug register at the green leds bar
280 59 ja_rd
green_leds <= reg_gleds;
281 2 ja_rd
 
282
 
283
--##############################################################################
284
-- QUAD 7-SEGMENT DISPLAYS
285
--##############################################################################
286
 
287 59 ja_rd
-- Show contents of debug register in hex display
288 2 ja_rd
display_data <= reg_display;
289
 
290 59 ja_rd
 
291 2 ja_rd
-- 7-segment encoders; the dev board displays are not multiplexed or encoded
292 59 ja_rd
hex3 <= nibble_to_7seg(display_data(15 downto 12));
293
hex2 <= nibble_to_7seg(display_data(11 downto  8));
294
hex1 <= nibble_to_7seg(display_data( 7 downto  4));
295
hex0 <= nibble_to_7seg(display_data( 3 downto  0));
296 2 ja_rd
 
297
--##############################################################################
298
-- SD card interface
299
--##############################################################################
300
 
301 59 ja_rd
-- unused in this demo
302 2 ja_rd
sd_cs     <= '0';
303
sd_cmd    <= '0';
304
sd_clk    <= '0';
305
sd_in     <= 'Z';
306
 
307
 
308
--##############################################################################
309
-- SERIAL
310
--##############################################################################
311
 
312
--  Embedded in the MPU entity
313
 
314
end minimal;

powered by: WebSVN 2.1.0

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