📄 uart1.vhd
字号:
d8_pre <= d7_pre;
d9_pre <= d8_pre;
new_rom <= d9_pre;
end if;
end if;
end process;
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 <= "00000000000";
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 + "00000000001";
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/uart1_input_data_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/uart1_input_data_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 <= readmemh("c:/pabst/test_scratch/test/full_featured/full_1c20_sim/uart1_input_data_stream.dat");
-- prep address and pre-pulse to alert world to new contents
address <= "00000000000";
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 uart1_rx_stimulus_source is
port (
-- inputs:
signal baud_divisor : IN STD_LOGIC_VECTOR (8 DOWNTO 0);
signal clk : IN STD_LOGIC;
signal clk_en : IN STD_LOGIC;
signal reset_n : IN STD_LOGIC;
signal rx_char_ready : IN STD_LOGIC;
signal rxd : IN STD_LOGIC;
-- outputs:
signal source_rxd : OUT STD_LOGIC
);
end entity uart1_rx_stimulus_source;
architecture europa of uart1_rx_stimulus_source is
--exemplar translate_off
component uart1_tx is
port (
-- inputs:
signal baud_divisor : IN STD_LOGIC_VECTOR (8 DOWNTO 0);
signal begintransfer : IN STD_LOGIC;
signal clk : IN STD_LOGIC;
signal clk_en : IN STD_LOGIC;
signal do_force_break : IN STD_LOGIC;
signal reset_n : IN STD_LOGIC;
signal status_wr_strobe : IN STD_LOGIC;
signal tx_data : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
signal tx_wr_strobe : IN STD_LOGIC;
-- outputs:
signal tx_overrun : OUT STD_LOGIC;
signal tx_ready : OUT STD_LOGIC;
signal tx_shift_empty : OUT STD_LOGIC;
signal txd : OUT STD_LOGIC
);
end component uart1_tx;
component uart1_rx_stimulus_source_character_source_rom_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 q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
signal safe : OUT STD_LOGIC
);
end component uart1_rx_stimulus_source_character_source_rom_module;
--exemplar translate_on
signal d1_stim_data : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal delayed_unxrx_char_readyxx0 : STD_LOGIC;
signal do_send_stim_data : STD_LOGIC;
signal internal_source_rxd : STD_LOGIC;
signal module_input1 : STD_LOGIC;
signal module_input2 : STD_LOGIC;
signal module_input3 : STD_LOGIC;
signal new_rom_pulse : STD_LOGIC;
signal pickup_pulse : STD_LOGIC;
signal safe : STD_LOGIC;
signal unused_empty : STD_LOGIC;
signal unused_overrun : STD_LOGIC;
signal unused_ready : STD_LOGIC;
--exemplar translate_off
signal stim_data : STD_LOGIC_VECTOR (7 DOWNTO 0);
--exemplar translate_on
begin
--vhdl renameroo for output signals
source_rxd <= internal_source_rxd;
--exemplar translate_off
stimulus_transmitter : uart1_tx
port map(
tx_overrun => unused_overrun,
tx_ready => unused_ready,
tx_shift_empty => unused_empty,
txd => internal_source_rxd,
baud_divisor => baud_divisor,
begintransfer => do_send_stim_data,
clk => clk,
clk_en => clk_en,
do_force_break => module_input1,
reset_n => reset_n,
status_wr_strobe => module_input2,
tx_data => d1_stim_data,
tx_wr_strobe => module_input3
);
module_input1 <= std_logic'('0');
module_input2 <= std_logic'('0');
module_input3 <= std_logic'('1');
process (clk, reset_n)
begin
if reset_n = '0' then
d1_stim_data <= std_logic_vector'("00000000");
elsif clk'event and clk = '1' then
if std_logic'(do_send_stim_data) = '1' then
d1_stim_data <= stim_data;
end if;
end if;
end process;
uart1_rx_stimulus_source_character_source_rom : uart1_rx_stimulus_source_character_source_rom_module
port map(
new_rom => new_rom_pulse,
q => stim_data,
safe => safe,
clk => clk,
incr_addr => do_send_stim_data,
reset_n => reset_n
);
--delayed_unxrx_char_readyxx0, which is an e_register
process (clk, reset_n)
begin
if reset_n = '0' then
delayed_unxrx_char_readyxx0 <= std_logic'('0');
elsif clk'event and clk = '1' then
if std_logic'(clk_en) = '1' then
delayed_unxrx_char_readyxx0 <= rx_char_ready;
end if;
end if;
end process;
pickup_pulse <= NOT (rx_char_ready) AND (delayed_unxrx_char_readyxx0);
do_send_stim_data <= ((pickup_pulse OR new_rom_pulse)) AND safe;
--exemplar translate_on
--synthesis read_comments_as_HDL on
-- internal_source_rxd <= rxd;
--synthesis read_comments_as_HDL off
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 uart1_rx is
port (
-- inputs:
signal baud_divisor : IN STD_LOGIC_VECTOR (8 DOWNTO 0);
signal begintransfer : IN STD_LOGIC;
signal clk : IN STD_LOGIC;
signal clk_en : IN STD_LOGIC;
signal reset_n : IN STD_LOGIC;
signal rx_rd_strobe : IN STD_LOGIC;
signal rxd : IN STD_LOGIC;
signal status_wr_strobe : IN STD_LOGIC;
-- outputs:
signal break_detect : OUT STD_LOGIC;
signal framing_error : OUT STD_LOGIC;
signal parity_error : OUT STD_LOGIC;
signal rx_char_ready : OUT STD_LOGIC;
signal rx_data : OUT STD_LOGIC_VECTOR (7 DOWNTO 0);
signal rx_overrun : OUT STD_LOGIC
);
end entity uart1_rx;
architecture europa of uart1_rx is
component uart1_rx_stimulus_source is
port (
-- inputs:
signal baud_divisor : IN STD_LOGIC_VECTOR (8 DOWNTO 0);
signal clk : IN STD_LOGIC;
signal clk_en : IN STD_LOGIC;
signal reset_n : IN STD_LOGIC;
signal rx_char_ready : IN STD_LOGIC;
signal rxd : IN STD_LOGIC;
-- outputs:
signal source_rxd : OUT STD_LOGIC
);
end component uart1_rx_stimulus_source;
signal baud_clk_en : STD_LOGIC;
signal baud_load_value : STD_LOGIC_VECTOR (8 DOWNTO 0);
signal baud_rate_counter : STD_LOGIC_VECTOR (8 DOWNTO 0);
signal baud_rate_counter_is_zero : STD_LOGIC;
signal d1_source_rxd : STD_LOGIC;
signal delayed_unxrx_in_processxx3 : STD_LOGIC;
signal delayed_unxsync_rxdxx1 : STD_LOGIC;
signal delayed_unxsync_rxdxx2 : STD_LOGIC;
signal do_start_rx : STD_LOGIC;
signal got_new_char : STD_LOGIC;
signal half_bit_cell_divisor : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal internal_rx_char_ready : STD_LOGIC;
signal is_break : STD_LOGIC;
signal is_framing_error : STD_LOGIC;
signal raw_data_in : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal rx_in_process : STD_LOGIC;
signal rx_rd_strobe_onset : STD_LOGIC;
signal rxd_edge : STD_LOGIC;
signal rxd_falling : STD_LOGIC;
signal rxd_shift_reg : STD_LOGIC_VECTOR (9 DOWNTO 0);
signal sample_enable : STD_LOGIC;
signal shift_reg_start_bit_n : STD_LOGIC;
signal source_rxd : STD_LOGIC;
signal stop_bit : STD_LOGIC;
signal sync_rxd : STD_LOGIC;
signal unused_start_bit : STD_LOGIC;
signal unxshiftxrxd_shift_regxshift_reg_start_bit_nxx6_in : STD_LOGIC_VECTOR (9 DOWNTO 0);
signal unxshiftxrxd_shift_regxshift_reg_start_bit_nxx6_out : STD_LOGIC_VECTOR (9 DOWNTO 0);
begin
the_uart1_rx_stimulus_source : uart1_rx_stimulus_source
port map(
source_rxd => source_rxd,
baud_divisor => baud_divisor,
clk => clk,
clk_en => clk_en,
reset_n => reset_n,
rx_char_ready => internal_rx_char_ready,
rxd => rxd
);
process (clk, reset_n)
begin
if reset_n = '0' then
d1_source_rxd <= std_logic'('0');
sync_rxd <= std_logic'('0');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -