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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [vhdl/] [plasma.vhd] - Blame information for rev 382

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

Line No. Rev Author Line
1 48 rhoads
---------------------------------------------------------------------
2
-- TITLE: Plasma (CPU core with memory)
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 6/4/02
5
-- FILENAME: plasma.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 combines the CPU core with memory and a UART.
11 139 rhoads
--
12
-- Memory Map:
13 184 rhoads
--   0x00000000 - 0x0000ffff   Internal RAM (8KB)
14
--   0x10000000 - 0x100fffff   External RAM (1MB)
15 139 rhoads
--   Access all Misc registers with 32-bit accesses
16
--   0x20000000  Uart Write (will pause CPU if busy)
17
--   0x20000000  Uart Read
18
--   0x20000010  IRQ Mask
19
--   0x20000020  IRQ Status
20 286 rhoads
--   0x20000030  GPIO0 Out Set bits
21
--   0x20000040  GPIO0 Out Clear bits
22 139 rhoads
--   0x20000050  GPIOA In
23
--   0x20000060  Counter
24 286 rhoads
--   0x20000070  Ethernet transmit count
25 139 rhoads
--   IRQ bits:
26
--      7   GPIO31
27 329 rhoads
--      6  ^GPIO31
28 286 rhoads
--      5   EthernetSendDone
29
--      4   EthernetReceive
30 139 rhoads
--      3   Counter(18)
31
--      2  ^Counter(18)
32
--      1  ^UartWriteBusy
33
--      0   UartDataAvailable
34 48 rhoads
---------------------------------------------------------------------
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use work.mlite_pack.all;
38
 
39
entity plasma is
40 186 rhoads
   generic(memory_type : string := "XILINX_16X"; --"DUAL_PORT_" "ALTERA_LPM";
41 286 rhoads
           log_file    : string := "UNUSED";
42 346 rhoads
           ethernet    : std_logic := '0';
43
           use_cache   : std_logic := '0');
44 286 rhoads
   port(clk          : in std_logic;
45
        reset        : in std_logic;
46 48 rhoads
 
47 286 rhoads
        uart_write   : out std_logic;
48
        uart_read    : in std_logic;
49 48 rhoads
 
50 286 rhoads
        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 356 rhoads
        mem_pause_in : in std_logic;
55
        no_ddr_start : out std_logic;
56 346 rhoads
        no_ddr_stop  : out std_logic;
57 139 rhoads
 
58 286 rhoads
        gpio0_out    : out std_logic_vector(31 downto 0);
59
        gpioA_in     : in std_logic_vector(31 downto 0));
60 48 rhoads
end; --entity plasma
61
 
62
architecture logic of plasma is
63 346 rhoads
   signal address_next      : std_logic_vector(31 downto 2);
64
   signal byte_we_next      : std_logic_vector(3 downto 0);
65
   signal cpu_address       : std_logic_vector(31 downto 0);
66
   signal cpu_byte_we       : std_logic_vector(3 downto 0);
67
   signal cpu_data_w        : std_logic_vector(31 downto 0);
68
   signal cpu_data_r        : std_logic_vector(31 downto 0);
69
   signal cpu_pause         : std_logic;
70 139 rhoads
 
71 346 rhoads
   signal data_read_uart    : std_logic_vector(7 downto 0);
72 356 rhoads
   signal write_enable      : std_logic;
73 346 rhoads
   signal eth_pause_in      : std_logic;
74
   signal eth_pause         : std_logic;
75
   signal mem_busy          : std_logic;
76 139 rhoads
 
77 346 rhoads
   signal enable_misc       : std_logic;
78
   signal enable_uart       : std_logic;
79
   signal enable_uart_read  : std_logic;
80
   signal enable_uart_write : std_logic;
81
   signal enable_eth        : std_logic;
82 139 rhoads
 
83 346 rhoads
   signal gpio0_reg         : std_logic_vector(31 downto 0);
84
   signal uart_write_busy   : std_logic;
85
   signal uart_data_avail   : std_logic;
86
   signal irq_mask_reg      : std_logic_vector(7 downto 0);
87
   signal irq_status        : std_logic_vector(7 downto 0);
88
   signal irq               : std_logic;
89
   signal irq_eth_rec       : std_logic;
90
   signal irq_eth_send      : std_logic;
91
   signal counter_reg       : std_logic_vector(31 downto 0);
92 139 rhoads
 
93 346 rhoads
   signal ram_enable        : std_logic;
94
   signal ram_byte_we       : std_logic_vector(3 downto 0);
95
   signal ram_address       : std_logic_vector(31 downto 2);
96
   signal ram_data_w        : std_logic_vector(31 downto 0);
97
   signal ram_data_r        : std_logic_vector(31 downto 0);
98
 
99
   signal cache_check       : std_logic;
100
   signal cache_checking    : std_logic;
101 356 rhoads
   signal cache_miss        : std_logic;
102 346 rhoads
   signal cache_hit         : std_logic;
103
 
104 48 rhoads
begin  --architecture
105 346 rhoads
   write_enable <= '1' when cpu_byte_we /= "0000" else '0';
106 356 rhoads
   mem_busy <= eth_pause or mem_pause_in;
107 346 rhoads
   cache_hit <= cache_checking and not cache_miss;
108
   cpu_pause <= (uart_write_busy and enable_uart and write_enable) or  --UART busy
109
      cache_miss or                                                    --Cache wait
110
      (cpu_address(28) and not cache_hit and mem_busy);                --DDR or flash                                    --DDR in use
111 286 rhoads
   irq_status <= gpioA_in(31) & not gpioA_in(31) &
112
                 irq_eth_send & irq_eth_rec &
113 139 rhoads
                 counter_reg(18) & not counter_reg(18) &
114
                 not uart_write_busy & uart_data_avail;
115
   irq <= '1' when (irq_status and irq_mask_reg) /= ZERO(7 downto 0) else '0';
116 286 rhoads
   gpio0_out(31 downto 29) <= gpio0_reg(31 downto 29);
117
   gpio0_out(23 downto 0) <= gpio0_reg(23 downto 0);
118 139 rhoads
 
119 346 rhoads
   enable_misc <= '1' when cpu_address(30 downto 28) = "010" else '0';
120
   enable_uart <= '1' when enable_misc = '1' and cpu_address(7 downto 4) = "0000" else '0';
121 139 rhoads
   enable_uart_read <= enable_uart and not write_enable;
122
   enable_uart_write <= enable_uart and write_enable;
123 346 rhoads
   enable_eth <= '1' when enable_misc = '1' and cpu_address(7 downto 4) = "0111" else '0';
124
   cpu_address(1 downto 0) <= "00";
125 139 rhoads
 
126 48 rhoads
   u1_cpu: mlite_cpu
127
      generic map (memory_type => memory_type)
128
      PORT MAP (
129 139 rhoads
         clk          => clk,
130
         reset_in     => reset,
131
         intr_in      => irq,
132 48 rhoads
 
133 346 rhoads
         address_next => address_next,             --before rising_edge(clk)
134 264 rhoads
         byte_we_next => byte_we_next,
135
 
136 346 rhoads
         address      => cpu_address(31 downto 2), --after rising_edge(clk)
137
         byte_we      => cpu_byte_we,
138
         data_w       => cpu_data_w,
139
         data_r       => cpu_data_r,
140
         mem_pause    => cpu_pause);
141 48 rhoads
 
142 356 rhoads
   opt_cache: if use_cache = '0' generate
143 346 rhoads
      cache_check <= '0';
144
      cache_checking <= '0';
145
      cache_miss <= '0';
146
   end generate;
147
 
148
   opt_cache2: if use_cache = '1' generate
149
   --Control 4KB unified cache that uses the upper 4KB of the 8KB
150
   --internal RAM.  Only lowest 2MB of DDR is cached.
151
   u_cache: cache
152
      generic map (memory_type => memory_type)
153
      PORT MAP (
154
         clk            => clk,
155
         reset          => reset,
156
         address_next   => address_next,
157
         byte_we_next   => byte_we_next,
158
         cpu_address    => cpu_address(31 downto 2),
159
         mem_busy       => mem_busy,
160
 
161
         cache_check    => cache_check,    --Stage1: address_next in first 2MB DDR
162
         cache_checking => cache_checking, --Stage2
163
         cache_miss     => cache_miss);    --Stage3
164 356 rhoads
   end generate; --opt_cache2
165
 
166
   no_ddr_start <= not eth_pause and cache_checking;
167
   no_ddr_stop <= not eth_pause and cache_miss;
168 346 rhoads
   eth_pause_in <= mem_pause_in or (not eth_pause and cache_miss and not cache_checking);
169
 
170
   misc_proc: process(clk, reset, cpu_address, enable_misc,
171
      ram_data_r, data_read, data_read_uart, cpu_pause,
172 139 rhoads
      irq_mask_reg, irq_status, gpio0_reg, write_enable,
173 346 rhoads
      cache_checking,
174
      gpioA_in, counter_reg, cpu_data_w)
175 139 rhoads
   begin
176 346 rhoads
      case cpu_address(30 downto 28) is
177
      when "000" =>         --internal RAM
178
         cpu_data_r <= ram_data_r;
179
      when "001" =>         --external RAM
180
         if cache_checking = '1' then
181
            cpu_data_r <= ram_data_r; --cache
182
         else
183
            cpu_data_r <= data_read; --DDR
184
         end if;
185
      when "010" =>         --misc
186
         case cpu_address(6 downto 4) is
187 139 rhoads
         when "000" =>      --uart
188 346 rhoads
            cpu_data_r <= ZERO(31 downto 8) & data_read_uart;
189 139 rhoads
         when "001" =>      --irq_mask
190 346 rhoads
            cpu_data_r <= ZERO(31 downto 8) & irq_mask_reg;
191 139 rhoads
         when "010" =>      --irq_status
192 346 rhoads
            cpu_data_r <= ZERO(31 downto 8) & irq_status;
193 139 rhoads
         when "011" =>      --gpio0
194 346 rhoads
            cpu_data_r <= gpio0_reg;
195 139 rhoads
         when "101" =>      --gpioA
196 346 rhoads
            cpu_data_r <= gpioA_in;
197 139 rhoads
         when "110" =>      --counter
198 346 rhoads
            cpu_data_r <= counter_reg;
199 139 rhoads
         when others =>
200 346 rhoads
            cpu_data_r <= gpioA_in;
201 139 rhoads
         end case;
202 346 rhoads
      when "011" =>         --flash
203
         cpu_data_r <= data_read;
204 139 rhoads
      when others =>
205 346 rhoads
         cpu_data_r <= ZERO;
206 139 rhoads
      end case;
207
 
208
      if reset = '1' then
209
         irq_mask_reg <= ZERO(7 downto 0);
210
         gpio0_reg <= ZERO;
211
         counter_reg <= ZERO;
212
      elsif rising_edge(clk) then
213 346 rhoads
         if cpu_pause = '0' then
214 139 rhoads
            if enable_misc = '1' and write_enable = '1' then
215 346 rhoads
               if cpu_address(6 downto 4) = "001" then
216
                  irq_mask_reg <= cpu_data_w(7 downto 0);
217
               elsif cpu_address(6 downto 4) = "011" then
218
                  gpio0_reg <= gpio0_reg or cpu_data_w;
219
               elsif cpu_address(6 downto 4) = "100" then
220
                  gpio0_reg <= gpio0_reg and not cpu_data_w;
221 139 rhoads
               end if;
222
            end if;
223
         end if;
224
         counter_reg <= bv_inc(counter_reg);
225
      end if;
226
   end process;
227
 
228 346 rhoads
   ram_enable <= '1' when address_next(30 downto 28) = "000" or
229
                  cache_check = '1' or cache_miss = '1' else '0';
230
   ram_byte_we <= byte_we_next when cache_miss = '0' else "1111";
231
   ram_address(31 downto 13) <= ZERO(31 downto 13);
232
   ram_address(12 downto 2) <= (address_next(12) or cache_check) & address_next(11 downto 2)
233
            when cache_miss = '0' else
234
            '1' & cpu_address(11 downto 2);  --Update cache after cache miss
235
   ram_data_w <= cpu_data_w when cache_miss = '0' else data_read;
236
 
237 48 rhoads
   u2_ram: ram
238
      generic map (memory_type => memory_type)
239 139 rhoads
      port map (
240
         clk               => clk,
241 346 rhoads
         enable            => ram_enable,
242
         write_byte_enable => ram_byte_we,
243
         address           => ram_address,
244
         data_write        => ram_data_w,
245
         data_read         => ram_data_r);
246 48 rhoads
 
247
   u3_uart: uart
248
      generic map (log_file => log_file)
249
      port map(
250 139 rhoads
         clk          => clk,
251
         reset        => reset,
252
         enable_read  => enable_uart_read,
253
         enable_write => enable_uart_write,
254 346 rhoads
         data_in      => cpu_data_w(7 downto 0),
255 139 rhoads
         data_out     => data_read_uart,
256
         uart_read    => uart_read,
257
         uart_write   => uart_write,
258
         busy_write   => uart_write_busy,
259
         data_avail   => uart_data_avail);
260 48 rhoads
 
261 286 rhoads
   dma_gen: if ethernet = '0' generate
262 346 rhoads
      address <= cpu_address(31 downto 2);
263
      byte_we <= cpu_byte_we;
264
      data_write <= cpu_data_w;
265 286 rhoads
      eth_pause <= '0';
266
      gpio0_out(28 downto 24) <= ZERO(28 downto 24);
267
      irq_eth_rec <= '0';
268
      irq_eth_send <= '0';
269
   end generate;
270
 
271
   dma_gen2: if ethernet = '1' generate
272
   u4_eth: eth_dma
273
      port map(
274
         clk         => clk,
275
         reset       => reset,
276
         enable_eth  => gpio0_reg(24),
277
         select_eth  => enable_eth,
278
         rec_isr     => irq_eth_rec,
279
         send_isr    => irq_eth_send,
280
 
281
         address     => address,      --to DDR
282
         byte_we     => byte_we,
283
         data_write  => data_write,
284
         data_read   => data_read,
285 346 rhoads
         pause_in    => eth_pause_in,
286 286 rhoads
 
287 346 rhoads
         mem_address => cpu_address(31 downto 2), --from CPU
288
         mem_byte_we => cpu_byte_we,
289
         data_w      => cpu_data_w,
290 286 rhoads
         pause_out   => eth_pause,
291
 
292
         E_RX_CLK    => gpioA_in(20),
293
         E_RX_DV     => gpioA_in(19),
294
         E_RXD       => gpioA_in(18 downto 15),
295
         E_TX_CLK    => gpioA_in(14),
296
         E_TX_EN     => gpio0_out(28),
297
         E_TXD       => gpio0_out(27 downto 24));
298
   end generate;
299
 
300 48 rhoads
end; --architecture logic
301 346 rhoads
 

powered by: WebSVN 2.1.0

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