--Program for Programmable Peripheral Intterface. library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; use IEEE.std_logic_arith.all; entity ppi is port ( a0: in STD_LOGIC; a1: in STD_LOGIC; reset: in STD_LOGIC; csb: in STD_LOGIC; rdb: in STD_LOGIC; wrb: in STD_LOGIC; din: inout STD_LOGIC_vector(7 downto 0); pa: inout STD_LOGIC_vector(7 downto 0); pb: inout STD_LOGIC_vector(7 downto 0); pcl: inout STD_LOGIC_vector(3 downto 0); pcu: inout STD_LOGIC_vector(7 downto 4) ); end ppi; architecture ppi_arch of ppi is signal cwr:std_logic_vector(7 downto 0); signal wrbu,rdbu,rdba,wrba,rdbcu,rdbcl,rdbb,wrbcl,wrbcu,wrbb:std_logic; signal wa,xa,ya,za,wb,xb,yb,zb:std_logic_vector( 7 downto 0); signal wcl,xcl,ycl,zcl:std_logic_vector( 3 downto 0); signal wcu,xcu,ycu,zcu:std_logic_vector( 7 downto 4); signal a :std_logic_vector(7 downto 0); signal c :std_logic_vector(2 downto 0); begin process(a1,a0,rdb,wrb,csb,wrba,rdba,reset,wrbb,rdbb,rdbcl,wrbcl,rdbcu,wrbcu) begin wrbu<=wrb; rdbu<=rdb; if csb<='0' then -- ***** architecture ports_arch of portss ***** -- ****** PORT A STARTS ****** if(a1='0' and a0='0') then for i in 0 to 7 loop if(wrba='1' and reset='1')then wa(i)<='Z'; else wa(i)<=din(i); end if; if(reset='0') then xa(i) <= wa(i); else xa(i)<='0'; end if; if(wrba='1'and reset='1') then pa(i)<='Z'; else pa(i)<=xa(i); end if; if(rdba='1' and reset='1')then ya(i)<='Z'; else ya(i)<=pa(i); end if; if(reset='0')then za(i)<=ya(i); else za(i)<='0'; end if; if(rdba='1' and reset='1')then din(i)<='Z'; else din(i)<=za(i); end if; end loop; else pa<="ZZZZZZZZ"; end if; -- PORT A ENDS- -- PORT B STARTS--- if(a1='0' and a0='1') then for i in 0 to 7 loop if(wrbb='1' and reset='1')then wb(i)<='Z'; else wb(i)<=din(i); end if; if(reset='0') then xb(i)<=wb(i); else xb(i)<='0'; end if; if(wrbb='1'and reset='1')then pb(i)<='Z'; else pb(i)<=xb(i); end if; if(rdbb='1' and reset='1')then yb(i)<='Z'; else yb(i)<=pb(i); end if; if(reset='0')then zb(i)<=yb(i); else zb(i)<='0'; end if; if(rdbb='1' and reset='1')then din(i)<='Z'; else din(i)<=zb(i); end if; end loop; else pb<="ZZZZZZZZ"; end if; -- PORT B ENDS-- -- PORT CL STARTS-- if (a1='1' and a0='0') then for i in 0 to 3 loop if(wrbcl='1' and reset='1')then wcl(i)<='Z'; else wcl(i)<=din(i); end if; if(reset='0') then xcl(i)<=wcl(i); else xcl(i)<='0'; end if; if(wrbcl='1'and reset='1')then pcl(i)<='Z'; else pcl(i)<=xcl(i); end if; if(rdbcl='1' and reset='1')then ycl(i)<='Z'; else ycl(i)<=pcl(i); end if; if(reset='0')then zcl(i)<=ycl(i); else zcl(i)<='0'; end if; if(rdbcl='1' and reset='1')then din(i)<='Z'; else din(i)<=zcl(i); end if; end loop; else pcl<="ZZZZ"; end if; --PCL ENDS-- --PCU STARTS-- if(a1='1' and a0='0') then for i in 4 to 7 loop if(wrbcu='1' and reset='1')then wcu(i)<='Z'; else wcu(i)<=din(i); end if; if(reset='0') then xcu(i)<=wcu(i); else xcu(i)<='0'; end if; if(wrbcu='1'and reset='1')then pcu(i)<='Z'; else pcu(i)<=xcu(i); end if; if(rdbcu='1' and reset='1')then ycu(i)<='Z'; else ycu(i)<=pcu(i); end if; if(reset='0')then zcu(i)<=ycu(i); else zcu(i)<='0'; end if; if(rdbcu='1' and reset='1')then din(i)<='Z'; else din(i)<=zcu(i); end if; end loop; else pcu<="ZZZZ"; pcl<="ZZZZ"; end if; --PCU ENDS-- --MODE_0 STARTS-- if (a0='1' and a1='1' and wrb='0' and rdb='1')then case cwr is when "10000000" =>rdba<='1';wrba<='0';rdbcu<='1'; wrbcu<='0';rdbb<='1';wrbb<='0'; rdbcl<='1';wrbcl<='0'; pa<=din; pb<=din; pcl<=din(3 downto 0);pcu<=din(7 downto 4); when "10000001" =>rdba<='1';wrba<='0';rdbcu<='1';wrbcu<='0';rdbb<='1';wrbb<='0'; rdbcl<='0';wrbcl<='1'; pa<=din;pb<=din;din(3 downto 0)<=pcl;pcu<=din(7 downto 4); when "10000010" =>rdba<='1';wrba<='0'; rdbcu<='1'; wrbcu<='0';rdbb<='0';wrbb<='1'; rdbcl<='1';wrbcl<='0'; pa<= din;din<=pb;pcl<=din(3 downto 0);pcu<=din(7 downto 4); when "10000011" =>rdba<='1';wrba<='0';rdbcu<='0'; wrbcu<='1';rdbb<='0';wrbb<='1'; rdbcl<='1';wrbcl<='0'; pa<= din;din<=pb; din(3 downto 0)<=pcl;pcu<=din(7 downto 4); when "10001000" =>rdba<='1';wrba<='0';rdbcu<='0';wrbcu<='1';rdbb<='1';wrbb<='0'; rdbcl<='1';wrbcl<='0'; din<=pa;din<=pb;pcl<=din(3 downto 0);din(7 downto 4)<=pcu; when "10010010" =>rdba<='0';wrba<='1'; rdbcu<='1'; wrbcu<='0';rdbb<='1';wrbb<='0'; rdbcl<='1';wrbcl<='0'; din<=pa;din<=pb;pcl<=din(3 downto 0);pcu<=din(7 downto 4); when others=>null; end case; end if; -- START BSR-MODE --- if (a1='1' and a0='1')then cwr<=din; if (rdbu='1' and wrbu='0' and csb='0' and reset='0') then if cwr(7)='0' then c<=cwr(3) & cwr(2) & cwr(1); case c is when "000" => pcl(0)<=cwr(0); when others =>pcl(0)<=pcl(0); end case; case c is when "001" => pcl(1)<=cwr(0); when others =>pcl(1)<=pcl(1); end case; case c is when "010" => pcl(2)<=cwr(0); when others =>pcl(2)<=pcl(2); end case; case c is when "011" => pcl(3)<=cwr(0); when others =>pcl(3)<=pcl(3); end case; case c is when "100" => pcu(4)<=cwr(0); when others =>pcu(4)<=pcu(4); end case; case c is when "101" => pcu(5)<=cwr(0); when others =>pcu(5)<=pcu(5); end case; case c is when "110" => pcu(6)<=cwr(0); when others =>pcu(6)<=pcu(6); end case; case c is when "111" => pcu(7)<=cwr(0); when others =>pcu(7)<=pcu(7); end case; end if; end if; end if; else din<="ZZZZZZZZ" ; end if; end process; end ppi_arch;