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 |
|
|
-- 0x00000000 - 0x0000ffff Internal RAM (16KB)
|
14 |
|
|
-- 0x10000000 - 0x000fffff External RAM (1MB)
|
15 |
|
|
-- 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 |
|
|
-- 0x20000030 GPIO0 Out
|
21 |
|
|
-- 0x20000050 GPIOA In
|
22 |
|
|
-- 0x20000060 Counter
|
23 |
|
|
-- IRQ bits:
|
24 |
|
|
-- 7 GPIO31
|
25 |
|
|
-- 6 GPIO30
|
26 |
|
|
-- 5 ^GPIO31
|
27 |
|
|
-- 4 ^GPIO30
|
28 |
|
|
-- 3 Counter(18)
|
29 |
|
|
-- 2 ^Counter(18)
|
30 |
|
|
-- 1 ^UartWriteBusy
|
31 |
|
|
-- 0 UartDataAvailable
|
32 |
48 |
rhoads |
---------------------------------------------------------------------
|
33 |
|
|
library ieee;
|
34 |
|
|
use ieee.std_logic_1164.all;
|
35 |
|
|
use work.mlite_pack.all;
|
36 |
|
|
|
37 |
|
|
entity plasma is
|
38 |
139 |
rhoads |
generic(memory_type : string := "XILINX_X16"; --"DUAL_PORT_" "ALTERA_LPM";
|
39 |
48 |
rhoads |
log_file : string := "UNUSED");
|
40 |
139 |
rhoads |
port(clk : in std_logic;
|
41 |
|
|
reset : in std_logic;
|
42 |
48 |
rhoads |
|
43 |
139 |
rhoads |
uart_write : out std_logic;
|
44 |
|
|
uart_read : in std_logic;
|
45 |
48 |
rhoads |
|
46 |
139 |
rhoads |
address : out std_logic_vector(31 downto 2);
|
47 |
|
|
data_write : out std_logic_vector(31 downto 0);
|
48 |
|
|
data_read : in std_logic_vector(31 downto 0);
|
49 |
|
|
write_byte_enable : out std_logic_vector(3 downto 0);
|
50 |
|
|
mem_pause_in : in std_logic;
|
51 |
|
|
|
52 |
|
|
gpio0_out : out std_logic_vector(31 downto 0);
|
53 |
|
|
gpioA_in : in std_logic_vector(31 downto 0));
|
54 |
48 |
rhoads |
end; --entity plasma
|
55 |
|
|
|
56 |
|
|
architecture logic of plasma is
|
57 |
139 |
rhoads |
signal address_reg : std_logic_vector(31 downto 2);
|
58 |
|
|
signal data_write_reg : std_logic_vector(31 downto 0);
|
59 |
|
|
signal write_byte_enable_reg : std_logic_vector(3 downto 0);
|
60 |
|
|
|
61 |
|
|
signal mem_address : std_logic_vector(31 downto 0);
|
62 |
|
|
signal mem_data_read : std_logic_vector(31 downto 0);
|
63 |
|
|
signal mem_data_write : std_logic_vector(31 downto 0);
|
64 |
|
|
signal mem_write_byte_enable : std_logic_vector(3 downto 0);
|
65 |
|
|
signal data_read_ram : std_logic_vector(31 downto 0);
|
66 |
|
|
signal data_read_uart : std_logic_vector(7 downto 0);
|
67 |
|
|
signal write_enable : std_logic;
|
68 |
|
|
signal mem_pause : std_logic;
|
69 |
|
|
|
70 |
|
|
signal enable_internal_ram : std_logic;
|
71 |
|
|
signal enable_misc : std_logic;
|
72 |
|
|
signal enable_uart : std_logic;
|
73 |
|
|
signal enable_uart_read : std_logic;
|
74 |
|
|
signal enable_uart_write : std_logic;
|
75 |
|
|
|
76 |
|
|
signal gpio0_reg : std_logic_vector(31 downto 0);
|
77 |
|
|
|
78 |
|
|
signal uart_write_busy : std_logic;
|
79 |
|
|
signal uart_data_avail : std_logic;
|
80 |
|
|
signal irq_mask_reg : std_logic_vector(7 downto 0);
|
81 |
|
|
signal irq_status : std_logic_vector(7 downto 0);
|
82 |
|
|
signal irq : std_logic;
|
83 |
|
|
signal counter_reg : std_logic_vector(31 downto 0);
|
84 |
|
|
|
85 |
48 |
rhoads |
begin --architecture
|
86 |
139 |
rhoads |
write_byte_enable <= write_byte_enable_reg;
|
87 |
|
|
data_write <= data_write_reg;
|
88 |
|
|
address <= address_reg;
|
89 |
48 |
rhoads |
|
90 |
139 |
rhoads |
write_enable <= '1' when write_byte_enable_reg /= "0000" else '0';
|
91 |
|
|
mem_pause <= mem_pause_in or (uart_write_busy and enable_uart and write_enable);
|
92 |
|
|
irq_status <= gpioA_in(31 downto 30) & (gpioA_in(31 downto 30) xor "11") &
|
93 |
|
|
counter_reg(18) & not counter_reg(18) &
|
94 |
|
|
not uart_write_busy & uart_data_avail;
|
95 |
|
|
irq <= '1' when (irq_status and irq_mask_reg) /= ZERO(7 downto 0) else '0';
|
96 |
|
|
gpio0_out <= gpio0_reg;
|
97 |
|
|
|
98 |
|
|
enable_internal_ram <= '1' when mem_address(30 downto 28) = "000" else '0';
|
99 |
|
|
enable_misc <= '1' when address_reg(30 downto 28) = "010" else '0';
|
100 |
|
|
enable_uart <= '1' when enable_misc = '1' and address_reg(7 downto 4) = "0000" else '0';
|
101 |
|
|
enable_uart_read <= enable_uart and not write_enable;
|
102 |
|
|
enable_uart_write <= enable_uart and write_enable;
|
103 |
|
|
|
104 |
48 |
rhoads |
u1_cpu: mlite_cpu
|
105 |
|
|
generic map (memory_type => memory_type)
|
106 |
|
|
PORT MAP (
|
107 |
139 |
rhoads |
clk => clk,
|
108 |
|
|
reset_in => reset,
|
109 |
|
|
intr_in => irq,
|
110 |
48 |
rhoads |
|
111 |
|
|
mem_address => mem_address,
|
112 |
139 |
rhoads |
mem_data_w => mem_data_write,
|
113 |
|
|
mem_data_r => mem_data_read,
|
114 |
|
|
mem_byte_we => mem_write_byte_enable,
|
115 |
48 |
rhoads |
mem_pause => mem_pause);
|
116 |
|
|
|
117 |
139 |
rhoads |
misc_proc: process(clk, reset, mem_address, address_reg, enable_misc,
|
118 |
|
|
data_read_ram, data_read, data_read_uart, mem_pause,
|
119 |
|
|
irq_mask_reg, irq_status, gpio0_reg, write_enable,
|
120 |
|
|
gpioA_in, counter_reg, mem_data_write, data_write_reg)
|
121 |
|
|
begin
|
122 |
|
|
case address_reg(30 downto 28) is
|
123 |
|
|
when "000" => --internal RAM
|
124 |
|
|
mem_data_read <= data_read_ram;
|
125 |
|
|
when "001" => --external RAM
|
126 |
|
|
mem_data_read <= data_read;
|
127 |
|
|
when "010" => --misc
|
128 |
|
|
case address_reg(6 downto 4) is
|
129 |
|
|
when "000" => --uart
|
130 |
|
|
mem_data_read <= ZERO(31 downto 8) & data_read_uart;
|
131 |
|
|
when "001" => --irq_mask
|
132 |
|
|
mem_data_read <= ZERO(31 downto 8) & irq_mask_reg;
|
133 |
|
|
when "010" => --irq_status
|
134 |
|
|
mem_data_read <= ZERO(31 downto 8) & irq_status;
|
135 |
|
|
when "011" => --gpio0
|
136 |
|
|
mem_data_read <= gpio0_reg;
|
137 |
|
|
when "101" => --gpioA
|
138 |
|
|
mem_data_read <= gpioA_in;
|
139 |
|
|
when "110" => --counter
|
140 |
|
|
mem_data_read <= counter_reg;
|
141 |
|
|
when others =>
|
142 |
|
|
mem_data_read <= gpioA_in;
|
143 |
|
|
end case;
|
144 |
|
|
when others =>
|
145 |
|
|
mem_data_read <= ZERO;
|
146 |
|
|
end case;
|
147 |
|
|
|
148 |
|
|
if reset = '1' then
|
149 |
|
|
address_reg <= ZERO(31 downto 2);
|
150 |
|
|
data_write_reg <= ZERO;
|
151 |
|
|
write_byte_enable_reg <= ZERO(3 downto 0);
|
152 |
|
|
irq_mask_reg <= ZERO(7 downto 0);
|
153 |
|
|
gpio0_reg <= ZERO;
|
154 |
|
|
counter_reg <= ZERO;
|
155 |
|
|
elsif rising_edge(clk) then
|
156 |
|
|
if mem_pause = '0' then
|
157 |
|
|
address_reg <= mem_address(31 downto 2);
|
158 |
|
|
data_write_reg <= mem_data_write;
|
159 |
|
|
write_byte_enable_reg <= mem_write_byte_enable;
|
160 |
|
|
if enable_misc = '1' and write_enable = '1' then
|
161 |
|
|
if address_reg(6 downto 4) = "001" then
|
162 |
|
|
irq_mask_reg <= data_write_reg(7 downto 0);
|
163 |
|
|
elsif address_reg(6 downto 4) = "011" then
|
164 |
|
|
gpio0_reg <= data_write_reg;
|
165 |
|
|
end if;
|
166 |
|
|
end if;
|
167 |
|
|
end if;
|
168 |
|
|
counter_reg <= bv_inc(counter_reg);
|
169 |
|
|
end if;
|
170 |
|
|
end process;
|
171 |
|
|
|
172 |
48 |
rhoads |
u2_ram: ram
|
173 |
|
|
generic map (memory_type => memory_type)
|
174 |
139 |
rhoads |
port map (
|
175 |
|
|
clk => clk,
|
176 |
|
|
enable => enable_internal_ram,
|
177 |
|
|
write_byte_enable => mem_write_byte_enable,
|
178 |
|
|
address => mem_address(31 downto 2),
|
179 |
|
|
data_write => mem_data_write,
|
180 |
|
|
data_read => data_read_ram);
|
181 |
48 |
rhoads |
|
182 |
|
|
u3_uart: uart
|
183 |
|
|
generic map (log_file => log_file)
|
184 |
|
|
port map(
|
185 |
139 |
rhoads |
clk => clk,
|
186 |
|
|
reset => reset,
|
187 |
|
|
enable_read => enable_uart_read,
|
188 |
|
|
enable_write => enable_uart_write,
|
189 |
|
|
data_in => data_write_reg(7 downto 0),
|
190 |
|
|
data_out => data_read_uart,
|
191 |
|
|
uart_read => uart_read,
|
192 |
|
|
uart_write => uart_write,
|
193 |
|
|
busy_write => uart_write_busy,
|
194 |
|
|
data_avail => uart_data_avail);
|
195 |
48 |
rhoads |
|
196 |
|
|
end; --architecture logic
|