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

Subversion Repositories light8080

[/] [light8080/] [trunk/] [vhdl/] [demos/] [c2sb/] [c2sb_soc.vhdl] - Blame information for rev 85

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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