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

Subversion Repositories light52

[/] [light52/] [trunk/] [boards/] [terasic_de1/] [vhdl/] [c2sb_soc.vhdl] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 ja_rd
--##############################################################################
2
-- light52 MCU demo on DE-1 board
3
--##############################################################################
4
-- 
5
-- This is a minimal demo of the light52 core targetting Terasic's DE-1 
6
-- development board for Cyclone-2 FPGAs. 
7
-- Since the demo uses little board resources other than the serial port it 
8
-- should be easy to port it to other platforms.
9
-- This file is strictly for demonstration purposes and has not been tested.
10
--
11
-- This demo has been built from a generic template for designs targetting the
12
-- DE-1 development board. The entity defines all the inputs and outputs present
13
-- in the actual board, whether or not they are used in the design at hand.
14
--##############################################################################
15
 
16
library ieee;
17
use ieee.std_logic_1164.all;
18
use ieee.std_logic_arith.all;
19
use ieee.std_logic_unsigned.all;
20
 
21
-- Package with utility functions for handling SoC object code.
22
use work.light52_pkg.all;
23
-- Package that contains the program object code in VHDL constant format.
24
use work.obj_code_pkg.all;
25
 
26
 
27
-- Define the entity outputs as they are connected in the DE-1 development 
28
-- board. Many of the outputs will be left unused in this demo.
29
entity c2sb_soc is
30
    port (
31
        -- ***** Clocks
32
        clk_50MHz     : in std_logic;
33
 
34
        -- ***** Flash 4MB
35
        flash_addr    : out std_logic_vector(21 downto 0);
36
        flash_data    : in std_logic_vector(7 downto 0);
37
        flash_oe_n    : out std_logic;
38
        flash_we_n    : out std_logic;
39
        flash_reset_n : out std_logic;
40
 
41
        -- ***** SRAM 256K x 16
42
        sram_addr     : out std_logic_vector(17 downto 0);
43
        sram_data     : inout std_logic_vector(15 downto 0);
44
        sram_oe_n     : out std_logic;
45
        sram_ub_n     : out std_logic;
46
        sram_lb_n     : out std_logic;
47
        sram_ce_n     : out std_logic;
48
        sram_we_n     : out std_logic;
49
 
50
        -- ***** RS-232
51
        rxd           : in std_logic;
52
        txd           : out std_logic;
53
 
54
        -- ***** Switches and buttons
55
        switches      : in std_logic_vector(9 downto 0);
56
        buttons       : in std_logic_vector(3 downto 0);
57
 
58
        -- ***** Quad 7-seg displays
59
        hex0          : out std_logic_vector(0 to 6);
60
        hex1          : out std_logic_vector(0 to 6);
61
        hex2          : out std_logic_vector(0 to 6);
62
        hex3          : out std_logic_vector(0 to 6);
63
 
64
        -- ***** Leds
65
        red_leds      : out std_logic_vector(9 downto 0);
66
        green_leds    : out std_logic_vector(7 downto 0);
67
 
68
        -- ***** SD Card
69
        sd_data       : in  std_logic;
70
        sd_cs         : out std_logic;
71
        sd_cmd        : out std_logic;
72
        sd_clk        : out std_logic
73
    );
74
end c2sb_soc;
75
 
76
architecture minimal of c2sb_soc is
77
 
78
--##############################################################################
79
-- Some of these signals are 
80
 
81
-- light52 MCU signals ---------------------------------------------------------
82
signal p0_out :           std_logic_vector(7 downto 0);
83
signal p1_out :           std_logic_vector(7 downto 0);
84
signal p2_in :            std_logic_vector(7 downto 0);
85
signal p3_in :            std_logic_vector(7 downto 0);
86
signal external_irq :     std_logic_vector(7 downto 0);
87
signal uart_txd :         std_logic;
88
signal uart_rxd :         std_logic;
89
 
90
-- Signals for external SRAM synchronization -----------------------------------
91
signal sram_data_out :    std_logic_vector(7 downto 0); -- sram output reg
92
signal sram_write :       std_logic; -- sram we register
93
signal address_reg :      std_logic_vector(15 downto 0); -- registered addr bus
94
 
95
 
96
--##############################################################################
97
-- On-board device interface signals 
98
 
99
-- Quad 7-segment display (non multiplexed) & LEDS -----------------------------
100
signal display_data :     std_logic_vector(15 downto 0);
101
 
102
 
103
-- Clock & reset signals -------------------------------------------------------
104
signal clk_1hz :          std_logic;
105
signal clk_master :       std_logic;
106
signal reset :            std_logic;
107
signal clk :              std_logic;
108
signal counter_1hz :      std_logic_vector(25 downto 0);
109
 
110
-- SD control signals ----------------------------------------------------------
111
-- SD connector unused, unconnected
112
 
113
 
114
--## Functions #################################################################
115
 
116
-- Converts hex nibble to 7-segment (sinthesizable).
117
-- Segments ordered as "GFEDCBA"; '0' is ON, '1' is OFF
118
function nibble_to_7seg(nibble : std_logic_vector(3 downto 0))
119
                        return std_logic_vector is
120
begin
121
    case nibble is
122
    when X"0"       => return "0000001";
123
    when X"1"       => return "1001111";
124
    when X"2"       => return "0010010";
125
    when X"3"       => return "0000110";
126
    when X"4"       => return "1001100";
127
    when X"5"       => return "0100100";
128
    when X"6"       => return "0100000";
129
    when X"7"       => return "0001111";
130
    when X"8"       => return "0000000";
131
    when X"9"       => return "0000100";
132
    when X"a"       => return "0001000";
133
    when X"b"       => return "1100000";
134
    when X"c"       => return "0110001";
135
    when X"d"       => return "1000010";
136
    when X"e"       => return "0110000";
137
    when X"f"       => return "0111000";
138
    when others     => return "0111111"; -- can't happen
139
    end case;
140
end function nibble_to_7seg;
141
 
142
begin
143
 
144
  -- SOC instantiation 
145
  mcu: entity work.light52_mcu
146
  generic map (
147
    -- Memory size is defined in package obj_code_pkg...
148
    CODE_ROM_SIZE => work.obj_code_pkg.XCODE_SIZE,
149
    XDATA_RAM_SIZE => work.obj_code_pkg.XDATA_SIZE,
150
    -- ...as is the object code initialization constant.
151
    OBJ_CODE => work.obj_code_pkg.object_code,
152
    -- Leave BCD opcodes disabled.
153
    IMPLEMENT_BCD_INSTRUCTIONS => false,
154
    -- UART baud rate isn't programmable in run time.
155
    UART_HARDWIRED => true,
156
    -- We're using the 50MHz clock of the DE-1 board.
157
    CLOCK_RATE => 50e6
158
  )
159
  port map (
160
    clk             => clk,
161
    reset           => reset,
162
 
163
    txd             => uart_txd,
164
    rxd             => uart_rxd,
165
 
166
    external_irq    => external_irq,
167
 
168
    p0_out          => p0_out,
169
    p1_out          => p1_out,
170
    p2_in           => p2_in,
171
    p3_in           => p3_in
172
  );
173
 
174
  -- Input port P2 connected to switches for lack of better use...
175
  p2_in <= switches(7 downto 0);
176
  -- ...and input port P3 is connected to P0 for test purposes.
177
  p3_in <= p0_out;
178
 
179
  -- External irq inputs tied to P1 for test purposes
180
  external_irq <= p0_out;
181
 
182
--##### Input ports ###########################################################
183
 
184
 
185
--##############################################################################
186
-- terasIC Cyclone II STARTER KIT BOARD
187
--##############################################################################
188
 
189
--##############################################################################
190
-- FLASH (flash is unused in this demo)
191
--##############################################################################
192
 
193
  flash_addr <= (others => '0');
194
 
195
  flash_we_n <= '1'; -- all enable signals inactive
196
  flash_oe_n <= '1';
197
  flash_reset_n <= '1';
198
 
199
 
200
--##############################################################################
201
-- SRAM (wired as 64K x 8)
202
-- The SRAM is unused in this demo.
203
--##############################################################################
204
 
205
  -- These registera make the external, asynchronous SRAM behave like an
206
  -- internal syncronous BRAM, except for the timing.
207
  -- Since the SoC has no wait state capability, the SoC clock rate must 
208
  -- accomodate the SRAM timing -- including FPGA clock-to-output, RAM delays 
209
  -- and FPGA input setup and hold times. Setting up the synthesis constraints
210
  -- is left to the user too.
211
  sram_registers:
212
  process(clk)
213
  begin
214
    if clk'event and clk='1' then
215
      if reset='1' then
216
        sram_addr <= "000000000000000000";
217
        address_reg <= "0000000000000000";
218
        sram_data_out <= X"00";
219
        sram_write <= '0';
220
      else
221
      end if;
222
    end if;
223
  end process sram_registers;
224
 
225
  sram_data(15 downto 8) <= "ZZZZZZZZ"; -- high byte unused
226
  sram_data(7 downto 0)  <= "ZZZZZZZZ" when sram_write='0' else sram_data_out;
227
  -- (the X"ZZ" will physically be the read input data)
228
 
229
  -- sram access controlled by WE_N
230
  sram_oe_n <= '0';
231
  sram_ce_n <= '0';
232
  sram_we_n <= not sram_write;
233
  sram_ub_n <= '1'; -- always disable
234
  sram_lb_n <= '0';
235
 
236
 
237
--##############################################################################
238
-- RESET, CLOCK
239
--##############################################################################
240
 
241
  -- Use switch 9 as reset
242
  reset <= not switches(9);
243
 
244
 
245
  -- Generate a 1-Hz 'clock' to flash a LED for visual reference.
246
  process(clk_50MHz)
247
  begin
248
    if clk_50MHz'event and clk_50MHz='1' then
249
      if reset = '1' then
250
        clk_1hz <= '0';
251
        counter_1hz <= (others => '0');
252
      else
253
        if conv_integer(counter_1hz) = 50000000 then
254
          counter_1hz <= (others => '0');
255
          clk_1hz <= not clk_1hz;
256
        else
257
          counter_1hz <= counter_1hz + 1;
258
        end if;
259
      end if;
260
    end if;
261
  end process;
262
 
263
  -- Master clock is external 50MHz oscillator
264
  clk <= clk_50MHz;
265
 
266
 
267
--##############################################################################
268
-- LEDS, SWITCHES
269
--##############################################################################
270
 
271
  -- Display the contents of an output port at the green leds bar
272
  green_leds <= p0_out;
273
 
274
  -- Red leds unused except for 1-Hz clock
275
  red_leds(9 downto 1) <= (others => '0');
276
  red_leds(0) <= clk_1hz;
277
 
278
 
279
--##############################################################################
280
-- QUAD 7-SEGMENT DISPLAYS
281
--##############################################################################
282
 
283
  -- Display the contents of the output port at the hex displays.
284
  display_data <= p0_out & p1_out;
285
 
286
  -- 7-segment encoders; the dev board displays are not multiplexed or encoded
287
  hex3 <= nibble_to_7seg(display_data(15 downto 12));
288
  hex2 <= nibble_to_7seg(display_data(11 downto  8));
289
  hex1 <= nibble_to_7seg(display_data( 7 downto  4));
290
  hex0 <= nibble_to_7seg(display_data( 3 downto  0));
291
 
292
 
293
--##############################################################################
294
-- SD card interface
295
--##############################################################################
296
 
297
  -- SD card unused in this demo
298
  sd_cs     <= '0';
299
  sd_cmd    <= '0';
300
  sd_clk    <= '0';
301
  --sd_in     <= '0';
302
 
303
 
304
--##############################################################################
305
-- SERIAL
306
--##############################################################################
307
 
308
  -- Txd & rxd pins connected straight to the MCU core
309
  txd <= uart_txd;
310
  uart_rxd <= rxd;
311
 
312
 
313
end minimal;

powered by: WebSVN 2.1.0

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