1 |
42 |
ja_rd |
--##############################################################################
|
2 |
196 |
ja_rd |
-- WARNING: THIS FILE IS DEPRECATED and will be removed soon.
|
3 |
|
|
-- As of revision 193 the test bench used is tb/mips_tb.vhdl.
|
4 |
|
|
-- Just ignore this file.
|
5 |
42 |
ja_rd |
--
|
6 |
|
|
--------------------------------------------------------------------------------
|
7 |
|
|
-- Simulation test bench TB2 -- not synthesizable.
|
8 |
|
|
--
|
9 |
|
|
-- Simulates the CPU core connected to a simulated external static RAM and an
|
10 |
|
|
-- internal BRAM block through a stub (i.e. empty).
|
11 |
|
|
-- BRAM is initialized with the program object code, and SRAM is initialized
|
12 |
|
|
-- with data secions from program.
|
13 |
|
|
-- The makefile for the source samples include targets to build simulation test
|
14 |
|
|
-- benches using this template, use them as usage examples.
|
15 |
|
|
--
|
16 |
|
|
-- The memory setup is meant to test the basic 'dummy' cache.
|
17 |
|
|
--
|
18 |
|
|
-- Console output (at addresses compatible to Plasma's) is logged to text file
|
19 |
|
|
-- "hw_sim_console_log.txt".
|
20 |
|
|
-- IMPORTANT: The code that echoes UART TX data to the simulation console does
|
21 |
|
|
-- line buffering; it will not print anything until it gets a CR (0x0d), and
|
22 |
|
|
-- will ifnore LFs (0x0a). Bear this in mind if you see no output when you
|
23 |
|
|
-- expect it.
|
24 |
|
|
--
|
25 |
|
|
-- WARNING: Will only work on Modelsim; uses custom library SignalSpy.
|
26 |
|
|
--##############################################################################
|
27 |
162 |
ja_rd |
-- Copyright (C) 2011 Jose A. Ruiz
|
28 |
161 |
ja_rd |
--
|
29 |
|
|
-- This source file may be used and distributed without
|
30 |
|
|
-- restriction provided that this copyright statement is not
|
31 |
|
|
-- removed from the file and that any derivative work contains
|
32 |
|
|
-- the original copyright notice and the associated disclaimer.
|
33 |
|
|
--
|
34 |
|
|
-- This source file is free software; you can redistribute it
|
35 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
36 |
|
|
-- Public License as published by the Free Software Foundation;
|
37 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
38 |
|
|
-- later version.
|
39 |
|
|
--
|
40 |
|
|
-- This source is distributed in the hope that it will be
|
41 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
42 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
43 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
44 |
|
|
-- details.
|
45 |
|
|
--
|
46 |
|
|
-- You should have received a copy of the GNU Lesser General
|
47 |
|
|
-- Public License along with this source; if not, download it
|
48 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
49 |
|
|
--##############################################################################
|
50 |
42 |
ja_rd |
|
51 |
51 |
ja_rd |
library ieee;
|
52 |
42 |
ja_rd |
use ieee.std_logic_1164.all;
|
53 |
|
|
use ieee.std_logic_arith.all;
|
54 |
|
|
use ieee.std_logic_unsigned.all;
|
55 |
51 |
ja_rd |
use std.textio.all;
|
56 |
42 |
ja_rd |
|
57 |
|
|
use work.mips_pkg.all;
|
58 |
51 |
ja_rd |
use work.mips_tb_pkg.all;
|
59 |
42 |
ja_rd |
use work.txt_util.all;
|
60 |
|
|
|
61 |
|
|
entity @entity_name@ is
|
62 |
|
|
end;
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
architecture @arch_name@ of @entity_name@ is
|
66 |
|
|
|
67 |
|
|
-------------------------------------------------------------------------------
|
68 |
|
|
-- Simulation parameters
|
69 |
|
|
|
70 |
|
|
-- Master clock period
|
71 |
|
|
constant T : time := 20 ns;
|
72 |
|
|
-- Time the UART is unavailable after writing to the TX register
|
73 |
|
|
-- WARNING: slite does not simulate this. The logs may be different when > 0.0!
|
74 |
|
|
constant SIMULATED_UART_TX_TIME : time := 0.0 us;
|
75 |
|
|
|
76 |
102 |
ja_rd |
-- Simulation length in clock cycles, should be long enough (you have to try...)
|
77 |
42 |
ja_rd |
constant SIMULATION_LENGTH : integer := @sim_len@;
|
78 |
|
|
|
79 |
|
|
-- Simulated external SRAM size in 32-bit words
|
80 |
|
|
constant SRAM_SIZE : integer := @xram_size@;
|
81 |
|
|
-- Ext. SRAM address length (memory is 16 bits wide so it needs an extra address bit)
|
82 |
|
|
constant SRAM_ADDR_SIZE : integer := log2(SRAM_SIZE)+1;
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
-- BRAM table and interface signals --------------------------------------------
|
86 |
|
|
constant BRAM_SIZE : integer := @code_table_size@;
|
87 |
|
|
constant BRAM_ADDR_SIZE : integer := @code_addr_size@;
|
88 |
|
|
subtype t_bram_address is std_logic_vector(BRAM_ADDR_SIZE-1 downto 0);
|
89 |
|
|
-- (this table holds one byte-slice; the RAM will have 4 of these)
|
90 |
|
|
type t_bram is array(0 to BRAM_SIZE-1) of std_logic_vector(7 downto 0);
|
91 |
|
|
|
92 |
|
|
signal bram_rd_addr : t_bram_address;
|
93 |
|
|
signal bram_wr_addr : t_bram_address;
|
94 |
|
|
signal bram_rd_data : t_word;
|
95 |
|
|
signal bram_wr_data : t_word;
|
96 |
|
|
signal bram_byte_we : std_logic_vector(3 downto 0);
|
97 |
51 |
ja_rd |
signal bram_data_rd_vma : std_logic;
|
98 |
42 |
ja_rd |
|
99 |
|
|
-- bram0 is LSB, bram3 is MSB
|
100 |
|
|
signal bram3 : t_bram := (@code3@);
|
101 |
|
|
signal bram2 : t_bram := (@code2@);
|
102 |
|
|
signal bram1 : t_bram := (@code1@);
|
103 |
|
|
signal bram0 : t_bram := (@code0@);
|
104 |
|
|
|
105 |
|
|
-- This is a 16-bit SRAM split in 2 byte slices; so each slice will have two
|
106 |
|
|
-- bytes for each word of SRAM_SIZE
|
107 |
|
|
type t_sram is array(0 to SRAM_SIZE*2-1) of std_logic_vector(7 downto 0);
|
108 |
|
|
signal sram1 : t_sram := (@data31@);
|
109 |
|
|
signal sram0 : t_sram := (@data20@);
|
110 |
|
|
|
111 |
77 |
ja_rd |
signal sram_chip_addr : std_logic_vector(SRAM_ADDR_SIZE downto 1);
|
112 |
|
|
signal sram_output : std_logic_vector(15 downto 0);
|
113 |
|
|
|
114 |
74 |
ja_rd |
-- PROM table and interface signals --------------------------------------------
|
115 |
42 |
ja_rd |
|
116 |
74 |
ja_rd |
-- We'll simulate a 16-bit-wide static PROM (e.g. a Flash) with some serious
|
117 |
|
|
-- cycle time (70 or 90 ns).
|
118 |
|
|
|
119 |
77 |
ja_rd |
constant PROM_SIZE : integer := @prom_size@;
|
120 |
|
|
constant PROM_ADDR_SIZE : integer := log2(PROM_SIZE);
|
121 |
74 |
ja_rd |
|
122 |
77 |
ja_rd |
subtype t_prom_address is std_logic_vector(PROM_ADDR_SIZE-1 downto 0);
|
123 |
|
|
type t_prom is array(0 to PROM_SIZE-1) of t_word;
|
124 |
74 |
ja_rd |
|
125 |
77 |
ja_rd |
signal prom_rd_addr : t_prom_address;
|
126 |
|
|
signal prom_output : std_logic_vector(7 downto 0);
|
127 |
|
|
signal prom_oe_n : std_logic;
|
128 |
|
|
|
129 |
|
|
-- bram0 is LSB, bram3 is MSB
|
130 |
|
|
signal prom : t_prom := (@flash@);
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
74 |
ja_rd |
-- I/O devices -----------------------------------------------------------------
|
135 |
|
|
|
136 |
42 |
ja_rd |
signal data_uart : std_logic_vector(31 downto 0);
|
137 |
|
|
signal data_uart_status : std_logic_vector(31 downto 0);
|
138 |
|
|
signal uart_tx_rdy : std_logic := '1';
|
139 |
|
|
signal uart_rx_rdy : std_logic := '1';
|
140 |
|
|
|
141 |
|
|
--------------------------------------------------------------------------------
|
142 |
|
|
|
143 |
|
|
signal clk : std_logic := '0';
|
144 |
|
|
signal reset : std_logic := '1';
|
145 |
|
|
signal interrupt : std_logic := '0';
|
146 |
|
|
signal done : std_logic := '0';
|
147 |
|
|
|
148 |
|
|
-- interface to asynchronous 16-bit-wide external SRAM
|
149 |
77 |
ja_rd |
signal sram_address : std_logic_vector(31 downto 0);
|
150 |
|
|
signal sram_data_rd : std_logic_vector(15 downto 0);
|
151 |
|
|
signal sram_data_wr : std_logic_vector(15 downto 0);
|
152 |
42 |
ja_rd |
signal sram_byte_we_n : std_logic_vector(1 downto 0);
|
153 |
|
|
signal sram_oe_n : std_logic;
|
154 |
|
|
|
155 |
|
|
-- interface cpu-cache
|
156 |
97 |
ja_rd |
signal cpu_data_addr : t_word;
|
157 |
42 |
ja_rd |
signal cpu_data_rd_vma : std_logic;
|
158 |
|
|
signal cpu_data_rd : t_word;
|
159 |
|
|
signal cpu_code_rd_addr : t_pc;
|
160 |
|
|
signal cpu_code_rd : t_word;
|
161 |
|
|
signal cpu_code_rd_vma : std_logic;
|
162 |
|
|
signal cpu_data_wr : t_word;
|
163 |
|
|
signal cpu_byte_we : std_logic_vector(3 downto 0);
|
164 |
|
|
signal cpu_mem_wait : std_logic;
|
165 |
102 |
ja_rd |
signal cpu_ic_invalidate : std_logic;
|
166 |
|
|
signal cpu_cache_enable : std_logic;
|
167 |
42 |
ja_rd |
|
168 |
|
|
-- interface to i/o
|
169 |
|
|
signal io_rd_data : std_logic_vector(31 downto 0);
|
170 |
|
|
signal io_wr_data : std_logic_vector(31 downto 0);
|
171 |
|
|
signal io_rd_addr : std_logic_vector(31 downto 2);
|
172 |
|
|
signal io_wr_addr : std_logic_vector(31 downto 2);
|
173 |
|
|
signal io_rd_vma : std_logic;
|
174 |
|
|
signal io_byte_we : std_logic_vector(3 downto 0);
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
--------------------------------------------------------------------------------
|
178 |
|
|
-- Logging signals
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
-- Log file
|
182 |
51 |
ja_rd |
file log_file: TEXT open write_mode is "hw_sim_log.txt";
|
183 |
42 |
ja_rd |
|
184 |
|
|
-- Console output log file
|
185 |
|
|
file con_file: TEXT open write_mode is "hw_sim_console_log.txt";
|
186 |
|
|
|
187 |
|
|
-- Maximum line size of for console output log. Lines longer than this will be
|
188 |
|
|
-- truncated.
|
189 |
|
|
constant CONSOLE_LOG_LINE_SIZE : integer := 1024*4;
|
190 |
|
|
|
191 |
|
|
-- Console log line buffer
|
192 |
|
|
signal con_line_buf : string(1 to CONSOLE_LOG_LINE_SIZE);
|
193 |
|
|
signal con_line_ix : integer := 1;
|
194 |
|
|
|
195 |
51 |
ja_rd |
signal log_info : t_log_info;
|
196 |
|
|
|
197 |
42 |
ja_rd |
-- Debug signals ---------------------------------------------------------------
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
signal full_rd_addr : std_logic_vector(31 downto 0);
|
201 |
|
|
signal full_wr_addr : std_logic_vector(31 downto 0);
|
202 |
|
|
signal full_code_addr : std_logic_vector(31 downto 0);
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
begin
|
206 |
|
|
|
207 |
|
|
cpu: entity work.mips_cpu
|
208 |
|
|
port map (
|
209 |
|
|
interrupt => '0',
|
210 |
|
|
|
211 |
97 |
ja_rd |
data_addr => cpu_data_addr,
|
212 |
42 |
ja_rd |
data_rd_vma => cpu_data_rd_vma,
|
213 |
|
|
data_rd => cpu_data_rd,
|
214 |
|
|
|
215 |
|
|
code_rd_addr=> cpu_code_rd_addr,
|
216 |
|
|
code_rd => cpu_code_rd,
|
217 |
|
|
code_rd_vma => cpu_code_rd_vma,
|
218 |
|
|
|
219 |
|
|
data_wr => cpu_data_wr,
|
220 |
|
|
byte_we => cpu_byte_we,
|
221 |
|
|
|
222 |
|
|
mem_wait => cpu_mem_wait,
|
223 |
102 |
ja_rd |
cache_enable=> cpu_cache_enable,
|
224 |
|
|
ic_invalidate=>cpu_ic_invalidate,
|
225 |
42 |
ja_rd |
|
226 |
|
|
clk => clk,
|
227 |
|
|
reset => reset
|
228 |
|
|
);
|
229 |
|
|
|
230 |
97 |
ja_rd |
|
231 |
125 |
ja_rd |
cache: entity work.mips_cache
|
232 |
42 |
ja_rd |
generic map (
|
233 |
|
|
BRAM_ADDR_SIZE => BRAM_ADDR_SIZE,
|
234 |
97 |
ja_rd |
SRAM_ADDR_SIZE => 32,-- we need the full address to decode sram vs flash
|
235 |
|
|
LINE_SIZE => 4,
|
236 |
|
|
CACHE_SIZE => 256
|
237 |
42 |
ja_rd |
)
|
238 |
|
|
port map (
|
239 |
|
|
clk => clk,
|
240 |
|
|
reset => reset,
|
241 |
|
|
|
242 |
|
|
-- Interface to CPU core
|
243 |
97 |
ja_rd |
data_addr => cpu_data_addr,
|
244 |
42 |
ja_rd |
data_rd => cpu_data_rd,
|
245 |
|
|
data_rd_vma => cpu_data_rd_vma,
|
246 |
|
|
|
247 |
|
|
code_rd_addr => cpu_code_rd_addr,
|
248 |
|
|
code_rd => cpu_code_rd,
|
249 |
|
|
code_rd_vma => cpu_code_rd_vma,
|
250 |
97 |
ja_rd |
|
251 |
42 |
ja_rd |
byte_we => cpu_byte_we,
|
252 |
|
|
data_wr => cpu_data_wr,
|
253 |
|
|
|
254 |
|
|
mem_wait => cpu_mem_wait,
|
255 |
102 |
ja_rd |
cache_enable => cpu_cache_enable,
|
256 |
|
|
ic_invalidate => cpu_ic_invalidate,
|
257 |
137 |
ja_rd |
unmapped => OPEN,
|
258 |
42 |
ja_rd |
|
259 |
|
|
-- interface to FPGA i/o devices
|
260 |
|
|
io_rd_data => io_rd_data,
|
261 |
|
|
io_wr_data => io_wr_data,
|
262 |
|
|
io_rd_addr => io_rd_addr,
|
263 |
|
|
io_wr_addr => io_wr_addr,
|
264 |
|
|
io_rd_vma => io_rd_vma,
|
265 |
|
|
io_byte_we => io_byte_we,
|
266 |
|
|
|
267 |
|
|
-- interface to synchronous 32-bit-wide FPGA BRAM
|
268 |
|
|
bram_rd_data => bram_rd_data,
|
269 |
|
|
bram_wr_data => bram_wr_data,
|
270 |
|
|
bram_rd_addr => bram_rd_addr,
|
271 |
|
|
bram_wr_addr => bram_wr_addr,
|
272 |
|
|
bram_byte_we => bram_byte_we,
|
273 |
51 |
ja_rd |
bram_data_rd_vma=> bram_data_rd_vma,
|
274 |
42 |
ja_rd |
|
275 |
|
|
-- interface to asynchronous 16-bit-wide external SRAM
|
276 |
|
|
sram_address => sram_address,
|
277 |
77 |
ja_rd |
sram_data_rd => sram_data_rd,
|
278 |
|
|
sram_data_wr => sram_data_wr,
|
279 |
42 |
ja_rd |
sram_byte_we_n => sram_byte_we_n,
|
280 |
|
|
sram_oe_n => sram_oe_n
|
281 |
|
|
);
|
282 |
|
|
|
283 |
|
|
---------------------------------------------------------------------------
|
284 |
|
|
-- Master clock: free running clock used as main module clock
|
285 |
|
|
run_master_clock:
|
286 |
|
|
process(done, clk)
|
287 |
|
|
begin
|
288 |
|
|
if done = '0' then
|
289 |
|
|
clk <= not clk after T/2;
|
290 |
|
|
end if;
|
291 |
|
|
end process run_master_clock;
|
292 |
|
|
|
293 |
|
|
drive_uut:
|
294 |
|
|
process
|
295 |
|
|
variable l : line;
|
296 |
|
|
begin
|
297 |
|
|
wait for T*4;
|
298 |
|
|
reset <= '0';
|
299 |
|
|
|
300 |
|
|
wait for T*SIMULATION_LENGTH;
|
301 |
|
|
|
302 |
|
|
-- Flush console output to log console file (in case the end of the
|
303 |
|
|
-- simulation caugh an unterminated line in the buffer)
|
304 |
|
|
if con_line_ix > 1 then
|
305 |
|
|
write(l, con_line_buf(1 to con_line_ix));
|
306 |
|
|
writeline(con_file, l);
|
307 |
|
|
end if;
|
308 |
|
|
|
309 |
|
|
print("TB0 finished");
|
310 |
|
|
done <= '1';
|
311 |
|
|
wait;
|
312 |
|
|
|
313 |
|
|
end process drive_uut;
|
314 |
|
|
|
315 |
97 |
ja_rd |
full_rd_addr <= cpu_data_addr;
|
316 |
|
|
full_wr_addr <= cpu_data_addr(31 downto 2) & "00";
|
317 |
42 |
ja_rd |
full_code_addr <= cpu_code_rd_addr & "00";
|
318 |
|
|
|
319 |
|
|
data_ram_block:
|
320 |
|
|
process(clk)
|
321 |
|
|
begin
|
322 |
|
|
if clk'event and clk='1' then
|
323 |
|
|
if reset='0' then
|
324 |
|
|
bram_rd_data <=
|
325 |
|
|
bram3(conv_integer(unsigned(bram_rd_addr))) &
|
326 |
|
|
bram2(conv_integer(unsigned(bram_rd_addr))) &
|
327 |
|
|
bram1(conv_integer(unsigned(bram_rd_addr))) &
|
328 |
|
|
bram0(conv_integer(unsigned(bram_rd_addr)));
|
329 |
|
|
|
330 |
|
|
if bram_byte_we(3)='1' then
|
331 |
|
|
bram3(conv_integer(unsigned(bram_wr_addr))) <= cpu_data_wr(31 downto 24);
|
332 |
|
|
end if;
|
333 |
|
|
if bram_byte_we(2)='1' then
|
334 |
|
|
bram2(conv_integer(unsigned(bram_wr_addr))) <= cpu_data_wr(23 downto 16);
|
335 |
|
|
end if;
|
336 |
|
|
if bram_byte_we(1)='1' then
|
337 |
|
|
bram1(conv_integer(unsigned(bram_wr_addr))) <= cpu_data_wr(15 downto 8);
|
338 |
|
|
end if;
|
339 |
|
|
if bram_byte_we(0)='1' then
|
340 |
|
|
bram0(conv_integer(unsigned(bram_wr_addr))) <= cpu_data_wr( 7 downto 0);
|
341 |
|
|
end if;
|
342 |
|
|
end if;
|
343 |
|
|
end if;
|
344 |
|
|
end process data_ram_block;
|
345 |
|
|
|
346 |
77 |
ja_rd |
sram_data_rd <=
|
347 |
|
|
X"00" & prom_output when sram_address(31 downto 27)="10110" else
|
348 |
|
|
sram_output;
|
349 |
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
-- Do a very basic simulation of an external SRAM ---------------
|
353 |
|
|
|
354 |
|
|
sram_chip_addr <= sram_address(SRAM_ADDR_SIZE downto 1);
|
355 |
|
|
|
356 |
|
|
-- FIXME should add some verification of /WE
|
357 |
|
|
sram_output <=
|
358 |
|
|
sram1(conv_integer(unsigned(sram_chip_addr))) &
|
359 |
|
|
sram0(conv_integer(unsigned(sram_chip_addr))) when sram_oe_n='0'
|
360 |
42 |
ja_rd |
else (others => 'Z');
|
361 |
|
|
|
362 |
77 |
ja_rd |
simulated_sram_write:
|
363 |
51 |
ja_rd |
process(sram_byte_we_n, sram_address, sram_oe_n)
|
364 |
42 |
ja_rd |
begin
|
365 |
51 |
ja_rd |
-- Write cycle
|
366 |
|
|
-- FIXME should add OE\ to write control logic
|
367 |
42 |
ja_rd |
if sram_byte_we_n'event or sram_address'event then
|
368 |
|
|
if sram_byte_we_n(1)='0' then
|
369 |
77 |
ja_rd |
sram1(conv_integer(unsigned(sram_chip_addr))) <= sram_data_wr(15 downto 8);
|
370 |
42 |
ja_rd |
end if;
|
371 |
|
|
if sram_byte_we_n(0)='0' then
|
372 |
77 |
ja_rd |
sram0(conv_integer(unsigned(sram_chip_addr))) <= sram_data_wr( 7 downto 0);
|
373 |
51 |
ja_rd |
end if;
|
374 |
|
|
end if;
|
375 |
77 |
ja_rd |
end process simulated_sram_write;
|
376 |
51 |
ja_rd |
|
377 |
|
|
|
378 |
74 |
ja_rd |
-- Do a very basic simulation of an external PROM wired to the same bus
|
379 |
|
|
-- as the sram (both are static).
|
380 |
|
|
|
381 |
77 |
ja_rd |
prom_rd_addr <= sram_address(PROM_ADDR_SIZE+1 downto 2);
|
382 |
74 |
ja_rd |
|
383 |
77 |
ja_rd |
prom_oe_n <= sram_oe_n;
|
384 |
|
|
|
385 |
|
|
prom_output <=
|
386 |
|
|
prom(conv_integer(unsigned(prom_rd_addr)))(31 downto 24) when prom_oe_n='0' and sram_address(1 downto 0)="00" else
|
387 |
|
|
prom(conv_integer(unsigned(prom_rd_addr)))(23 downto 16) when prom_oe_n='0' and sram_address(1 downto 0)="01" else
|
388 |
|
|
prom(conv_integer(unsigned(prom_rd_addr)))(15 downto 8) when prom_oe_n='0' and sram_address(1 downto 0)="10" else
|
389 |
|
|
prom(conv_integer(unsigned(prom_rd_addr)))( 7 downto 0) when prom_oe_n='0' and sram_address(1 downto 0)="11" else
|
390 |
86 |
ja_rd |
(others => 'Z');
|
391 |
77 |
ja_rd |
|
392 |
|
|
|
393 |
42 |
ja_rd |
simulated_io:
|
394 |
|
|
process(clk)
|
395 |
|
|
variable i : integer;
|
396 |
|
|
variable uart_data : integer;
|
397 |
|
|
begin
|
398 |
|
|
if clk'event and clk='1' then
|
399 |
|
|
|
400 |
|
|
if io_byte_we/="0000" then
|
401 |
|
|
if io_wr_addr(31 downto 28)=X"2" then
|
402 |
|
|
-- Write to UART
|
403 |
|
|
|
404 |
|
|
-- If we're simulating the UART TX time, pulse RDY low
|
405 |
|
|
if SIMULATED_UART_TX_TIME > 0 us then
|
406 |
|
|
uart_tx_rdy <= '0', '1' after SIMULATED_UART_TX_TIME;
|
407 |
|
|
end if;
|
408 |
|
|
|
409 |
|
|
-- TX data may come from the high or low byte (opcodes.s
|
410 |
|
|
-- uses high byte, no_op.c uses low)
|
411 |
|
|
if io_byte_we(0)='1' then
|
412 |
|
|
uart_data := conv_integer(unsigned(io_wr_data(7 downto 0)));
|
413 |
|
|
else
|
414 |
|
|
uart_data := conv_integer(unsigned(io_wr_data(31 downto 24)));
|
415 |
|
|
end if;
|
416 |
|
|
|
417 |
|
|
-- UART TX data goes to output after a bit of line-buffering
|
418 |
|
|
-- and editing
|
419 |
|
|
if uart_data = 10 then
|
420 |
|
|
-- CR received: print output string and clear it
|
421 |
|
|
print(con_file, con_line_buf(1 to con_line_ix));
|
422 |
|
|
con_line_ix <= 1;
|
423 |
|
|
for i in 1 to con_line_buf'high loop
|
424 |
|
|
con_line_buf(i) <= ' ';
|
425 |
|
|
end loop;
|
426 |
|
|
elsif uart_data = 13 then
|
427 |
|
|
-- ignore LF
|
428 |
|
|
else
|
429 |
|
|
-- append char to output string
|
430 |
|
|
if con_line_ix < con_line_buf'high then
|
431 |
|
|
con_line_buf(con_line_ix) <= character'val(uart_data);
|
432 |
|
|
con_line_ix <= con_line_ix + 1;
|
433 |
|
|
end if;
|
434 |
|
|
end if;
|
435 |
|
|
end if;
|
436 |
|
|
end if;
|
437 |
|
|
end if;
|
438 |
|
|
end process simulated_io;
|
439 |
|
|
|
440 |
|
|
-- UART read registers; only status, and hardwired, for the time being
|
441 |
51 |
ja_rd |
io_rd_data <= X"00000003";
|
442 |
42 |
ja_rd |
data_uart <= data_uart_status;
|
443 |
|
|
data_uart_status <= X"0000000" & "00" & uart_tx_rdy & uart_rx_rdy;
|
444 |
|
|
|
445 |
51 |
ja_rd |
log_execution:
|
446 |
42 |
ja_rd |
process
|
447 |
|
|
begin
|
448 |
51 |
ja_rd |
log_cpu_activity(clk, reset, done,
|
449 |
86 |
ja_rd |
"@entity_name@/cpu", log_info, "log_info",
|
450 |
|
|
@log_trigger_addr@, log_file);
|
451 |
42 |
ja_rd |
wait;
|
452 |
51 |
ja_rd |
end process log_execution;
|
453 |
42 |
ja_rd |
|
454 |
|
|
|
455 |
|
|
end architecture @arch_name@;
|