⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart1.vhd

📁 nois 2cpu 硬件实现编程
💻 VHD
📖 第 1 页 / 共 4 页
字号:
--Legal Notice: (C)2006 Altera Corporation. All rights reserved.  Your--use of Altera Corporation's design tools, logic functions and other--software and tools, and its AMPP partner logic functions, and any--output files any of the foregoing (including device programming or--simulation files), and any associated documentation or information are--expressly subject to the terms and conditions of the Altera Program--License Subscription Agreement or other applicable license agreement,--including, without limitation, that your use is for the sole purpose--of programming logic devices manufactured by Altera and sold by Altera--or its authorized distributors.  Please refer to the applicable--agreement for further details.-- turn off superfluous VHDL processor warnings -- altera message_level Level1 -- altera message_off 10034 10035 10036 10037 10230 10240 10030 library altera;use altera.altera_europa_support_lib.all;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;library std;use std.textio.all;entity uart1_log_module is         port (              -- inputs:                 signal clk : IN STD_LOGIC;                 signal data : IN STD_LOGIC_VECTOR (7 DOWNTO 0);                 signal strobe : IN STD_LOGIC;                 signal valid : IN STD_LOGIC              );end entity uart1_log_module;architecture europa of uart1_log_module is    file text_handle : TEXT ;                             -- synthesis translate_off  -- purpose: convert 8 bit signal data to 8 bit string  FUNCTION bin_to_char(vec_to_convert : STD_LOGIC_VECTOR (7 downto 0))    RETURN CHARACTER IS    VARIABLE result: CHARACTER;  BEGIN    CASE vec_to_convert IS      -- cover basic ascii printable characters...      when X"0a" => result := lf; -- \n, linefeed      when X"0d" => result := nul; -- \r, Ctrl-M      when X"09" => result := ht; -- \t, Ctrl-I, TAB      when X"20" => result := ' ' ;      when X"21" => result := '!' ;      when X"22" => result := '"' ;      when X"23" => result := '#' ;      when X"24" => result := '$' ;      when X"25" => result := '%' ;      when X"26" => result := '&' ;      when X"27" => result := ''' ; -- sync ' char for hilighting txt editors      when X"28" => result := '(' ;      when X"29" => result := ')' ;      when X"2a" => result := '*' ;      when X"2b" => result := '+' ;      when X"2c" => result := ',' ;      when X"2d" => result := '-' ;      when X"2e" => result := '.' ;      when X"2f" => result := '/' ;      when X"30" => result := '0' ;      when X"31" => result := '1' ;      when X"32" => result := '2' ;      when X"33" => result := '3' ;      when X"34" => result := '4' ;      when X"35" => result := '5' ;      when X"36" => result := '6' ;      when X"37" => result := '7' ;      when X"38" => result := '8' ;      when X"39" => result := '9' ;      when X"3a" => result := ':' ;      when X"3b" => result := ';' ;      when X"3c" => result := '<' ;      when X"3d" => result := '=' ;      when X"3e" => result := '>' ;      when X"3f" => result := '?' ;      when X"40" => result := '@' ;      when X"41" => result := 'A' ;      when X"42" => result := 'B' ;      when X"43" => result := 'C' ;      when X"44" => result := 'D' ;      when X"45" => result := 'E' ;      when X"46" => result := 'F' ;      when X"47" => result := 'G' ;      when X"48" => result := 'H' ;      when X"49" => result := 'I' ;      when X"4a" => result := 'J' ;      when X"4b" => result := 'K' ;      when X"4c" => result := 'L' ;      when X"4d" => result := 'M' ;      when X"4e" => result := 'N' ;      when X"4f" => result := 'O' ;      when X"50" => result := 'P' ;      when X"51" => result := 'Q' ;      when X"52" => result := 'R' ;      when X"53" => result := 'S' ;      when X"54" => result := 'T' ;      when X"55" => result := 'U' ;      when X"56" => result := 'V' ;      when X"57" => result := 'W' ;      when X"58" => result := 'X' ;      when X"59" => result := 'Y' ;      when X"5a" => result := 'Z' ;      when X"5b" => result := '[' ;      when X"5c" => result := '\' ;      when X"5d" => result := ']' ;      when X"5e" => result := '^' ;      when X"5f" => result := '_' ;      when X"60" => result := '`' ;      when X"61" => result := 'a' ;      when X"62" => result := 'b' ;      when X"63" => result := 'c' ;      when X"64" => result := 'd' ;      when X"65" => result := 'e' ;      when X"66" => result := 'f' ;      when X"67" => result := 'g' ;      when X"68" => result := 'h' ;      when X"69" => result := 'i' ;      when X"6a" => result := 'j' ;      when X"6b" => result := 'k' ;      when X"6c" => result := 'l' ;      when X"6d" => result := 'm' ;      when X"6e" => result := 'n' ;      when X"6f" => result := 'o' ;      when X"70" => result := 'p' ;      when X"71" => result := 'q' ;      when X"72" => result := 'r' ;      when X"73" => result := 's' ;      when X"74" => result := 't' ;      when X"75" => result := 'u' ;      when X"76" => result := 'v' ;      when X"77" => result := 'w' ;      when X"78" => result := 'x' ;      when X"79" => result := 'y' ;      when X"7a" => result := 'z' ;      when X"7b" => result := '{' ;      when X"7c" => result := '|' ;      when X"7d" => result := '}' ;      when X"7e" => result := '~' ;      when X"7f" => result := '_' ;      WHEN others =>        ASSERT False REPORT "data contains a non-printable character" SEVERITY Warning;        result := nul;    END case;    RETURN result;  end bin_to_char;  -- synthesis translate_on                             begin--synthesis translate_off  -- purpose: simulate verilog initial function to open file in write mode  -- type   : combinational  -- inputs : initial  -- outputs: <none>  process is    variable initial : boolean := true; -- not initialized yet    variable status : file_open_status; -- status for fopen  begin  -- process    if initial = true then      file_open (status, text_handle, "/data/job/20061127/2047501/examples/vhdl/niosII_cycloneII_2c35/standard/std_2C35_sim/uart1_log_module.txt", WRITE_MODE);      initial := false;                 -- done!    end if;    wait;                               -- wait forever  end process;  process (clk)    variable data_string : LINE;        -- for line buffer to file    variable status : file_open_status; -- status for fopen                          begin  -- process clk    if clk'event and clk = '1' then -- sync ' chars for hilighting txt editors      if (valid and strobe) = '1' then                                write (data_string,bin_to_char(data));        if data = X"0a" or data = X"0d" then -- \n or \r will flush line          writeline (text_handle,data_string);          file_close (text_handle);     -- flush buffer          file_open (status, text_handle, "/data/job/20061127/2047501/examples/vhdl/niosII_cycloneII_2c35/standard/std_2C35_sim/uart1_log_module.txt", APPEND_MODE);        end if;                                 end if;    end if;  end process;                       --synthesis translate_onend europa;-- turn off superfluous VHDL processor warnings -- altera message_level Level1 -- altera message_off 10034 10035 10036 10037 10230 10240 10030 library altera;use altera.altera_europa_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_tx is         port (              -- inputs:                 signal baud_divisor : IN STD_LOGIC_VECTOR (9 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 entity uart1_tx;architecture europa of uart1_tx is                signal baud_clk_en :  STD_LOGIC;                signal baud_rate_counter :  STD_LOGIC_VECTOR (9 DOWNTO 0);                signal baud_rate_counter_is_zero :  STD_LOGIC;                signal do_load_shifter :  STD_LOGIC;                signal do_shift :  STD_LOGIC;                signal internal_tx_ready :  STD_LOGIC;                signal pre_txd :  STD_LOGIC;                signal shift_done :  STD_LOGIC;                signal tx_load_val :  STD_LOGIC_VECTOR (9 DOWNTO 0);                signal tx_shift_reg_out :  STD_LOGIC;                signal tx_shift_register_contents :  STD_LOGIC_VECTOR (9 DOWNTO 0);                signal tx_wr_strobe_onset :  STD_LOGIC;                signal unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_in :  STD_LOGIC_VECTOR (9 DOWNTO 0);                signal unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out :  STD_LOGIC_VECTOR (9 DOWNTO 0);begin  tx_wr_strobe_onset <= tx_wr_strobe AND begintransfer;  tx_load_val <= Std_Logic_Vector'(A_ToStdLogicVector(std_logic'('1')) & tx_data & A_ToStdLogicVector(std_logic'('0')));  shift_done <= NOT (or_reduce(tx_shift_register_contents));  process (clk, reset_n)  begin    if reset_n = '0' then      do_load_shifter <= std_logic'('0');    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         do_load_shifter <= (NOT internal_tx_ready) AND shift_done;      end if;    end if;  end process;  process (clk, reset_n)  begin    if reset_n = '0' then      internal_tx_ready <= std_logic'('1');    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         if std_logic'(tx_wr_strobe_onset) = '1' then           internal_tx_ready <= std_logic'('0');        elsif std_logic'(do_load_shifter) = '1' then           internal_tx_ready <= Vector_To_Std_Logic(-SIGNED(std_logic_vector'("00000000000000000000000000000001")));        end if;      end if;    end if;  end process;  process (clk, reset_n)  begin    if reset_n = '0' then      tx_overrun <= std_logic'('0');    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         if std_logic'(status_wr_strobe) = '1' then           tx_overrun <= std_logic'('0');        elsif std_logic'((NOT internal_tx_ready AND tx_wr_strobe_onset)) = '1' then           tx_overrun <= Vector_To_Std_Logic(-SIGNED(std_logic_vector'("00000000000000000000000000000001")));        end if;      end if;    end if;  end process;  process (clk, reset_n)  begin    if reset_n = '0' then      tx_shift_empty <= std_logic'('1');    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         tx_shift_empty <= internal_tx_ready AND shift_done;      end if;    end if;  end process;  process (clk, reset_n)  begin    if reset_n = '0' then      baud_rate_counter <= std_logic_vector'("0000000000");    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         if std_logic'((baud_rate_counter_is_zero OR do_load_shifter)) = '1' then           baud_rate_counter <= baud_divisor;        else          baud_rate_counter <= A_EXT (((std_logic_vector'("00000000000000000000000") & (baud_rate_counter)) - std_logic_vector'("000000000000000000000000000000001")), 10);        end if;      end if;    end if;  end process;  baud_rate_counter_is_zero <= to_std_logic(((std_logic_vector'("0000000000000000000000") & (baud_rate_counter)) = std_logic_vector'("00000000000000000000000000000000")));  process (clk, reset_n)  begin    if reset_n = '0' then      baud_clk_en <= std_logic'('0');    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         baud_clk_en <= baud_rate_counter_is_zero;      end if;    end if;  end process;  do_shift <= (baud_clk_en AND (NOT shift_done)) AND (NOT do_load_shifter);  process (clk, reset_n)  begin    if reset_n = '0' then      pre_txd <= std_logic'('1');    elsif clk'event and clk = '1' then      if std_logic'(NOT shift_done) = '1' then         pre_txd <= tx_shift_reg_out;      end if;    end if;  end process;  process (clk, reset_n)  begin    if reset_n = '0' then      txd <= std_logic'('1');    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         txd <= pre_txd AND NOT do_force_break;      end if;    end if;  end process;  --_reg, which is an e_register  process (clk, reset_n)  begin    if reset_n = '0' then      unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out <= std_logic_vector'("0000000000");    elsif clk'event and clk = '1' then      if std_logic'(clk_en) = '1' then         unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out <= unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_in;      end if;    end if;  end process;  unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_in <= A_WE_StdLogicVector((std_logic'((do_load_shifter)) = '1'), tx_load_val, A_WE_StdLogicVector((std_logic'((do_shift)) = '1'), Std_Logic_Vector'(A_ToStdLogicVector(std_logic'('0')) & unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out(9 DOWNTO 1)), unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out));  tx_shift_register_contents <= unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out;  tx_shift_reg_out <= unxshiftxtx_shift_register_contentsxtx_shift_reg_outxx5_out(0);  --vhdl renameroo for output signals  tx_ready <= internal_tx_ready;end europa;-- turn off superfluous VHDL processor warnings -- altera message_level Level1 -- altera message_off 10034 10035 10036 10037 10230 10240 10030 library altera;use altera.altera_europa_support_lib.all;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;library std;use std.textio.all;entity 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -