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

Subversion Repositories ion

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

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
    port (
16
        -- ***** 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
        sram_lb_n     : out std_logic;
32
        sram_ce_n     : out std_logic;
33
        sram_we_n     : out std_logic;
34
 
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
        sd_clk        : out std_logic
58
    );
59
end c2sb_demo;
60
 
61
architecture minimal of c2sb_demo is
62
 
63
 
64
--##############################################################################
65
-- 
66
 
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
-- 
84
 
85
 
86
-- CPU access to hex display (unused by Altair SW)
87
signal reg_display :        std_logic_vector(15 downto 0);
88
 
89
 
90
 
91
--##############################################################################
92
-- DE-1 board interface signals
93
 
94
-- Quad 7-segment display (non multiplexed) & LEDS
95
signal display_data :       std_logic_vector(15 downto 0);
96
signal reg_gleds :          std_logic_vector(7 downto 0);
97
 
98
-- i/o signals
99
signal data_io_in :         std_logic_vector(7 downto 0);
100
signal data_mem_in :        std_logic_vector(7 downto 0);
101
signal data_rom_in :        std_logic_vector(7 downto 0);
102
signal rom_access :         std_logic;
103
signal rom_space :          std_logic;
104
signal breakpoint :         std_logic;
105
 
106
 
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
 
139
 
140 2 ja_rd
begin
141
 
142
    mpu: entity work.mips_mpu
143 46 ja_rd
    generic map (
144
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
145
    )
146 2 ja_rd
    port map (
147
        interrupt   => '0',
148
 
149 46 ja_rd
        -- interface to FPGA i/o devices
150
        io_rd_data  => io_rd_data,
151
        io_rd_addr  => io_rd_addr,
152
        io_wr_addr  => io_wr_addr,
153
        io_wr_data  => io_wr_data,
154
        io_rd_vma   => io_rd_vma,
155
        io_byte_we  => io_byte_we,
156 2 ja_rd
 
157 46 ja_rd
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
158
        sram_address    => mpu_sram_address,
159
        sram_databus    => sram_data,
160
        sram_byte_we_n  => mpu_sram_byte_we_n,
161
        sram_oe_n       => mpu_sram_oe_n,
162 2 ja_rd
 
163
 
164
        uart_rxd    => rxd,
165
        uart_txd    => txd,
166
 
167
        clk         => clk,
168
        reset       => reset
169
    );
170
 
171
 
172 46 ja_rd
reg_display <= io_wr_data(15 downto 0);
173
reg_gleds <= io_rd_vma & "000" & io_byte_we;
174 2 ja_rd
 
175
-- red leds (light with '1') -- some CPU control signals 
176
red_leds(0) <= '0';
177
red_leds(1) <= '0';
178
red_leds(2) <= '0';
179
red_leds(3) <= '0';
180
red_leds(4) <= '0';
181
red_leds(5) <= '0';
182
red_leds(6) <= '0';
183
red_leds(7) <= '0';
184
red_leds(8) <= '0';
185
red_leds(9) <= clk_1hz;
186
 
187
 
188
--##############################################################################
189
-- terasIC Cyclone II STARTER KIT BOARD -- interface to on-board devices
190
--##############################################################################
191
 
192
--##############################################################################
193
-- FLASH (flash is unused in this demo)
194
--##############################################################################
195
 
196
flash_addr <= (others => '0');
197
flash_we_n <= '1'; -- all enable signals inactive
198
flash_oe_n <= '1';
199
flash_reset_n <= '1';
200
 
201
 
202
--##############################################################################
203
-- SRAM (used as 64K x 8)
204
--
205
-- NOTE: All writes go to SRAM independent of rom paging status
206
--##############################################################################
207
 
208 46 ja_rd
sram_addr <= mpu_sram_address;
209
sram_oe_n <= mpu_sram_oe_n;
210
sram_ub_n <= mpu_sram_byte_we_n(1) and mpu_sram_oe_n;
211
sram_lb_n <= mpu_sram_byte_we_n(0) and mpu_sram_oe_n;
212
sram_ce_n <= '0';
213
sram_we_n <= mpu_sram_byte_we_n(1) and mpu_sram_byte_we_n(0);
214 2 ja_rd
 
215
 
216
--##############################################################################
217
-- RESET, CLOCK
218
--##############################################################################
219
 
220
-- Use button 3 as reset
221
reset <= not buttons(3);
222
 
223
 
224
-- Generate a 1-Hz 'clock' to flash a LED for visual reference.
225
process(clk_50MHz)
226
begin
227
  if clk_50MHz'event and clk_50MHz='1' then
228
    if reset = '1' then
229
      clk_1hz <= '0';
230
      counter_1hz <= (others => '0');
231
    else
232
      if conv_integer(counter_1hz) = 50000000 then
233
        counter_1hz <= (others => '0');
234
        clk_1hz <= not clk_1hz;
235
      else
236
        counter_1hz <= counter_1hz + 1;
237
      end if;
238
    end if;
239
  end if;
240
end process;
241
 
242
-- Master clock is external 50MHz oscillator
243
clk <= clk_50MHz;
244
 
245
 
246
--##############################################################################
247
-- LEDS, SWITCHES
248
--##############################################################################
249
 
250
-- Display the contents of a debug register at the green leds bar
251
green_leds <= reg_gleds;
252
 
253
 
254
--##############################################################################
255
-- QUAD 7-SEGMENT DISPLAYS
256
--##############################################################################
257
 
258
-- So far, nothing to display
259
display_data <= reg_display;
260
 
261
 
262
-- 7-segment encoders; the dev board displays are not multiplexed or encoded
263
with display_data(15 downto 12) select hex3 <=
264
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
265
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
266
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
267
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
268
 
269
with display_data(11 downto 8) select hex2 <=
270
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
271
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
272
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
273
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
274
 
275
with display_data(7 downto 4) select hex1 <=
276
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
277
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
278
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
279
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
280
 
281
with display_data(3 downto 0) select hex0 <=
282
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
283
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
284
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
285
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
286
 
287
--##############################################################################
288
-- SD card interface
289
--##############################################################################
290
 
291
-- unused in this demo, but I did not bother to cut away the attached registers
292
sd_cs     <= '0';
293
sd_cmd    <= '0';
294
sd_clk    <= '0';
295
sd_in     <= 'Z';
296
 
297
 
298
--##############################################################################
299
-- SERIAL
300
--##############################################################################
301
 
302
--  Embedded in the MPU entity
303
 
304
end minimal;

powered by: WebSVN 2.1.0

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