Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIBRARY ieee;
- USE ieee.std_logic_1164.ALL;
- use ieee.std_logic_arith.all;
- -- Uncomment the following library declaration if using
- -- arithmetic functions with Signed or Unsigned values
- --USE ieee.numeric_std.ALL;
- ENTITY TestQuiz IS
- END TestQuiz;
- ARCHITECTURE behavior OF TestQuiz IS
- -- Component Declaration for the Unit Under Test (UUT)
- COMPONENT QUIZ
- PORT(
- rst : IN std_logic;
- clk : IN std_logic;
- P1 : IN std_logic;
- P2 : IN std_logic;
- display : OUT std_logic_vector(6 downto 0);
- stato : OUT std_logic_vector(2 downto 0);
- cont : OUT std_logic_vector(3 downto 0)
- );
- END COMPONENT;
- --Inputs
- signal rst : std_logic := '0';
- signal clk : std_logic := '0';
- signal P1 : std_logic := '0';
- signal P2 : std_logic := '0';
- --Outputs
- signal display : std_logic_vector(6 downto 0);
- signal stato : std_logic_vector(2 downto 0);
- signal cont : std_logic_vector(3 downto 0);
- -- Clock period definitions
- constant clk_period : time := 10 ns;
- function to_string (a: std_logic_vector) return string is
- variable b : string (1 to a'length) := (others => NUL);
- variable stri : integer:=1;
- begin
- for i in a'range loop
- b(stri) := std_logic'image(a((i)))(2);
- stri:=stri+1;
- end loop;
- return b;
- end function;
- BEGIN
- -- Instantiate the Unit Under Test (UUT)
- uut: QUIZ PORT MAP (
- rst => rst,
- clk => clk,
- P1 => P1,
- P2 => P2,
- display => display,
- stato => stato,
- cont => cont
- );
- -- Clock process definitions
- clk_process :process
- begin
- clk <= '0';
- wait for clk_period/2;
- clk <= '1';
- wait for clk_period/2;
- end process;
- -- Stimulus process
- stim_proc: process
- variable ing: std_logic_vector(1 downto 0);
- begin
- ing:=P1&P2;
- -- hold reset state for 100 ns.
- rst<='1';
- wait for 4*clk_period;
- rst<='0';
- wait for clk_period*2;
- -- insert stimulus here
- P2<='1'; P1<='0'; --Inseriamo la combinazione per far transitare
- wait for clk_period*2; -- in uno stato dei 4 stati di prenotazione
- for i in 0 to 3 loop
- ing:=conv_std_logic_vector(i,2); --Proviamo che qualsiasi combinazione di ingressi
- P2<=ing(1); P1<=ing(0); --non ha effetto sull'uscita per 11 clk
- wait for clk_period*2;
- end loop;
- P2<='0'; P1<='1'; --E che esiste un colpo di clock in cui la macchina
- wait for clk_period*2; --si spegne indipendemnete dagli ingressi prima
- --di tornare in uno dei due stati di non prenotazione
- P2<='0'; P1<='0';
- wait for clk_period*2; --Aspetto qualche clock nello stato di non prenptazione
- --Ripeto il procedimento per ogni stato.
- P2<='0'; P1<='1';
- wait for clk_period*2;
- for i in 0 to 3 loop
- ing:=conv_std_logic_vector(i,2);
- P2<=ing(1); P1<=ing(0);
- wait for clk_period*2;
- end loop;
- P2<='1'; P1<='0';
- wait for clk_period*2;
- P2<='0'; P1<='0';
- wait for clk_period*2;
- P2<='1'; P1<='1';
- wait for clk_period*2;
- for i in 0 to 3 loop
- ing:=conv_std_logic_vector(i,2);
- P2<=ing(1); P1<=ing(0);
- wait for clk_period*2;
- end loop;
- P2<='1'; P1<='1';
- wait for clk_period*2;
- P2<='0'; P1<='0';
- wait for clk_period*2;
- P2<='0'; P1<='1';
- wait for clk_period*2;
- for i in 0 to 3 loop
- ing:=conv_std_logic_vector(i,2);
- P2<=ing(1); P1<=ing(0);
- wait for clk_period*2;
- end loop;
- P2<='0'; P1<='0';
- wait for clk_period*2;
- P2<='0'; P1<='0';
- wait for clk_period*2;
- P2<='1'; P1<='0';
- wait for clk_period*2;
- for i in 0 to 3 loop
- ing:=conv_std_logic_vector(i,2);
- P2<=ing(1); P1<=ing(0);
- wait for clk_period*2;
- end loop;
- P2<='0'; P1<='1';
- wait for clk_period*2;
- P2<='0'; P1<='0';
- wait for clk_period*2;
- P2<='1'; P1<='1';
- wait for clk_period*2;
- for i in 0 to 3 loop
- ing:=conv_std_logic_vector(i,2);
- P2<=ing(1); P1<=ing(0);
- wait for clk_period*2;
- end loop;
- P2<='1'; P1<='0';
- wait for clk_period*2;
- P2<='0'; P1<='0';
- wait for clk_period*2;
- wait;
- end process;
- --Processi per seguire meglio la simulazione
- --Processo che segue le transizioni fra stati e che stampa quando ne avviene una
- checkState: process (stato)
- variable temp_in : std_logic_vector (1 downto 0);
- begin
- temp_in(1):=P2;
- temp_in(0):=P1;
- if(rst/='1') then
- if(stato="000") then
- --assert (temp_in/="00") report "Nessuno dei giocatori ha premuto il pulsante (Precedenza P1)" severity note;
- --assert (temp_in="00") report "Uscita dallo stato di prenotazione" severity note;
- assert false report "Uscita dallo stato di prenotazione (Precedenza P1)" severity note;
- elsif (stato="001") then
- assert false report "Il giocatore 1 si è prenotato (Precedenza P1)" severity note;
- elsif (stato="010") then
- assert false report "Il giocatore 2 si è prenotato (Precedenza P1)" severity note;
- elsif (stato="011") then
- --assert (temp_in/="00") report "Nessuno dei giocatori ha premuto il pulsante (Precedenza P1)" severity note;
- --assert (temp_in="00") report "Uscita dallo stato di prenotazione" severity note;
- assert false report "Uscita dallo stato di prenotazione (Precedenza P2)" severity note;
- elsif (stato="100") then
- assert false report "Il giocatore 1 si è prenotato (Precedenza P2)" severity note;
- elsif (stato="101") then
- assert false report "il giocatore 2 si è prenotato (Precedenza P2)" severity note;
- else
- assert false report "Transizione errata" severity warning;
- end if;
- end if;
- end process;
- --Gestione particolare della stampa delgi unici due stati che per "00"
- --rimangono in se stessi e di quando si resetta
- nessunPressione: process(clk)
- variable temp_ln : std_logic_vector (1 downto 0);
- begin
- temp_ln(1):=P2;
- temp_ln(0):=P1;
- if(rising_edge(clk)) then
- if(rst='1') then
- assert false report "Stai resettando la macchina" severity note;
- elsif(stato="000") then
- assert temp_ln/="00" report "Nessuno dei due giocatori sta premendo il pulsante (Precedenza P1)" severity note;
- elsif(stato="011") then
- assert temp_ln/="00" report "Nessuno dei due giocatori sta premendo il pulsante (Precedenza P2)" severity note;
- end if;
- end if;
- end process;
- checkCounter: process (cont) --Processo stampa contatore quando effetivamente coinvolto in uno stato
- begin
- if(cont/="0000") then
- assert false report "Ho mantenuto l'uscita per: " & to_string(cont) severity note;
- end if;
- end process;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement