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

Subversion Repositories ion

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

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

Line No. Rev Author Line
1 2 ja_rd
--#############################################################################
2
-- ION MIPS-compatible CPU demo on Terasic DE-1 Cyclone-II starter board
3
--#############################################################################
4
-- This module is little more than a wrapper around the CPU and its memories.
5
--#############################################################################
6
 
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
--##############################################################################
68
-- RS232 interface signals
69
 
70
signal rx_rdy :             std_logic;
71
signal tx_rdy :             std_logic;
72
signal rs232_data_rx :      std_logic_vector(7 downto 0);
73
signal rs232_status :       std_logic_vector(7 downto 0);
74
signal data_io_out :        std_logic_vector(7 downto 0);
75
signal io_port :            std_logic_vector(7 downto 0);
76
signal read_rx :            std_logic;
77
signal write_tx :           std_logic;
78
 
79
 
80
--##############################################################################
81
-- 
82
 
83
 
84
-- CPU access to hex display (unused by Altair SW)
85
signal reg_display :        std_logic_vector(15 downto 0);
86
 
87
 
88
 
89
--##############################################################################
90
-- DE-1 board interface signals
91
 
92
-- Quad 7-segment display (non multiplexed) & LEDS
93
signal display_data :       std_logic_vector(15 downto 0);
94
signal reg_gleds :          std_logic_vector(7 downto 0);
95
 
96
-- i/o signals
97
signal data_io_in :         std_logic_vector(7 downto 0);
98
signal data_mem_in :        std_logic_vector(7 downto 0);
99
signal data_rom_in :        std_logic_vector(7 downto 0);
100
signal rom_access :         std_logic;
101
signal rom_space :          std_logic;
102
signal breakpoint :         std_logic;
103
 
104
 
105
-- Clock & reset signals
106
signal clk_1hz :            std_logic;
107
signal clk_master :         std_logic;
108
signal counter_1hz :        std_logic_vector(25 downto 0);
109
signal reset :              std_logic;
110
signal clk :                std_logic;
111
 
112
-- SD control signals
113
signal sd_in :              std_logic;
114
signal reg_sd_dout :        std_logic;
115
signal reg_sd_clk :         std_logic;
116
signal reg_sd_cs :          std_logic;
117
 
118
signal cpu_rd_addr :        std_logic_vector(31 downto 0);
119
signal cpu_rd_data :        std_logic_vector(31 downto 0);
120
signal prev_rd_addr :       std_logic_vector(31 downto 28);
121
signal cpu_vma_data :       std_logic;
122
 
123
signal cpu_wr_addr :        std_logic_vector(31 downto 2);
124
signal cpu_wr_data :        std_logic_vector(31 downto 0);
125
signal cpu_byte_we :        std_logic_vector(3 downto 0);
126
 
127
signal data_uart :          std_logic_vector(31 downto 0);
128
 
129
signal data_uart_status :   std_logic_vector(31 downto 0);
130
signal uart_tx_rdy :        std_logic := '1';
131
signal uart_rx_rdy :        std_logic := '1';
132
 
133
 
134
begin
135
 
136
    mpu: entity work.mips_mpu
137
    port map (
138
        interrupt   => '0',
139
 
140
        rd_addr     => cpu_rd_addr,
141
        vma_data    => cpu_vma_data,
142
        data_r      => cpu_rd_data,
143
 
144
        wr_addr     => cpu_wr_addr,
145
        data_w      => cpu_wr_data,
146
        byte_we     => cpu_byte_we,
147
 
148
        mem_wait    => '0',
149
 
150
        uart_rxd    => rxd,
151
        uart_txd    => txd,
152
 
153
        clk         => clk,
154
        reset       => reset
155
    );
156
 
157
 
158
reg_display <= cpu_wr_addr(17 downto 2);
159
reg_gleds <= cpu_vma_data & "000" & cpu_byte_we;
160
 
161
-- red leds (light with '1') -- some CPU control signals 
162
red_leds(0) <= '0';
163
red_leds(1) <= '0';
164
red_leds(2) <= '0';
165
red_leds(3) <= '0';
166
red_leds(4) <= '0';
167
red_leds(5) <= '0';
168
red_leds(6) <= '0';
169
red_leds(7) <= '0';
170
red_leds(8) <= '0';
171
red_leds(9) <= clk_1hz;
172
 
173
 
174
--##############################################################################
175
-- terasIC Cyclone II STARTER KIT BOARD -- interface to on-board devices
176
--##############################################################################
177
 
178
--##############################################################################
179
-- FLASH (flash is unused in this demo)
180
--##############################################################################
181
 
182
flash_addr <= (others => '0');
183
 
184
flash_we_n <= '1'; -- all enable signals inactive
185
flash_oe_n <= '1';
186
flash_reset_n <= '1';
187
 
188
 
189
--##############################################################################
190
-- SRAM (used as 64K x 8)
191
--
192
-- NOTE: All writes go to SRAM independent of rom paging status
193
--##############################################################################
194
 
195
-- SRAM disabled for the time being
196
sram_addr <= (others => '0');
197
sram_data <= (others => 'Z');
198
sram_oe_n <= '1';
199
sram_ub_n <= '1';
200
sram_lb_n <= '1';
201
sram_ce_n <= '1';
202
sram_we_n <= '1';
203
 
204
 
205
--##############################################################################
206
-- RESET, CLOCK
207
--##############################################################################
208
 
209
-- Use button 3 as reset
210
reset <= not buttons(3);
211
 
212
 
213
-- Generate a 1-Hz 'clock' to flash a LED for visual reference.
214
process(clk_50MHz)
215
begin
216
  if clk_50MHz'event and clk_50MHz='1' then
217
    if reset = '1' then
218
      clk_1hz <= '0';
219
      counter_1hz <= (others => '0');
220
    else
221
      if conv_integer(counter_1hz) = 50000000 then
222
        counter_1hz <= (others => '0');
223
        clk_1hz <= not clk_1hz;
224
      else
225
        counter_1hz <= counter_1hz + 1;
226
      end if;
227
    end if;
228
  end if;
229
end process;
230
 
231
-- Master clock is external 50MHz oscillator
232
clk <= clk_50MHz;
233
 
234
 
235
--##############################################################################
236
-- LEDS, SWITCHES
237
--##############################################################################
238
 
239
-- Display the contents of a debug register at the green leds bar
240
green_leds <= reg_gleds;
241
 
242
 
243
--##############################################################################
244
-- QUAD 7-SEGMENT DISPLAYS
245
--##############################################################################
246
 
247
-- So far, nothing to display
248
display_data <= reg_display;
249
 
250
 
251
-- 7-segment encoders; the dev board displays are not multiplexed or encoded
252
with display_data(15 downto 12) select hex3 <=
253
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
254
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
255
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
256
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
257
 
258
with display_data(11 downto 8) select hex2 <=
259
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
260
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
261
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
262
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
263
 
264
with display_data(7 downto 4) select hex1 <=
265
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
266
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
267
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
268
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
269
 
270
with display_data(3 downto 0) select hex0 <=
271
"0000001" when X"0","1001111" when X"1","0010010" when X"2","0000110" when X"3",
272
"1001100" when X"4","0100100" when X"5","0100000" when X"6","0001111" when X"7",
273
"0000000" when X"8","0000100" when X"9","0001000" when X"a","1100000" when X"b",
274
"0110001" when X"c","1000010" when X"d","0110000" when X"e","0111000" when others;
275
 
276
--##############################################################################
277
-- SD card interface
278
--##############################################################################
279
 
280
-- unused in this demo, but I did not bother to cut away the attached registers
281
sd_cs     <= '0';
282
sd_cmd    <= '0';
283
sd_clk    <= '0';
284
sd_in     <= 'Z';
285
 
286
 
287
--##############################################################################
288
-- SERIAL
289
--##############################################################################
290
 
291
--  Embedded in the MPU entity
292
 
293
end minimal;

powered by: WebSVN 2.1.0

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