Laborator 1
entity two_com IS
port( x, clk, rst: in bit; z: out bit);
end two_com;
entity and2 IS
port(a,b:in bit; c: out bit);
end and2;
entity and3 IS
port(a,b,c:in bit;d:out bit);
end and3;
entity or2 IS
port(a,b:in bit;c:out bit);
end or2;
entity inv IS
port(a:in bit;b:out bit);
end inv;
entity mydff IS
port(d,c,r:in bit;q:out bit);
end mydff;
architecture struct of two_com IS
component and2
port(a,b:in bit;c:out bit);
end component;
component and3
port(a,b,c:in bit;d:out bit);
end component;
component or2
port(a,b:in bit;c:out bit);
end component;
component inv
port(a:in bit;b:out bit);
end component;
component mydff
port(d,c,r:in bit;q:out bit);
end component;
signal gnd:bit := '0';
signal q1,q0,qn,xn,t1,t2:bit;
begin
c0:mydff port map(gnd,clk,rst,q0); --mapare pozitionala-
c1:mydff port map(q=>q1,r=>rst,c=>clk,d=>x); --mapare explicita--
c2:inv port map(q1,qn);
c3:inv port map(x,xn);
c4:and2 port map(c=>t1,b=>q1,a=>x); --mapare mixta--
c5:and3 port map(xn,qn,q0,t2);
c6:or2 port map(t1,t2,z);
end struct;
configuration cfg_tc of two_com is
for struct
end for;
end cfg_tc;
entity test_tc is
end test_tc;
architecture ta of test_tc is
component two_com
port(x,clk,rst:in bit; z:out bit);
end component;
signal x_t,c_t,r_t,z_t:bit;
begin
x_t<='0','1' after 20 ns, '0' after 60 ns, '1' after 87 ns, '0' after 100 ns;
r_t<='1', '0' after 2 ns, '1' after 5 ns;
process
begin
c_t<='0';
wait for 10 ns;
c_t<='1';
wait for 10 ns;
end process;
cpn_t: two_com PORT MAP(x_t, c_t, r_t, z_t);
end ta;
configuration cfg_tst of test_tc IS
for ta
end for;
end cfg_tst;
architecture behavioral of two_com is
type stare is(s0,s1,s2);
signal st:stare;
begin
p1:process(clk,rst)
begin
if rst'EVENT and rst='0' then
st<=s0;
elsif clk'EVENT and clk='1' then
if x='0' then
st<=s1;
else st<=s2;
end if;
end if;
end process p1;
p2:process(st,x)
begin
if (st=s0 and x='0') or (st=s1 and x='1') then
z<='1' after 2 ns;
else
z<='0' after 2 ns;
end if;
end process p2;
end behavioral;
configuration cfg_behavioral of test_tc is
for ta
for cpn_t: two_com use entity work.two_com(behavioral);
end for;
end for;
end cfg_behavioral;