📄 jtag_uart.vhd
字号:
read(data_line, the_character_from_data_line);
-- No @ characters allowed in binary/bit_vector mode
result(mem_index) := To_stdlogicvector(the_character_from_data_line);
mem_index := mem_index + 1;
line_length := line_length - 8;
end loop; -- read characters
end loop; -- read lines
file_close (handle);
return result;
end readmemb;
-- exemplar translate_on
begin
--exemplar translate_off
q <= mem_array(CONV_INTEGER(UNSIGNED((address))));
process (clk, reset_n)
begin
if reset_n = '0' then
d1_pre <= std_logic'('0');
d2_pre <= std_logic'('0');
d3_pre <= std_logic'('0');
d4_pre <= std_logic'('0');
d5_pre <= std_logic'('0');
d6_pre <= std_logic'('0');
d7_pre <= std_logic'('0');
d8_pre <= std_logic'('0');
d9_pre <= std_logic'('0');
new_rom <= std_logic'('0');
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
d1_pre <= pre;
d2_pre <= d1_pre;
d3_pre <= d2_pre;
d4_pre <= d3_pre;
d5_pre <= d4_pre;
d6_pre <= d5_pre;
d7_pre <= d6_pre;
d8_pre <= d7_pre;
d9_pre <= d8_pre;
new_rom <= d9_pre;
end if;
end if;
end process;
num_bytes <= mutex(1);
safe <= safe_wire;
safe_wire <= to_std_logic( address < mutex(1) );
process (clk, reset_n)
begin
if reset_n = '0' then
safe_delay <= '0';
elsif clk'event and clk = '1' then -- balance ' for emacs quoting
safe_delay <= safe_wire;
end if;
end process;
process (clk, reset_n)
variable poll_count : integer := POLL_RATE; -- STD_LOGIC_VECTOR (31:0);
variable status : file_open_status; -- status for fopen
variable mutex_string : LINE; -- temp space for read/write data
variable stream_string : LINE; -- temp space for read data
variable init_done : BOOLEAN; -- only used if non-interactive
variable interactive : BOOLEAN := FALSE;
begin
if reset_n /= '1' then
address <= "000000000000";
mem_array(0) <= X"00";
mutex(0) <= X"00000000";
mutex(1) <= X"00000000";
pre <= '0';
init_done := FALSE;
elsif clk'event and clk = '1' then -- balance ' for emacs quoting
pre <= '0';
if incr_addr = '1' and safe_wire = '1' then
address <= address + "000000000001";
end if;
-- blast mutex via textio after falling edge of safe
if mutex(0) /= X"00000000" and safe_wire = '0' and safe_delay = '1' then
if interactive then -- bash mutex
file_open (status, mutex_handle, "c:/pabst/test_scratch/test/full_featured/full_1c20_sim/jtag_uart_input_mutex.dat", WRITE_MODE);
write (mutex_string, string'("0")); -- balance ' for emacs quoting
writeline (mutex_handle, mutex_string);
file_close (mutex_handle);
mutex(0) <= X"00000000";
else -- non-nteractive does not bash mutex: it stops poll counter
init_done := TRUE;
end if;
end if;
if poll_count < POLL_RATE then -- wait
if not init_done then -- stop counting if init_done is TRUE
poll_count := poll_count + 1;
end if;
else -- do the real work
poll_count := 0;
-- get mutex via textio ...
mutex(0) <= get_mutex_val ("c:/pabst/test_scratch/test/full_featured/full_1c20_sim/jtag_uart_input_mutex.dat");
if mutex(0) /= X"00000000" and safe_wire = '0' then
-- read stream into array after previous stream is complete
mutex (1) <= mutex (0); -- save mutex value for address compare
-- get mem_array via textio ...
mem_array <= readmemb("c:/pabst/test_scratch/test/full_featured/full_1c20_sim/jtag_uart_input_stream.dat");
-- prep address and pre-pulse to alert world to new contents
address <= "000000000000";
pre <= '1';
end if; -- poll_count
end if; -- clock
end if; -- reset
end process;
--exemplar translate_on
end europa;
library altera_vhdl_support;
use altera_vhdl_support.altera_vhdl_support_lib.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity jtag_uart_sim_scfifo_r is
port (
-- inputs:
signal clk : IN STD_LOGIC;
signal fifo_rd : IN STD_LOGIC;
signal rst_n : IN STD_LOGIC;
-- outputs:
signal fifo_EF : OUT STD_LOGIC;
signal fifo_rdata : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
signal rfifo_full : OUT STD_LOGIC;
signal rfifo_used : OUT STD_LOGIC_VECTOR (5 DOWNTO 0)
);
end entity jtag_uart_sim_scfifo_r;
architecture europa of jtag_uart_sim_scfifo_r is
--exemplar translate_off
component jtag_uart_drom_module is
generic (
POLL_RATE : integer := 100
);
port (
-- inputs:
signal clk : IN STD_LOGIC;
signal incr_addr : IN STD_LOGIC;
signal reset_n : IN STD_LOGIC;
-- outputs:
signal new_rom : OUT STD_LOGIC;
signal num_bytes : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
signal q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
signal safe : OUT STD_LOGIC
);
end component jtag_uart_drom_module;
--exemplar translate_on
signal bytes_left : STD_LOGIC_VECTOR (31 DOWNTO 0);
signal fifo_rd_d : STD_LOGIC;
signal internal_fifo_rdata1 : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal internal_rfifo_full1 : STD_LOGIC;
signal new_rom : STD_LOGIC;
signal num_bytes : STD_LOGIC_VECTOR (31 DOWNTO 0);
signal rfifo_entries : STD_LOGIC_VECTOR (6 DOWNTO 0);
signal safe : STD_LOGIC;
begin
--vhdl renameroo for output signals
fifo_rdata <= internal_fifo_rdata1;
--vhdl renameroo for output signals
rfifo_full <= internal_rfifo_full1;
--exemplar translate_off
jtag_uart_drom : jtag_uart_drom_module
port map(
new_rom => new_rom,
num_bytes => num_bytes,
q => internal_fifo_rdata1,
safe => safe,
clk => clk,
incr_addr => fifo_rd_d,
reset_n => rst_n
);
-- Generate rfifo_entries for simulation
process (clk, rst_n)
begin
if rst_n = '0' then
bytes_left <= std_logic_vector'("00000000000000000000000000000000");
fifo_rd_d <= std_logic'('0');
elsif clk'event and clk = '1' then
fifo_rd_d <= fifo_rd;
-- decrement on read
if std_logic'(fifo_rd_d) = '1' then
bytes_left <= A_EXT (((std_logic_vector'("0") & (bytes_left)) - (std_logic_vector'("00000000000000000000000000000000") & (A_TOSTDLOGICVECTOR(std_logic'('1'))))), 32);
end if;
-- catch new contents
if std_logic'(new_rom) = '1' then
bytes_left <= num_bytes;
end if;
end if;
end process;
fifo_EF <= to_std_logic((bytes_left = std_logic_vector'("00000000000000000000000000000000")));
internal_rfifo_full1 <= to_std_logic((bytes_left>std_logic_vector'("00000000000000000000000001000000")));
rfifo_entries <= A_EXT (A_WE_StdLogicVector((std_logic'((internal_rfifo_full1)) = '1'), std_logic_vector'("00000000000000000000000001000000"), bytes_left), 7);
rfifo_used <= rfifo_entries(5 DOWNTO 0);
--exemplar translate_on
end europa;
library altera_mf;
use altera_mf.all;
library altera_vhdl_support;
use altera_vhdl_support.altera_vhdl_support_lib.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
library lpm;
use lpm.all;
entity jtag_uart_scfifo_r is
port (
-- inputs:
signal clk : IN STD_LOGIC;
signal fifo_rd : IN STD_LOGIC;
signal rst_n : IN STD_LOGIC;
signal t_dat : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
signal wr_rfifo : IN STD_LOGIC;
-- outputs:
signal fifo_EF : OUT STD_LOGIC;
signal fifo_rdata : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
signal rfifo_full : OUT STD_LOGIC;
signal rfifo_used : OUT STD_LOGIC_VECTOR (5 DOWNTO 0)
);
end entity jtag_uart_scfifo_r;
architecture europa of jtag_uart_scfifo_r is
--exemplar translate_off
component jtag_uart_sim_scfifo_r is
port (
-- inputs:
signal clk : IN STD_LOGIC;
signal fifo_rd : IN STD_LOGIC;
signal rst_n : IN STD_LOGIC;
-- outputs:
signal fifo_EF : OUT STD_LOGIC;
signal fifo_rdata : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
signal rfifo_full : OUT STD_LOGIC;
signal rfifo_used : OUT STD_LOGIC_VECTOR (5 DOWNTO 0)
);
end component jtag_uart_sim_scfifo_r;
--exemplar translate_on
--synthesis read_comments_as_HDL on
-- component scfifo is
--GENERIC (
-- lpm_hint : STRING;
-- lpm_numwords : NATURAL;
-- lpm_showahead : STRING;
-- lpm_type : STRING;
-- lpm_width : NATURAL;
-- lpm_widthu : NATURAL;
-- overflow_checking : STRING;
-- underflow_checking : STRING;
-- use_eab : STRING
-- );
-- PORT (
-- signal empty : OUT STD_LOGIC;
-- signal full : OUT STD_LOGIC;
-- signal q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
-- signal usedw : OUT STD_LOGIC_VECTOR (5 DOWNTO 0);
-- signal clock : IN STD_LOGIC;
-- signal data : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
-- signal rdreq : IN STD_LOGIC;
-- signal wrreq : IN STD_LOGIC
-- );
-- end component scfifo;
--synthesis read_comments_as_HDL off
signal internal_fifo_EF : STD_LOGIC;
signal internal_fifo_rdata : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal internal_rfifo_full : STD_LOGIC;
signal internal_rfifo_used : STD_LOGIC_VECTOR (5 DOWNTO 0);
begin
--vhdl renameroo for output signals
fifo_EF <= internal_fifo_EF;
--vhdl renameroo for output signals
fifo_rdata <= internal_fifo_rdata;
--vhdl renameroo for output signals
rfifo_full <= internal_rfifo_full;
--vhdl renameroo for output signals
rfifo_used <= internal_rfifo_used;
--exemplar translate_off
the_jtag_uart_sim_scfifo_r : jtag_uart_sim_scfifo_r
port map(
fifo_EF => internal_fifo_EF,
fifo_rdata => internal_fifo_rdata,
rfifo_full => internal_rfifo_full,
rfifo_used => internal_rfifo_used,
clk => clk,
fifo_rd => fifo_rd,
rst_n => rst_n
);
--exemplar translate_on
--synthesis read_comments_as_HDL on
-- rfifo : scfifo
-- generic map(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -