]> rtime.felk.cvut.cz Git - fpga/plasma.git/blob - vhdl/plasma_if.vhd
Local copy of Plasma MIPS project.
[fpga/plasma.git] / vhdl / plasma_if.vhd
1 ---------------------------------------------------------------------
2 -- TITLE: Plamsa Interface (clock divider and interface to FPGA board)
3 -- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4 -- DATE CREATED: 6/6/02
5 -- FILENAME: plasma_if.vhd
6 -- PROJECT: Plasma CPU core
7 -- COPYRIGHT: Software placed into the public domain by the author.
8 --    Software 'as is' without warranty.  Author liable for nothing.
9 -- DESCRIPTION:
10 --    This entity divides the clock by two and interfaces to the 
11 --    Altera EP20K200EFC484-2X FPGA board.
12 --    Xilinx Spartan-3 XC3S200FT256-4 FPGA.
13 ---------------------------------------------------------------------
14 library ieee;
15 use ieee.std_logic_1164.all;
16 --use work.mlite_pack.all;
17
18 entity plasma_if is
19    port(clk_in      : in std_logic;
20         reset       : in std_logic;
21         uart_read   : in std_logic;
22         uart_write  : out std_logic;
23
24         ram_address : out std_logic_vector(31 downto 2);
25         ram_data    : inout std_logic_vector(31 downto 0);
26         ram_ce1_n   : out std_logic;
27         ram_ub1_n   : out std_logic;
28         ram_lb1_n   : out std_logic;
29         ram_ce2_n   : out std_logic;
30         ram_ub2_n   : out std_logic;
31         ram_lb2_n   : out std_logic;
32         ram_we_n    : out std_logic;
33         ram_oe_n    : out std_logic;
34          
35         gpio0_out   : out std_logic_vector(31 downto 0);
36         gpioA_in    : in std_logic_vector(31 downto 0));
37 end; --entity plasma_if
38
39
40 architecture logic of plasma_if is
41
42    component plasma
43       generic(memory_type : string := "XILINX_16X"; --"DUAL_PORT_" "ALTERA_LPM";
44               log_file    : string := "UNUSED");
45       port(clk               : in std_logic;
46            reset             : in std_logic;
47            uart_write        : out std_logic;
48            uart_read         : in std_logic;
49    
50            address           : out std_logic_vector(31 downto 2);
51            byte_we           : out std_logic_vector(3 downto 0); 
52            data_write        : out std_logic_vector(31 downto 0);
53            data_read         : in std_logic_vector(31 downto 0);
54            mem_pause_in      : in std_logic;
55         
56            gpio0_out         : out std_logic_vector(31 downto 0);
57            gpioA_in          : in std_logic_vector(31 downto 0));
58    end component; --plasma
59
60    signal clk_reg      : std_logic;
61    signal we_n_next    : std_logic;
62    signal we_n_reg     : std_logic;
63    signal mem_address  : std_logic_vector(31 downto 2);
64    signal data_write   : std_logic_vector(31 downto 0);
65    signal data_reg     : std_logic_vector(31 downto 0);
66    signal byte_we      : std_logic_vector(3 downto 0);
67    signal mem_pause_in : std_logic;
68
69 begin  --architecture
70    --Divide 50 MHz clock by two
71    clk_div: process(reset, clk_in, clk_reg, we_n_next)
72    begin
73       if reset = '1' then
74          clk_reg <= '0';
75       elsif rising_edge(clk_in) then
76          clk_reg <= not clk_reg;
77       end if;
78
79       if reset = '1' then
80          we_n_reg <= '1';
81          data_reg <= (others => '0');
82       elsif falling_edge(clk_in) then
83          we_n_reg <= we_n_next or not clk_reg;
84          data_reg <= ram_data;
85       end if;
86    end process; --clk_div
87
88    mem_pause_in <= '0';
89    ram_address <= mem_address(31 downto 2);
90    ram_we_n <= we_n_reg;
91
92    --For Xilinx Spartan-3 Starter Kit
93    ram_control:   
94    process(clk_reg, mem_address, byte_we, data_write)
95    begin
96       if mem_address(30 downto 28) = "001" then  --RAM
97          ram_ce1_n <= '0';
98          ram_ce2_n <= '0';
99          if byte_we = "0000" then      --read
100             ram_data  <= (others => 'Z');
101             ram_ub1_n <= '0';
102             ram_lb1_n <= '0';
103             ram_ub2_n <= '0';
104             ram_lb2_n <= '0';
105             we_n_next <= '1';
106             ram_oe_n  <= '0';
107          else                                    --write
108             if clk_reg = '1' then
109                ram_data <= (others => 'Z');
110             else
111                ram_data <= data_write;
112             end if;
113             ram_ub1_n <= not byte_we(3);
114             ram_lb1_n <= not byte_we(2);
115             ram_ub2_n <= not byte_we(1);
116             ram_lb2_n <= not byte_we(0);
117             we_n_next <= '0';
118             ram_oe_n  <= '1';
119          end if;
120       else
121          ram_data <= (others => 'Z');
122          ram_ce1_n <= '1';
123          ram_ub1_n <= '1';
124          ram_lb1_n <= '1';
125          ram_ce2_n <= '1';
126          ram_ub2_n <= '1';
127          ram_lb2_n <= '1';
128          we_n_next <= '1';
129          ram_oe_n  <= '1';
130       end if;
131    end process; --ram_control
132
133    u1_plama: plasma 
134       generic map (memory_type => "XILINX_16X",
135                    log_file    => "UNUSED")
136       PORT MAP (
137          clk               => clk_reg,
138          reset             => reset,
139          uart_write        => uart_write,
140          uart_read         => uart_read,
141  
142          address           => mem_address,
143          byte_we           => byte_we,
144          data_write        => data_write,
145          data_read         => data_reg,
146          mem_pause_in      => mem_pause_in,
147          
148          gpio0_out         => gpio0_out,
149          gpioA_in          => gpioA_in);
150          
151 end; --architecture logic
152